Skip to content

Commit 507de52

Browse files
committed
Update button color, map type for switch map button
1 parent d423abe commit 507de52

File tree

10 files changed

+126
-114
lines changed

10 files changed

+126
-114
lines changed

.kotlin/sessions/kotlin-compiler-755236396982485345.salive

Whitespace-only changes.

lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapComponent.kt

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ import com.what3words.components.compose.maps.W3WMapDefaults.MapColors
2525
import com.what3words.components.compose.maps.W3WMapDefaults.defaultMapColors
2626
import com.what3words.components.compose.maps.buttons.W3WMapButtons
2727
import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault
28-
import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault.defaultButtonColors
28+
import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault.defaultLocationButtonColor
29+
import com.what3words.components.compose.maps.extensions.contains
2930
import com.what3words.components.compose.maps.models.W3WGridScreenCell
3031
import com.what3words.components.compose.maps.models.W3WLocationSource
3132
import com.what3words.components.compose.maps.models.W3WMapProjection
@@ -61,7 +62,7 @@ import kotlinx.coroutines.launch
6162
* - If `isDarkMode` is `false`, the normal color scheme (`normalMapColor`) is used.
6263
* - If the `mapType` is `HYBRID` or `SATELLITE`, the satellite color scheme (`satelliteMapColor`) is used, regardless of the dark mode setting.
6364
* @param mapColors [W3WMapDefaults.MapColor] Configuration for the map's color such as light, dark and satellite mode will based on mapType and state isDarkMode
64-
* @param buttonColors [W3WMapButtonsDefault.ButtonColors] Configuration for the button's color which are applied according to the current theme
65+
* @param locationButtonColor Color settings for the location button (the button to center on the user's current location).
6566
* @param mapManager The [W3WMapManager] instance that manages the map's mapState and interactions.
6667
* @param locationSource An optional [W3WLocationSource] used to fetch the user's location.
6768
* @param content Optional composable content to be displayed on the map.
@@ -72,7 +73,7 @@ fun W3WMapComponent(
7273
modifier: Modifier = Modifier,
7374
layoutConfig: W3WMapDefaults.LayoutConfig = W3WMapDefaults.defaultLayoutConfig(),
7475
mapConfig: W3WMapDefaults.MapConfig = W3WMapDefaults.defaultMapConfig(),
75-
buttonColors: W3WMapButtonsDefault.ButtonColors = defaultButtonColors(),
76+
locationButtonColor: W3WMapButtonsDefault.LocationButtonColor = defaultLocationButtonColor(),
7677
mapColors: MapColors = defaultMapColors(),
7778
mapManager: W3WMapManager,
7879
textDataSource: W3WTextDataSource,
@@ -122,7 +123,7 @@ fun W3WMapComponent(
122123
layoutConfig = currentLayoutConfig.value,
123124
mapConfig = currentMapConfig.value,
124125
mapColors = mapColors,
125-
buttonColors = buttonColors,
126+
locationButtonColor = locationButtonColor,
126127
mapProvider = mapManager.mapProvider,
127128
content = content,
128129
mapState = mapState,
@@ -184,7 +185,7 @@ fun W3WMapComponent(
184185
* - If `isDarkMode` is `false`, the normal color scheme (`normalMapColor`) is used.
185186
* - If the `mapType` is `HYBRID` or `SATELLITE`, the satellite color scheme (`satelliteMapColor`) is used, regardless of the dark mode setting.
186187
* @param mapColors [W3WMapDefaults.MapColor] Configuration for the map's color such as light, dark and satellite mode will based on mapType and state isDarkMode
187-
* @param buttonColors [W3WMapButtonsDefault.ButtonColors] Configuration for the button's color which are applied according to the current theme
188+
* @param locationButtonColor Color settings for the location button (the button to center on the user's current location).
188189
* @param mapState The [W3WMapState] object that holds the mapState of the map.
189190
* @param buttonState The [W3WButtonsState] object that holds the buttonState of the map.
190191
* @param mapProvider An instance of enum [MapProvider] to define map provide: GoogleMap, MapBox.
@@ -200,7 +201,7 @@ fun W3WMapComponent(
200201
modifier: Modifier = Modifier,
201202
layoutConfig: W3WMapDefaults.LayoutConfig = W3WMapDefaults.defaultLayoutConfig(),
202203
mapConfig: W3WMapDefaults.MapConfig = W3WMapDefaults.defaultMapConfig(),
203-
buttonColors: W3WMapButtonsDefault.ButtonColors = defaultButtonColors(),
204+
locationButtonColor: W3WMapButtonsDefault.LocationButtonColor = defaultLocationButtonColor(),
204205
mapColors: MapColors = defaultMapColors(),
205206
mapState: W3WMapState,
206207
buttonState: W3WButtonsState,
@@ -222,7 +223,7 @@ fun W3WMapComponent(
222223
layoutConfig = layoutConfig,
223224
mapConfig = mapConfig,
224225
mapColors = mapColors,
225-
buttonColors = buttonColors,
226+
locationButtonColor = locationButtonColor,
226227
mapProvider = mapProvider,
227228
content = content,
228229
mapState = mapState,
@@ -271,7 +272,7 @@ fun W3WMapComponent(
271272
* - If `isDarkMode` is `false`, the normal color scheme (`normalMapColor`) is used.
272273
* - If the `mapType` is `HYBRID` or `SATELLITE`, the satellite color scheme (`satelliteMapColor`) is used, regardless of the dark mode setting.
273274
* @param mapColors [W3WMapDefaults.MapColors] Configuration for the map's color such as light, dark and satellite mode will based on mapType and state isDarkMode
274-
* @param buttonColors [W3WMapButtonsDefault.ButtonColors] Configuration for the button's color which are applied according to the current theme
275+
* @param locationButtonColor Color settings for the location button (the button to center on the user's current location).
275276
* @param mapState The [W3WMapState] object that holds the mapState of the map.
276277
* @param buttonState The [W3WButtonsState] object that holds the buttonState of the map.
277278
* @param mapProvider An instance of enum [MapProvider] to define map provide: GoogleMap, MapBox.
@@ -285,9 +286,9 @@ fun W3WMapComponent(
285286
@Composable
286287
internal fun W3WMapContent(
287288
modifier: Modifier = Modifier,
288-
layoutConfig: W3WMapDefaults.LayoutConfig = W3WMapDefaults.defaultLayoutConfig(),
289-
mapConfig: W3WMapDefaults.MapConfig = W3WMapDefaults.defaultMapConfig(),
290-
buttonColors: W3WMapButtonsDefault.ButtonColors = defaultButtonColors(),
289+
layoutConfig: W3WMapDefaults.LayoutConfig,
290+
mapConfig: W3WMapDefaults.MapConfig,
291+
locationButtonColor: W3WMapButtonsDefault.LocationButtonColor,
291292
mapColors: MapColors = defaultMapColors(),
292293
mapState: W3WMapState,
293294
buttonState: W3WButtonsState,
@@ -334,6 +335,18 @@ internal fun W3WMapContent(
334335
}
335336
}
336337

338+
val recallButtonColor = remember(mapState.selectedAddress, mapState.markers, mapColor) {
339+
derivedStateOf {
340+
val markersAtSelectedSquare = mapState.markers.filter { it.square.contains(mapState.selectedAddress?.center) }
341+
val color = when(markersAtSelectedSquare.size) {
342+
0 -> mapColor.markerColors.selectedZoomOutColor
343+
1 -> markersAtSelectedSquare.first().color
344+
else -> mapColor.markerColors.defaultMarkerColor
345+
}
346+
W3WMapButtonsDefault.RecallButtonColor(recallArrowColor = color.slash, recallBackgroundColor = color.background)
347+
}
348+
}
349+
337350
LaunchedEffect(bounds) {
338351
bounds.let {
339352
val leftTop = PointF(it.left, it.top)
@@ -376,7 +389,9 @@ internal fun W3WMapContent(
376389
.padding(layoutConfig.contentPadding),
377390
buttonConfig = mapConfig.buttonConfig,
378391
buttonState = buttonState,
379-
buttonColors = buttonColors,
392+
mapType = mapState.mapType,
393+
locationButtonColor = locationButtonColor,
394+
recallButtonColor = recallButtonColor.value,
380395
isLocationEnabled = mapState.isMyLocationEnabled,
381396
onMapTypeClicked = onMapTypeClicked,
382397
onMyLocationClicked = onMyLocationClicked,

lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapDefaults.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import androidx.compose.runtime.Immutable
66
import androidx.compose.ui.graphics.Color
77
import androidx.compose.ui.unit.Dp
88
import androidx.compose.ui.unit.dp
9-
import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault
10-
import com.what3words.components.compose.maps.buttons.W3WMapButtonsDefault.defaultButtonColors
119
import com.what3words.components.compose.maps.models.DarkModeStyle
1210
import com.what3words.components.compose.maps.models.W3WMarkerColor
1311
import com.what3words.core.types.geometry.W3WCoordinates

lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapManager.kt

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import androidx.annotation.RequiresPermission
66
import androidx.compose.runtime.Composable
77
import androidx.compose.runtime.saveable.Saver
88
import androidx.compose.runtime.saveable.rememberSaveable
9-
import androidx.compose.ui.graphics.Color
109
import com.google.android.gms.maps.model.CameraPosition
1110
import com.google.maps.android.compose.CameraPositionState
1211
import com.mapbox.geojson.Point
@@ -1603,41 +1602,8 @@ class W3WMapManager(
16031602
}
16041603
}
16051604

1606-
private suspend fun updateRecallButtonColor() {
1607-
withContext(dispatcher) {
1608-
val selectedLatLng = getSelectedAddress()?.center ?: return@withContext
1609-
//TODO: Find solution to handle color in composable side due to manager no keep the color config
1610-
// val markerColor = when (markersAtSelectedSquare.size) {
1611-
// 0 -> mapConfig?.markerConfig?.selectedZoomOutColor
1612-
// 1 -> markersAtSelectedSquare.first().marker.color
1613-
// else -> mapConfig?.markerConfig?.defaultMarkerColor
1614-
// }
1615-
1616-
val markersAtSelectedSquare =
1617-
getMarkersAt(selectedLatLng)
1618-
val markerSlashColor = if (markersAtSelectedSquare.size == 1) {
1619-
markersAtSelectedSquare.first().marker.color.slash
1620-
} else {
1621-
Color.White
1622-
}
1623-
val markerBackgroundColor = if (markersAtSelectedSquare.size == 1) {
1624-
markersAtSelectedSquare.first().marker.color.background
1625-
} else {
1626-
Color(0xFFE11F26) // TODO: Define name for this color
1627-
}
1628-
1629-
_buttonState.update {
1630-
it.copy(
1631-
recallArrowColor = markerSlashColor,
1632-
recallBackgroundColor = markerBackgroundColor
1633-
)
1634-
}
1635-
}
1636-
}
1637-
16381605
private suspend fun handleRecallButton() {
16391606
updateSelectedScreenLocation()
1640-
updateRecallButtonColor()
16411607

16421608
val buttonState = buttonState.value
16431609
val selectedScreenLocation = buttonState.selectedScreenLocation

lib-compose/src/main/java/com/what3words/components/compose/maps/buttons/MyLocationButton.kt

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ const val VISIBLE_TIME = 2000L
5656
* @param isButtonEnabled Whether the location button is enabled or not.
5757
* @param locationStatus The status of the location service.
5858
* @param unitMetrics The unit of accuracy distance, default is "m".
59-
* @param buttonConfig The configuration for the button, default is [W3WMapButtonsDefault.defaultLocationButtonConfig].
59+
* @param layoutConfig Configuration for the button's layout, including positioning, size, and other layout properties. Defaults to [W3WMapButtonsDefault.defaultLocationButtonConfig].
60+
* @param colors Defines the color scheme of the location button, such as background and icon colors. Defaults to [W3WMapButtonsDefault.defaultLocationButtonColor].
6061
* @param resourceString The resource string for the button, default is [W3WMapButtonsDefault.defaultResourceString].
6162
* @param contentDescription The content description for the button, default is [W3WMapButtonsDefault.defaultContentDescription].
6263
* @param onMyLocationClicked The callback when the button is clicked.
@@ -68,7 +69,7 @@ fun MyLocationButton(
6869
isButtonEnabled: Boolean,
6970
locationStatus: LocationStatus,
7071
unitMetrics: String = METER,
71-
buttonConfig: W3WMapButtonsDefault.LocationButtonConfig = W3WMapButtonsDefault.defaultLocationButtonConfig(),
72+
layoutConfig: W3WMapButtonsDefault.LocationButtonLayoutConfig = W3WMapButtonsDefault.defaultLocationButtonConfig(),
7273
colors: W3WMapButtonsDefault.LocationButtonColor = W3WMapButtonsDefault.defaultLocationButtonColor(),
7374
resourceString: W3WMapButtonsDefault.ResourceString = W3WMapButtonsDefault.defaultResourceString(),
7475
contentDescription: W3WMapButtonsDefault.ContentDescription = W3WMapButtonsDefault.defaultContentDescription(),
@@ -102,14 +103,14 @@ fun MyLocationButton(
102103
Row {
103104
AnimatedVisibility(
104105
visible = isShowingAccuracy,
105-
enter = buttonConfig.enterAnimation,
106-
exit = buttonConfig.exitAnimation
106+
enter = layoutConfig.enterAnimation,
107+
exit = layoutConfig.exitAnimation
107108
) {
108109
Row(
109110
verticalAlignment = Alignment.CenterVertically,
110111
horizontalArrangement = Arrangement.End, // Align Row content to end to control animation direction
111112
modifier = Modifier
112-
.height(buttonConfig.locationButtonSize)
113+
.height(layoutConfig.locationButtonSize)
113114
.clip(
114115
RoundedCornerShape(
115116
topStartPercent = 50,
@@ -122,14 +123,14 @@ fun MyLocationButton(
122123
) {
123124
Text(
124125
text = resourceString.accuracyMessage.format(accuracyDistance, unitMetrics),
125-
style = buttonConfig.accuracyTextStyle,
126+
style = layoutConfig.accuracyTextStyle,
126127
color = colors.accuracyTextColor,
127128
maxLines = 1 // Prevent text overflow
128129
)
129-
Spacer(Modifier.size(buttonConfig.locationButtonSize / 2))
130+
Spacer(Modifier.size(layoutConfig.locationButtonSize / 2))
130131
}
131132
}
132-
Spacer(Modifier.size(buttonConfig.locationButtonSize / 2))
133+
Spacer(Modifier.size(layoutConfig.locationButtonSize / 2))
133134
}
134135

135136
Box {
@@ -139,7 +140,7 @@ fun MyLocationButton(
139140
.shadow(elevation = 3.dp, shape = CircleShape)
140141
.clip(CircleShape)
141142
.background(colors.locationBackgroundColor)
142-
.size(buttonConfig.locationButtonSize),
143+
.size(layoutConfig.locationButtonSize),
143144
onClick = {
144145
onMyLocationClicked()
145146
if (locationStatus == LocationStatus.ACTIVE) {
@@ -152,14 +153,14 @@ fun MyLocationButton(
152153
painter = locationIconVector,
153154
contentDescription = contentDescription.locationButtonDescription,
154155
tint = locationIconColor,
155-
modifier = Modifier.size(buttonConfig.locationIconSize)
156+
modifier = Modifier.size(layoutConfig.locationIconSize)
156157
)
157158
}
158159
if (accuracyDistance >= SAFE_ACCURACY_DISTANCE) {
159160
WarningIndicator(
160161
modifier = Modifier.align(Alignment.TopEnd),
161162
accuracyDistance = accuracyDistance,
162-
buttonConfig = buttonConfig,
163+
buttonConfig = layoutConfig,
163164
colors = colors,
164165
contentDescription = contentDescription
165166
)
@@ -172,7 +173,7 @@ fun MyLocationButton(
172173
private fun WarningIndicator(
173174
modifier: Modifier,
174175
accuracyDistance: Int,
175-
buttonConfig: W3WMapButtonsDefault.LocationButtonConfig,
176+
buttonConfig: W3WMapButtonsDefault.LocationButtonLayoutConfig,
176177
colors: W3WMapButtonsDefault.LocationButtonColor,
177178
contentDescription: W3WMapButtonsDefault.ContentDescription,
178179
) {

0 commit comments

Comments
 (0)