diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapComponent.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapComponent.kt index 80f6784f..a1d6040c 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapComponent.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapComponent.kt @@ -21,7 +21,11 @@ import androidx.compose.ui.layout.boundsInParent import androidx.compose.ui.layout.onGloballyPositioned import com.google.accompanist.permissions.ExperimentalPermissionsApi import com.google.accompanist.permissions.rememberMultiplePermissionsState +import com.what3words.components.compose.maps.W3WMapDefaults.MapColors +import com.what3words.components.compose.maps.W3WMapDefaults.defaultMapColors import com.what3words.components.compose.maps.buttons.W3WMapButtons +import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault +import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault.defaultButtonColors import com.what3words.components.compose.maps.models.W3WGridScreenCell import com.what3words.components.compose.maps.models.W3WLocationSource import com.what3words.components.compose.maps.models.W3WMapProjection @@ -50,6 +54,13 @@ import kotlinx.coroutines.launch * @param modifier Modifier for styling and layout. * @param layoutConfig [W3WMapDefaults.LayoutConfig] Configuration for the map's layout. * @param mapConfig [W3WMapDefaults.MapConfig] Configuration for the map's appearance such as custom dark mode, grid line config. + * Determines the map's color scheme based on the current map type and dark mode setting. + * - If the `mapType` is `NORMAL` or `TERRAIN`: + * - If `isDarkMode` is `true`, the dark color scheme (`darkMapColor`) is used. + * - If `isDarkMode` is `false`, the normal color scheme (`normalMapColor`) is used. + * - If the `mapType` is `HYBRID` or `SATELLITE`, the satellite color scheme (`satelliteMapColor`) is used, regardless of the dark mode setting. + * @param mapColors [W3WMapDefaults.MapColor] Configuration for the map's color such as light, dark and satellite mode will based on mapType and state isDarkMode + * @param buttonColors [W3WMapButtonsDefault.ButtonColors] Configuration for the button's color which are applied according to the current theme * @param mapManager The [W3WMapManager] instance that manages the map's mapState and interactions. * @param locationSource An optional [W3WLocationSource] used to fetch the user's location. * @param content Optional composable content to be displayed on the map. @@ -60,6 +71,8 @@ fun W3WMapComponent( modifier: Modifier = Modifier, layoutConfig: W3WMapDefaults.LayoutConfig = W3WMapDefaults.defaultLayoutConfig(), mapConfig: W3WMapDefaults.MapConfig = W3WMapDefaults.defaultMapConfig(), + buttonColors: W3WMapButtonsDefault.ButtonColors = defaultButtonColors(), + mapColors: MapColors = defaultMapColors(), mapManager: W3WMapManager, onSelectedSquareChanged: (W3WAddress) -> Unit, locationSource: W3WLocationSource? = null, @@ -102,6 +115,8 @@ fun W3WMapComponent( modifier = modifier, layoutConfig = currentLayoutConfig.value, mapConfig = currentMapConfig.value, + mapColors = mapColors, + buttonColors = buttonColors, mapProvider = mapManager.mapProvider, content = content, mapState = mapState, @@ -157,6 +172,13 @@ fun W3WMapComponent( * @param modifier Modifier for styling and layout. * @param layoutConfig [W3WMapDefaults.LayoutConfig] Configuration for the map's layout. * @param mapConfig [W3WMapDefaults.MapConfig] Configuration for the map's appearance. + * Determines the map's color scheme based on the current map type and dark mode setting. + * - If the `mapType` is `NORMAL` or `TERRAIN`: + * - If `isDarkMode` is `true`, the dark color scheme (`darkMapColor`) is used. + * - If `isDarkMode` is `false`, the normal color scheme (`normalMapColor`) is used. + * - If the `mapType` is `HYBRID` or `SATELLITE`, the satellite color scheme (`satelliteMapColor`) is used, regardless of the dark mode setting. + * @param mapColors [W3WMapDefaults.MapColor] Configuration for the map's color such as light, dark and satellite mode will based on mapType and state isDarkMode + * @param buttonColors [W3WMapButtonsDefault.ButtonColors] Configuration for the button's color which are applied according to the current theme * @param mapState The [W3WMapState] object that holds the mapState of the map. * @param buttonState The [W3WButtonsState] object that holds the buttonState of the map. * @param mapProvider An instance of enum [MapProvider] to define map provide: GoogleMap, MapBox. @@ -172,6 +194,8 @@ fun W3WMapComponent( modifier: Modifier = Modifier, layoutConfig: W3WMapDefaults.LayoutConfig = W3WMapDefaults.defaultLayoutConfig(), mapConfig: W3WMapDefaults.MapConfig = W3WMapDefaults.defaultMapConfig(), + buttonColors: W3WMapButtonsDefault.ButtonColors = defaultButtonColors(), + mapColors: MapColors = defaultMapColors(), mapState: W3WMapState, buttonState: W3WButtonsState, mapProvider: MapProvider, @@ -191,6 +215,8 @@ fun W3WMapComponent( modifier = modifier, layoutConfig = layoutConfig, mapConfig = mapConfig, + mapColors = mapColors, + buttonColors = buttonColors, mapProvider = mapProvider, content = content, mapState = mapState, @@ -233,6 +259,13 @@ fun W3WMapComponent( ** @param modifier Modifier for styling and layout. * @param layoutConfig [W3WMapDefaults.LayoutConfig] Configuration for the map's layout. * @param mapConfig [W3WMapDefaults.MapConfig] Configuration for the map's appearance. + * Determines the map's color scheme based on the current map type and dark mode setting. + * - If the `mapType` is `NORMAL` or `TERRAIN`: + * - If `isDarkMode` is `true`, the dark color scheme (`darkMapColor`) is used. + * - If `isDarkMode` is `false`, the normal color scheme (`normalMapColor`) is used. + * - If the `mapType` is `HYBRID` or `SATELLITE`, the satellite color scheme (`satelliteMapColor`) is used, regardless of the dark mode setting. + * @param mapColors [W3WMapDefaults.MapColors] Configuration for the map's color such as light, dark and satellite mode will based on mapType and state isDarkMode + * @param buttonColors [W3WMapButtonsDefault.ButtonColors] Configuration for the button's color which are applied according to the current theme * @param mapState The [W3WMapState] object that holds the mapState of the map. * @param buttonState The [W3WButtonsState] object that holds the buttonState of the map. * @param mapProvider An instance of enum [MapProvider] to define map provide: GoogleMap, MapBox. @@ -248,6 +281,8 @@ internal fun W3WMapContent( modifier: Modifier = Modifier, layoutConfig: W3WMapDefaults.LayoutConfig = W3WMapDefaults.defaultLayoutConfig(), mapConfig: W3WMapDefaults.MapConfig = W3WMapDefaults.defaultMapConfig(), + buttonColors: W3WMapButtonsDefault.ButtonColors = defaultButtonColors(), + mapColors: MapColors = defaultMapColors(), mapState: W3WMapState, buttonState: W3WButtonsState, mapProvider: MapProvider, @@ -279,6 +314,19 @@ internal fun W3WMapContent( } } + val mapColor = remember(mapState.mapType, mapState.isDarkMode) { + when(mapState.mapType) { + W3WMapType.NORMAL, + W3WMapType.TERRAIN -> { + if(mapState.isDarkMode) mapColors.darkMapColor else mapColors.normalMapColor + } + W3WMapType.HYBRID, + W3WMapType.SATELLITE -> { + mapColors.satelliteMapColor + } + } + } + LaunchedEffect(bounds) { bounds.let { val leftTop = PointF(it.left, it.top) @@ -305,6 +353,7 @@ internal fun W3WMapContent( modifier = modifier, layoutConfig = layoutConfig, mapConfig = mapConfig, + mapColor = mapColor, mapProvider = mapProvider, mapState = mapState, onMarkerClicked = onMarkerClicked, @@ -320,6 +369,7 @@ internal fun W3WMapContent( .padding(layoutConfig.contentPadding), buttonConfig = mapConfig.buttonConfig, buttonState = buttonState, + buttonColors = buttonColors, isLocationEnabled = mapState.isMyLocationEnabled, onMapTypeClicked = onMapTypeClicked, onMyLocationClicked = onMyLocationClicked, @@ -386,6 +436,7 @@ internal fun MapPermissionsHandler( * @param modifier Modifier for styling and layout of the map view. * @param layoutConfig [W3WMapDefaults.LayoutConfig] Configuration for the map's layout. * @param mapConfig [W3WMapDefaults.MapConfig] Configuration for the map's appearance. + * @param mapColor [W3WMapDefaults.MapColor] Configuration for the map's appearance color such gridLine, marker. * @param mapProvider An instance of enum [MapProvider] to define map provide: GoogleMap, MapBox. * @param mapState The [W3WMapState] object that holds the mapState of the map. * @param content Optional composable content to be displayed on the map. @@ -397,6 +448,7 @@ internal fun W3WMapView( modifier: Modifier, layoutConfig: W3WMapDefaults.LayoutConfig, mapConfig: W3WMapDefaults.MapConfig, + mapColor: W3WMapDefaults.MapColor, mapProvider: MapProvider, mapState: W3WMapState, content: (@Composable () -> Unit)? = null, @@ -411,6 +463,7 @@ internal fun W3WMapView( modifier = modifier, layoutConfig = layoutConfig, mapConfig = mapConfig, + mapColor = mapColor, state = mapState, content = content, onMapClicked = onMapClicked, @@ -425,6 +478,7 @@ internal fun W3WMapView( modifier = modifier, layoutConfig = layoutConfig, mapConfig = mapConfig, + mapColor = mapColor, state = mapState, content = content, onMapClicked = onMapClicked, diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapDefaults.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapDefaults.kt index e2ae4fc1..d2a27b60 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapDefaults.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapDefaults.kt @@ -6,6 +6,8 @@ import androidx.compose.runtime.Immutable import androidx.compose.ui.graphics.Color import androidx.compose.ui.unit.Dp import androidx.compose.ui.unit.dp +import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault +import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault.defaultButtonColors import com.what3words.components.compose.maps.models.DarkModeStyle import com.what3words.components.compose.maps.models.W3WMarkerColor import com.what3words.core.types.geometry.W3WCoordinates @@ -24,8 +26,6 @@ enum class MapProvider { object W3WMapDefaults { val LOCATION_DEFAULT = W3WCoordinates(51.521251, -0.203586) val MARKER_COLOR_DEFAULT = W3WMarkerColor(background = Color.Red, slash = Color.White) - private val SELECTED_ZOOM_OUT_MARKER_COLOR_DEFAULT = - W3WMarkerColor(background = Color(0xFF0A3049), slash = Color.White) const val MIN_SUPPORT_GRID_ZOOM_LEVEL_GOOGLE = 19f const val MIN_SUPPORT_GRID_ZOOM_LEVEL_MAP_BOX = 18.5f @@ -41,9 +41,6 @@ object W3WMapDefaults { val darkModeCustomJsonStyle: String = DarkModeStyle.darkMode, val isBuildingEnable: Boolean, - // Marker - val markerConfig: MarkerConfig, - // Grid view val gridLineConfig: GridLinesConfig, @@ -55,7 +52,6 @@ object W3WMapDefaults { * Data class representing the configuration for grid lines on the map. * * @property isGridEnabled Whether the grid is enabled or not. - * @property gridColor The color of the grid lines. * @property gridLineWidth The width of the grid lines. * @property zoomSwitchLevel The zoom level at which the grid appearance changes. * @property gridScale The scale factor for the grid. Determines how much larger the grid is @@ -65,8 +61,6 @@ object W3WMapDefaults { @Immutable data class GridLinesConfig( val isGridEnabled: Boolean, - val gridColor: Color, - val gridColorDarkMode: Color, val gridLineWidth: Dp, val zoomSwitchLevel: Float, val gridScale: Float @@ -100,11 +94,23 @@ object W3WMapDefaults { ) @Immutable - data class MarkerConfig( - val defaultMarkerColor: W3WMarkerColor, + data class MapColors( + val normalMapColor: MapColor, + val darkMapColor: MapColor, + val satelliteMapColor: MapColor + ) + + @Immutable + data class MapColor( + val gridLineColor: Color, + val markerColors: MarkerColors + ) + + @Immutable + data class MarkerColors( + val selectedColor: Color, val selectedZoomOutColor: W3WMarkerColor, - val selectedZoomInColor: Color, - val selectedZoomInColorDarkMode: Color, + val defaultMarkerColor: W3WMarkerColor ) @Composable @@ -121,29 +127,23 @@ object W3WMapDefaults { isBuildingEnable: Boolean = false, gridLineConfig: GridLinesConfig = defaultGridLinesConfig(), buttonConfig: ButtonConfig = defaultButtonConfig(), - markerConfig: MarkerConfig = defaultMarkerConfig() ): MapConfig { return MapConfig( darkModeCustomJsonStyle = darkModeCustomJsonStyle, isBuildingEnable = isBuildingEnable, gridLineConfig = gridLineConfig, buttonConfig = buttonConfig, - markerConfig = markerConfig ) } fun defaultGridLinesConfig( isGridEnabled: Boolean = true, - gridColor: Color = Color(0xB3697F8D), - gridColorDarkMode: Color = Color(0xB3697F8D), zoomSwitchLevel: Float = 19f, gridLineWidth: Dp = 2.dp, gridScale: Float = 6f ): GridLinesConfig { return GridLinesConfig( isGridEnabled = isGridEnabled, - gridColor = gridColor, - gridColorDarkMode = gridColorDarkMode, zoomSwitchLevel = zoomSwitchLevel, gridLineWidth = gridLineWidth, gridScale = gridScale @@ -162,17 +162,63 @@ object W3WMapDefaults { ) } - fun defaultMarkerConfig( - selectedZoomOutColor: W3WMarkerColor = SELECTED_ZOOM_OUT_MARKER_COLOR_DEFAULT, - defaultMarkerColor: W3WMarkerColor = MARKER_COLOR_DEFAULT, - selectedColor: Color = Color.Black, - selectedColorDarkMode: Color = Color.White - ): MarkerConfig { - return MarkerConfig( + fun defaultMapColors( + normalMapColor: MapColor = defaultNormalMapColor(), + darkMapColor: MapColor = defaultDarkMapColor(), + satelliteMapColor: MapColor = defaultSatelliteMapColor() + ): MapColors { + return MapColors( + normalMapColor = normalMapColor, + satelliteMapColor = satelliteMapColor, + darkMapColor = darkMapColor + ) + } + + fun defaultNormalMapColor( + gridLineColor: Color = Color(0x29697F8D), + markerColors: MarkerColors = defaultMarkerColor() + ): MapColor { + return MapColor( + gridLineColor = gridLineColor, + markerColors = markerColors + ) + } + + fun defaultSatelliteMapColor( + gridLineColor: Color = Color(0x29FFFFFF), + markerColors: MarkerColors = defaultMarkerColor( + selectedZoomOutColor = W3WMarkerColor(background = Color(0xffdbeffa), slash = Color(0xff0a3049)), + selectedColor = Color(0xfffcfcff) + ) + ): MapColor { + return MapColor( + gridLineColor = gridLineColor, + markerColors = markerColors + ) + } + + fun defaultDarkMapColor( + gridLineColor: Color = Color(0x29FFFFFF), + markerColors: MarkerColors = defaultMarkerColor( + selectedZoomOutColor = W3WMarkerColor(background = Color(0xffdbeffa), slash = Color(0xff0a3049)), + selectedColor = Color(0xfffcfcff) + ) + ): MapColor { + return MapColor( + gridLineColor = gridLineColor, + markerColors = markerColors + ) + } + + fun defaultMarkerColor( + selectedZoomOutColor: W3WMarkerColor = W3WMarkerColor(background = Color(0xFF0A3049), slash = Color(0xFFFCFCFF)), + defaultMarkerColor: W3WMarkerColor = W3WMarkerColor(background = Color(0xffe11f26), slash = Color(0xfffffbff)), + selectedColor: Color = Color(0xFF0A3049), + ): MarkerColors { + return MarkerColors( selectedZoomOutColor = selectedZoomOutColor, defaultMarkerColor = defaultMarkerColor, - selectedZoomInColor = selectedColor, - selectedZoomInColorDarkMode = selectedColorDarkMode + selectedColor = selectedColor ) } } \ No newline at end of file diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/MyLocationButton.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/MyLocationButton.kt index d906e1a4..f745cbfa 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/MyLocationButton.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/MyLocationButton.kt @@ -69,6 +69,7 @@ fun MyLocationButton( locationStatus: LocationStatus, unitMetrics: String = METER, buttonConfig: W3WMapButtonsDefault.LocationButtonConfig = W3WMapButtonsDefault.defaultLocationButtonConfig(), + colors: W3WMapButtonsDefault.LocationButtonColor = W3WMapButtonsDefault.defaultLocationButtonColor(), resourceString: W3WMapButtonsDefault.ResourceString = W3WMapButtonsDefault.defaultResourceString(), contentDescription: W3WMapButtonsDefault.ContentDescription = W3WMapButtonsDefault.defaultContentDescription(), onMyLocationClicked: () -> Unit @@ -83,8 +84,8 @@ fun MyLocationButton( } val locationIconColor = when (locationStatus) { - LocationStatus.ACTIVE -> buttonConfig.locationButtonColor.locationIconColorActive - else -> buttonConfig.locationButtonColor.locationIconColorInactive + LocationStatus.ACTIVE -> colors.locationIconColorActive + else -> colors.locationIconColorInactive } LaunchedEffect(isShowingAccuracy) { @@ -116,13 +117,13 @@ fun MyLocationButton( ) ) // Rounded on the start side // TODO: The alpha for light mode is too much transparent, original is 0.16 - .background(buttonConfig.locationButtonColor.accuracyBackgroundColor) + .background(colors.accuracyBackgroundColor) .padding(start = 12.dp, end = 4.dp) ) { Text( text = resourceString.accuracyMessage.format(accuracyDistance, unitMetrics), style = buttonConfig.accuracyTextStyle, - color = buttonConfig.locationButtonColor.accuracyTextColor, + color = colors.accuracyTextColor, maxLines = 1 // Prevent text overflow ) Spacer(Modifier.size(buttonConfig.locationButtonSize / 2)) @@ -137,7 +138,7 @@ fun MyLocationButton( .align(Alignment.CenterEnd) .shadow(elevation = 3.dp, shape = CircleShape) .clip(CircleShape) - .background(buttonConfig.locationButtonColor.locationBackgroundColor) + .background(colors.locationBackgroundColor) .size(buttonConfig.locationButtonSize), onClick = { onMyLocationClicked() @@ -159,6 +160,7 @@ fun MyLocationButton( modifier = Modifier.align(Alignment.TopEnd), accuracyDistance = accuracyDistance, buttonConfig = buttonConfig, + colors = colors, contentDescription = contentDescription ) } @@ -171,16 +173,17 @@ private fun WarningIndicator( modifier: Modifier, accuracyDistance: Int, buttonConfig: W3WMapButtonsDefault.LocationButtonConfig, + colors: W3WMapButtonsDefault.LocationButtonColor, contentDescription: W3WMapButtonsDefault.ContentDescription, ) { val indicatorBackgroundColor = when { accuracyDistance in SAFE_ACCURACY_DISTANCE until WARNING_ACCURACY_DISTANCE -> { - buttonConfig.locationButtonColor.warningLowBackgroundColor + colors.warningLowBackgroundColor } accuracyDistance >= WARNING_ACCURACY_DISTANCE -> { - buttonConfig.locationButtonColor.warningHighBackgroundColor + colors.warningHighBackgroundColor } else -> return @@ -188,11 +191,11 @@ private fun WarningIndicator( val indicatorIconColor = when { accuracyDistance in SAFE_ACCURACY_DISTANCE until WARNING_ACCURACY_DISTANCE -> { - buttonConfig.locationButtonColor.warningLowIconColor + colors.warningLowIconColor } accuracyDistance >= WARNING_ACCURACY_DISTANCE -> { - buttonConfig.locationButtonColor.warningHighIconColor + colors.warningHighIconColor } else -> return diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/RecallButton.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/RecallButton.kt index 2d024aa0..988ff162 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/RecallButton.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/RecallButton.kt @@ -42,8 +42,8 @@ import androidx.compose.ui.unit.dp fun RecallButton( modifier: Modifier = Modifier, rotation: Float = 0F, - backgroundColor: Color = Color(0xFFE11F26), - arrowColor: Color = Color.White, + backgroundColor: Color, + arrowColor: Color, isVisible: Boolean = false, contentDescription: W3WMapButtonsDefault.ContentDescription = W3WMapButtonsDefault.defaultContentDescription(), onRecallClicked: () -> Unit, diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtons.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtons.kt index e82b0830..4659d0fe 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtons.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtons.kt @@ -31,6 +31,7 @@ fun W3WMapButtons( isLocationEnabled: Boolean, resourceString: W3WMapButtonsDefault.ResourceString = W3WMapButtonsDefault.defaultResourceString(), contentDescription: W3WMapButtonsDefault.ContentDescription = W3WMapButtonsDefault.defaultContentDescription(), + buttonColors: W3WMapButtonsDefault.ButtonColors = W3WMapButtonsDefault.defaultButtonColors(), onMyLocationClicked: (() -> Unit), onMapTypeClicked: ((W3WMapType) -> Unit), onRecallClicked: (() -> Unit), @@ -57,6 +58,7 @@ fun W3WMapButtons( accuracyDistance = buttonState.accuracyDistance.toInt(), isButtonEnabled = isLocationEnabled, locationStatus = buttonState.locationStatus, + colors = buttonColors.locationButtonColor, onMyLocationClicked = onMyLocationClicked, resourceString = resourceString, contentDescription = contentDescription, diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtonsDefault.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtonsDefault.kt index ec29f62c..f4c1848a 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtonsDefault.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/W3WMapButtonsDefault.kt @@ -16,6 +16,10 @@ import androidx.compose.ui.unit.dp import com.what3words.design.library.ui.theme.w3wColorScheme object W3WMapButtonsDefault { + @Immutable + data class ButtonColors( + val locationButtonColor: LocationButtonColor + ) @Immutable data class LocationButtonConfig( @@ -25,7 +29,6 @@ object W3WMapButtonsDefault { val locationIconSize: Dp, val accuracyIndicatorSize: Dp, val accuracyTextStyle: TextStyle, - val locationButtonColor: LocationButtonColor, ) @Immutable @@ -54,6 +57,15 @@ object W3WMapButtonsDefault { val mapSwitchButtonDescription: String, ) + @Composable + fun defaultButtonColors( + locationButtonColor: LocationButtonColor = defaultLocationButtonColor() + ): ButtonColors { + return ButtonColors( + locationButtonColor = locationButtonColor + ) + } + @Composable fun defaultLocationButtonColor( locationBackgroundColor: Color = MaterialTheme.colorScheme.surface, @@ -92,10 +104,7 @@ object W3WMapButtonsDefault { locationButtonSize: Dp = 50.dp, locationIconSize: Dp = 30.dp, accuracyIndicatorSize: Dp = 20.dp, - accuracyTextStyle: TextStyle = MaterialTheme.typography.labelSmall.copy( - color = MaterialTheme.colorScheme.onSecondaryContainer - ), - locationButtonColor: LocationButtonColor = defaultLocationButtonColor(), + accuracyTextStyle: TextStyle = MaterialTheme.typography.labelSmall ): LocationButtonConfig { return LocationButtonConfig( enterAnimation = enterAnimation, @@ -104,7 +113,6 @@ object W3WMapButtonsDefault { locationIconSize = locationIconSize, accuracyIndicatorSize = accuracyIndicatorSize, accuracyTextStyle = accuracyTextStyle, - locationButtonColor = defaultLocationButtonColor() ) } diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMap.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMap.kt index 8c4934de..4d4dabdd 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMap.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMap.kt @@ -51,6 +51,7 @@ fun W3WGoogleMap( modifier: Modifier, layoutConfig: W3WMapDefaults.LayoutConfig, mapConfig: W3WMapDefaults.MapConfig, + mapColor: W3WMapDefaults.MapColor, state: W3WMapState, content: (@Composable () -> Unit)? = null, onMarkerClicked: (W3WMarker) -> Unit, @@ -129,7 +130,12 @@ fun W3WGoogleMap( MapEffect(Unit) { map -> mapProjection = W3WGoogleMapProjection(map.projection) } - W3WGoogleMapDrawer(state = state, mapConfig, onMarkerClicked) + W3WGoogleMapDrawer( + state = state, + mapConfig = mapConfig, + mapColor = mapColor, + onMarkerClicked = onMarkerClicked + ) content?.invoke() } } diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMapDrawer.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMapDrawer.kt index b6ec3a62..992ee620 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMapDrawer.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/googlemap/W3WGoogleMapDrawer.kt @@ -8,6 +8,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue +import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.platform.LocalDensity import com.google.android.gms.maps.model.BitmapDescriptor @@ -22,11 +23,11 @@ import com.google.maps.android.compose.MarkerState import com.google.maps.android.compose.Polyline import com.what3words.components.compose.maps.W3WMapDefaults import com.what3words.components.compose.maps.W3WMapDefaults.MIN_SUPPORT_GRID_ZOOM_LEVEL_GOOGLE -import com.what3words.components.compose.maps.W3WMapDefaults.defaultMarkerConfig import com.what3words.components.compose.maps.extensions.contains import com.what3words.components.compose.maps.extensions.id import com.what3words.components.compose.maps.mapper.toGoogleLatLng import com.what3words.components.compose.maps.models.W3WMarker +import com.what3words.components.compose.maps.models.W3WMarkerColor import com.what3words.components.compose.maps.state.W3WMapState import com.what3words.components.compose.maps.utils.getFillGridMarkerBitmap import com.what3words.components.compose.maps.utils.getMarkerBitmap @@ -51,6 +52,7 @@ import kotlinx.collections.immutable.toPersistentList fun W3WGoogleMapDrawer( state: W3WMapState, mapConfig: W3WMapDefaults.MapConfig, + mapColor: W3WMapDefaults.MapColor, onMarkerClicked: (W3WMarker) -> Unit ) { state.cameraState?.let { cameraState -> @@ -65,8 +67,7 @@ fun W3WGoogleMapDrawer( W3WGoogleMapDrawGridLines( verticalLines = state.gridLines.verticalLines, horizontalLines = state.gridLines.horizontalLines, - gridLinesConfig = mapConfig.gridLineConfig, - isDarkMode = state.isDarkMode + gridLineColor = mapColor.gridLineColor ) } @@ -129,7 +130,7 @@ fun W3WGoogleMapDrawer( //Draw the markers W3WGoogleMapDrawMarkers( - markerConfig = mapConfig.markerConfig, + defaultMarkerColor = mapColor.markerColors.defaultMarkerColor, zoomLevel = cameraState.getZoomLevel(), zoomSwitchLevel = mapConfig.gridLineConfig.zoomSwitchLevel, markers = state.markers, @@ -147,11 +148,10 @@ fun W3WGoogleMapDrawer( //Draw the selected address W3WGoogleMapDrawSelectedAddress( - markerConfig = mapConfig.markerConfig, + markerColors = mapColor.markerColors, zoomLevel = cameraState.getZoomLevel(), zoomSwitchLevel = mapConfig.gridLineConfig.zoomSwitchLevel, selectedAddress = state.selectedAddress, - isDarkMode = state.isDarkMode, markersInSelectedAddress = markersInSelectedAddress ) } @@ -164,15 +164,8 @@ fun W3WGoogleMapDrawer( fun W3WGoogleMapDrawGridLines( verticalLines: List, horizontalLines: List, - gridLinesConfig: W3WMapDefaults.GridLinesConfig, - isDarkMode: Boolean + gridLineColor: Color ) { - val gridLineColor = remember(isDarkMode) { - derivedStateOf { - if (isDarkMode) gridLinesConfig.gridColorDarkMode else gridLinesConfig.gridColor - } - } - val horizontalPolylines = remember(horizontalLines) { horizontalLines.map { LatLng(it.lat, it.lng) } } @@ -183,7 +176,7 @@ fun W3WGoogleMapDrawGridLines( Polyline( points = horizontalPolylines, - color = gridLineColor.value, + color = gridLineColor, width = 1f, clickable = false, zIndex = 1f @@ -191,7 +184,7 @@ fun W3WGoogleMapDrawGridLines( Polyline( points = verticalPolylines, - color = gridLineColor.value, + color = gridLineColor, width = 1f, clickable = false, zIndex = 1f @@ -201,12 +194,11 @@ fun W3WGoogleMapDrawGridLines( @Composable @GoogleMapComposable fun W3WGoogleMapDrawSelectedAddress( - markerConfig: W3WMapDefaults.MarkerConfig = defaultMarkerConfig(), + markerColors: W3WMapDefaults.MarkerColors = W3WMapDefaults.defaultMarkerColor(), zoomLevel: Float, zoomSwitchLevel: Float, selectedAddress: W3WAddress, - markersInSelectedAddress: ImmutableList, - isDarkMode: Boolean + markersInSelectedAddress: ImmutableList ) { val density = LocalDensity.current.density @@ -225,30 +217,29 @@ fun W3WGoogleMapDrawSelectedAddress( if (drawZoomIn.value) { DrawZoomInSelectedAddress( - markerConfig = markerConfig, + selectedMarkerColor = markerColors.selectedColor, gridLineWidth = gridLineWidth.value, selectedAddress = selectedAddress, - isDarkMode = isDarkMode ) } else { - DrawZoomOutSelectedAddress(markerConfig, selectedAddress, markersInSelectedAddress) + DrawZoomOutSelectedAddress(markerColors, selectedAddress, markersInSelectedAddress) } } @Composable @GoogleMapComposable private fun DrawZoomOutSelectedAddress( - markerConfig: W3WMapDefaults.MarkerConfig, + markerColors: W3WMapDefaults.MarkerColors, selectedAddress: W3WAddress, - markersInSelectedSquare: ImmutableList, + markersInSelectedSquare: ImmutableList ) { val context = LocalContext.current val density = LocalDensity.current.density val color = when (markersInSelectedSquare.size) { - 0 -> markerConfig.selectedZoomOutColor + 0 -> markerColors.selectedZoomOutColor 1 -> markersInSelectedSquare.first().color - else -> markerConfig.defaultMarkerColor + else -> markerColors.defaultMarkerColor } val markerState = rememberUpdatedMarkerState(selectedAddress.center!!.toGoogleLatLng()) @@ -276,15 +267,10 @@ private fun DrawZoomOutSelectedAddress( @Composable @GoogleMapComposable private fun DrawZoomInSelectedAddress( - markerConfig: W3WMapDefaults.MarkerConfig, + selectedMarkerColor: Color, selectedAddress: W3WAddress, - gridLineWidth: Float, - isDarkMode: Boolean + gridLineWidth: Float ) { - val color = remember(isDarkMode) { - derivedStateOf { if (isDarkMode) markerConfig.selectedZoomInColorDarkMode else markerConfig.selectedZoomInColor } - } - selectedAddress.square?.let { square -> Polyline( points = listOf( @@ -309,7 +295,7 @@ private fun DrawZoomInSelectedAddress( square.southwest.lng ) ), - color = color.value, + color = selectedMarkerColor, width = gridLineWidth, clickable = false, zIndex = 1f @@ -321,7 +307,7 @@ private fun DrawZoomInSelectedAddress( @Composable @GoogleMapComposable fun W3WGoogleMapDrawMarkers( - markerConfig: W3WMapDefaults.MarkerConfig = defaultMarkerConfig(), + defaultMarkerColor: W3WMarkerColor, zoomLevel: Float, zoomSwitchLevel: Float, markers: ImmutableList, @@ -346,12 +332,12 @@ fun W3WGoogleMapDrawMarkers( if (drawZoomIn.value) { DrawZoomInMarkers( - markerConfig = markerConfig, + defaultMarkerColor = defaultMarkerColor, markers = markers ) } else { DrawZoomOutMarkers( - markerConfig = markerConfig, + defaultMarkerColor = defaultMarkerColor, markers = zoomOutMarkers.value, onMarkerClicked = onMarkerClicked ) @@ -360,7 +346,7 @@ fun W3WGoogleMapDrawMarkers( @Composable private fun DrawZoomInMarkers( - markerConfig: W3WMapDefaults.MarkerConfig, + defaultMarkerColor: W3WMarkerColor, markers: ImmutableList ) { val context = LocalContext.current @@ -375,7 +361,7 @@ private fun DrawZoomInMarkers( markersBySquareId.forEach { (_, markers) -> val color = - if (markers.size == 1) markers.first().color else markerConfig.defaultMarkerColor + if (markers.size == 1) markers.first().color else defaultMarkerColor val icon = bitmapCache.getOrPut(color.id) { BitmapDescriptorFactory.fromBitmap( @@ -405,7 +391,7 @@ private fun DrawZoomInMarkers( @Composable private fun DrawZoomOutMarkers( - markerConfig: W3WMapDefaults.MarkerConfig, + defaultMarkerColor: W3WMarkerColor, markers: ImmutableList, onMarkerClicked: (W3WMarker) -> Unit ) { @@ -422,7 +408,7 @@ private fun DrawZoomOutMarkers( markersBySquareId.forEach { (_, markers) -> val color = - if (markers.size == 1) markers.first().color else markerConfig.defaultMarkerColor + if (markers.size == 1) markers.first().color else defaultMarkerColor val icon = bitmapCache.getOrPut(color.id) { BitmapDescriptorFactory.fromBitmap( diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBox.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBox.kt index d6ff40b1..996c501a 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBox.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBox.kt @@ -60,6 +60,7 @@ fun W3WMapBox( modifier: Modifier, layoutConfig: W3WMapDefaults.LayoutConfig, mapConfig: W3WMapDefaults.MapConfig, + mapColor: W3WMapDefaults.MapColor, state: W3WMapState, content: (@Composable () -> Unit)? = null, onMarkerClicked: (W3WMarker) -> Unit, @@ -215,7 +216,12 @@ fun W3WMapBox( } } - W3WMapBoxDrawer(state, mapConfig, onMarkerClicked) + W3WMapBoxDrawer( + state = state, + mapConfig = mapConfig, + mapColor = mapColor, + onMarkerClicked = onMarkerClicked + ) content?.invoke() } } diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBoxDrawers.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBoxDrawers.kt index 9baba134..50ff9284 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBoxDrawers.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/providers/mapbox/W3WMapBoxDrawers.kt @@ -10,6 +10,7 @@ import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember import androidx.compose.runtime.rememberUpdatedState import androidx.compose.runtime.setValue +import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.asImageBitmap import androidx.compose.ui.graphics.painter.BitmapPainter import androidx.compose.ui.platform.LocalContext @@ -36,10 +37,10 @@ import com.mapbox.maps.plugin.annotation.generated.PointAnnotationOptions import com.mapbox.maps.plugin.annotation.generated.PolylineAnnotationOptions import com.what3words.components.compose.maps.W3WMapDefaults import com.what3words.components.compose.maps.W3WMapDefaults.MIN_SUPPORT_GRID_ZOOM_LEVEL_MAP_BOX -import com.what3words.components.compose.maps.W3WMapDefaults.defaultMarkerConfig import com.what3words.components.compose.maps.extensions.contains import com.what3words.components.compose.maps.extensions.id import com.what3words.components.compose.maps.models.W3WMarker +import com.what3words.components.compose.maps.models.W3WMarkerColor import com.what3words.components.compose.maps.state.W3WMapState import com.what3words.components.compose.maps.utils.getFillGridMarkerBitmap import com.what3words.components.compose.maps.utils.getMarkerBitmap @@ -56,6 +57,7 @@ import kotlinx.collections.immutable.toPersistentList fun W3WMapBoxDrawer( state: W3WMapState, mapConfig: W3WMapDefaults.MapConfig, + mapColor: W3WMapDefaults.MapColor, onMarkerClicked: (W3WMarker) -> Unit ) { state.cameraState?.let { cameraState -> @@ -69,8 +71,7 @@ fun W3WMapBoxDrawer( W3WMapBoxDrawGridLines( verticalLines = state.gridLines.verticalLines, horizontalLines = state.gridLines.horizontalLines, - gridLinesConfig = mapConfig.gridLineConfig, - isDarkMode = state.isDarkMode + gridLineColor = mapColor.gridLineColor, ) } @@ -131,7 +132,7 @@ fun W3WMapBoxDrawer( } W3WMapBoxDrawMarkers( - markerConfig = mapConfig.markerConfig, + defaultMarkerColor = mapColor.markerColors.defaultMarkerColor, zoomLevel = cameraState.getZoomLevel(), zoomSwitchLevel = mapConfig.gridLineConfig.zoomSwitchLevel, markers = visibleMarkers, @@ -150,11 +151,10 @@ fun W3WMapBoxDrawer( //Draw the selected address W3WMapBoxDrawSelectedAddress( - markerConfig = mapConfig.markerConfig, + markerColors = mapColor.markerColors, zoomLevel = cameraState.getZoomLevel(), zoomSwitchLevel = mapConfig.gridLineConfig.zoomSwitchLevel, selectedAddress = state.selectedAddress, - isDarkMode = state.isDarkMode, markersInSelectedSquare = markersInSelectedSquare ) } @@ -166,15 +166,8 @@ fun W3WMapBoxDrawer( fun W3WMapBoxDrawGridLines( verticalLines: List, horizontalLines: List, - gridLinesConfig: W3WMapDefaults.GridLinesConfig, - isDarkMode: Boolean + gridLineColor: Color ) { - val gridLineColor = remember(isDarkMode) { - derivedStateOf { - if (isDarkMode) gridLinesConfig.gridColorDarkMode else gridLinesConfig.gridColor - } - } - val polylines = remember(verticalLines, horizontalLines) { listOf( PolylineAnnotationOptions() @@ -191,7 +184,7 @@ fun W3WMapBoxDrawGridLines( lineOcclusionOpacity = 0.0 lineEmissiveStrength = 1.0 lineWidth = 1.0 - lineColor = gridLineColor.value + lineColor = gridLineColor } } ) @@ -200,12 +193,11 @@ fun W3WMapBoxDrawGridLines( @Composable @MapboxMapComposable fun W3WMapBoxDrawSelectedAddress( - markerConfig: W3WMapDefaults.MarkerConfig = defaultMarkerConfig(), + markerColors: W3WMapDefaults.MarkerColors = W3WMapDefaults.defaultMarkerColor(), zoomLevel: Float, zoomSwitchLevel: Float, selectedAddress: W3WAddress, markersInSelectedSquare: ImmutableList, - isDarkMode: Boolean, ) { val drawZoomIn = remember(zoomLevel) { derivedStateOf { @@ -221,14 +213,13 @@ fun W3WMapBoxDrawSelectedAddress( } DrawZoomInSelectedAddress( - markerConfig = markerConfig, + selectedMarkerColor = markerColors.selectedColor, gridLineWidth = gridLineWidth.value, selectedAddress = selectedAddress, - isDarkMode = isDarkMode, ) } else { DrawZoomOutSelectedAddress( - markerConfig, + markerColors, selectedAddress, markersInSelectedSquare ) @@ -238,7 +229,7 @@ fun W3WMapBoxDrawSelectedAddress( @Composable @MapboxMapComposable fun W3WMapBoxDrawMarkers( - markerConfig: W3WMapDefaults.MarkerConfig = defaultMarkerConfig(), + defaultMarkerColor: W3WMarkerColor, zoomLevel: Float, zoomSwitchLevel: Float, markers: ImmutableList, @@ -263,12 +254,12 @@ fun W3WMapBoxDrawMarkers( if (drawZoomIn.value) { DrawZoomInMarkers( - markerConfig, + defaultMarkerColor, markers ) } else { DrawZoomOutMarkers( - markerConfig, + defaultMarkerColor, zoomOutMarkers.value, onMarkerClicked, ) @@ -278,7 +269,7 @@ fun W3WMapBoxDrawMarkers( @Composable @MapboxMapComposable private fun DrawZoomOutMarkers( - markerConfig: W3WMapDefaults.MarkerConfig, + defaultMarkerColor: W3WMarkerColor, markers: ImmutableList, onMarkerClicked: (W3WMarker) -> Unit ) { @@ -296,7 +287,7 @@ private fun DrawZoomOutMarkers( val annotations = remember(markers) { markersBySquareId.keys.map { squareId -> val color = if (markersBySquareId[squareId]!!.size == 1) markersBySquareId[squareId]!! - .first().color else markerConfig.defaultMarkerColor + .first().color else defaultMarkerColor val bitmap = bitmapCache.getOrPut(color.id) { getPinBitmap( @@ -332,7 +323,7 @@ private fun DrawZoomOutMarkers( @Composable @MapboxMapComposable private fun DrawZoomInMarkers( - markerConfig: W3WMapDefaults.MarkerConfig, + defaultMarkerColor: W3WMarkerColor, markers: ImmutableList ) { val context = LocalContext.current @@ -347,7 +338,7 @@ private fun DrawZoomInMarkers( markersBySquareId.forEach { (squareId, markers) -> val color = - if (markers.size == 1) markers.first().color else markerConfig.defaultMarkerColor + if (markers.size == 1) markers.first().color else defaultMarkerColor val bitmap = bitmapCache.getOrPut(color.id) { getFillGridMarkerBitmap( @@ -387,7 +378,7 @@ private fun DrawZoomInMarkers( @Composable @MapboxMapComposable private fun DrawZoomOutSelectedAddress( - markerConfig: W3WMapDefaults.MarkerConfig, + markerColors: W3WMapDefaults.MarkerColors, selectedAddress: W3WAddress, markersInSelectedSquare: ImmutableList, ) { @@ -395,9 +386,9 @@ private fun DrawZoomOutSelectedAddress( val density = LocalDensity.current.density val color = when (markersInSelectedSquare.size) { - 0 -> markerConfig.selectedZoomOutColor + 0 -> markerColors.selectedZoomOutColor 1 -> markersInSelectedSquare.first().color - else -> markerConfig.defaultMarkerColor + else -> markerColors.defaultMarkerColor } val marker = rememberIconImage( @@ -427,15 +418,10 @@ private fun DrawZoomOutSelectedAddress( @Composable @MapboxMapComposable private fun DrawZoomInSelectedAddress( - markerConfig: W3WMapDefaults.MarkerConfig, + selectedMarkerColor: Color, selectedAddress: W3WAddress, - gridLineWidth: Double, - isDarkMode: Boolean + gridLineWidth: Double ) { - val color = remember(isDarkMode) { - derivedStateOf { if (isDarkMode) markerConfig.selectedZoomInColorDarkMode else markerConfig.selectedZoomInColor } - } - selectedAddress.square?.let { square -> PolylineAnnotationGroup( annotations = listOf( @@ -454,7 +440,7 @@ private fun DrawZoomInSelectedAddress( PolylineAnnotationGroupState().apply { lineOcclusionOpacity = 0.0 lineEmissiveStrength = 1.0 - lineColor = color.value + lineColor = selectedMarkerColor lineWidth = gridLineWidth } } diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WMapState.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WMapState.kt index cb7b3019..c0536df1 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WMapState.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WMapState.kt @@ -16,7 +16,7 @@ import kotlinx.collections.immutable.persistentListOf * status of the map, such as language, map type, dark mode, gestures, * selected address, markers, camera state, and grid lines. * @property mapType The type of map displayed. - * @property isDarkMode Whether dark mode is enabled for the map. + * @property isDarkMode Whether dark mode is enabled for the raw map. * @property isMapGestureEnable Whether map gestures are enabled. * @property isMyLocationEnabled Whether the "My Location" feature is enabled. * @property selectedAddress The currently selected what3words address.