Skip to content

Commit 738946d

Browse files
Implement dark mode for button
1 parent 5e63b68 commit 738946d

File tree

10 files changed

+187
-114
lines changed

10 files changed

+187
-114
lines changed

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

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import androidx.compose.ui.layout.onGloballyPositioned
2121
import com.google.accompanist.permissions.ExperimentalPermissionsApi
2222
import com.google.accompanist.permissions.rememberMultiplePermissionsState
2323
import com.what3words.components.compose.maps.buttons.W3WMapButtons
24-
import com.what3words.components.compose.maps.models.W3WLocationSource
2524
import com.what3words.components.compose.maps.models.W3WGridScreenCell
25+
import com.what3words.components.compose.maps.models.W3WLocationSource
2626
import com.what3words.components.compose.maps.models.W3WMapProjection
2727
import com.what3words.components.compose.maps.models.W3WMapType
2828
import com.what3words.components.compose.maps.models.W3WMarker
@@ -84,9 +84,11 @@ fun W3WMapComponent(
8484
mapManager.setMapConfig(currentMapConfig.value)
8585
}
8686

87-
// TODO: Find optimal way to set isRecallButtonEnabled
88-
LaunchedEffect(mapConfig.buttonConfig.isRecallButtonUsed) {
89-
mapManager.setRecallButtonEnabled(mapConfig.buttonConfig.isRecallButtonUsed)
87+
LaunchedEffect(Unit) {
88+
mapManager.setRecallButtonEnabled(mapConfig.buttonConfig.isRecallButtonAvailable)
89+
locationSource?.locationStatus?.collect { status ->
90+
mapManager.updateLocationStatus(status)
91+
}
9092
}
9193

9294
LaunchedEffect(mapState.selectedAddress) {
@@ -314,6 +316,7 @@ internal fun W3WMapContent(
314316
buttonConfig = mapConfig.buttonConfig,
315317
buttonState = buttonState,
316318
isLocationEnabled = mapState.isMyLocationEnabled,
319+
isDarkMode = mapState.isDarkMode,
317320
onMapTypeClicked = onMapTypeClicked,
318321
onMyLocationClicked = onMyLocationClicked,
319322
onRecallClicked = onRecallClicked,
@@ -461,16 +464,12 @@ private fun fetchCurrentLocation(
461464
animate = true
462465
)
463466

464-
465467
if (location.hasAccuracy()) {
466468
mapManager.updateAccuracyDistance(location.accuracy)
467469
}
468470
} catch (e: Exception) {
469471
onError?.invoke(W3WError("Location fetch failed: ${e.message}"))
470472
}
471-
it.isActive.collect { isActive ->
472-
mapManager.updateIsLocationActive(isActive)
473-
}
474473
}
475474
}
476475
}

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

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ object W3WMapDefaults {
9494

9595
@Immutable
9696
data class ButtonConfig(
97-
val isMapSwitchButtonUsed: Boolean,
98-
val isMyLocationButtonUsed: Boolean,
99-
val isRecallButtonUsed: Boolean,
97+
val isMapSwitchButtonAvailable: Boolean,
98+
val isMyLocationButtonAvailable: Boolean,
99+
val isRecallButtonAvailable: Boolean,
100100
)
101101

102102
@Immutable
@@ -151,14 +151,14 @@ object W3WMapDefaults {
151151
}
152152

153153
fun defaultButtonConfig(
154-
isMapSwitchButtonUsed: Boolean = true,
155-
isMyLocationButtonUsed: Boolean = true,
156-
isRecallButtonUsed: Boolean = false
154+
isMapSwitchButtonAvailable: Boolean = true,
155+
isMyLocationButtonAvailable: Boolean = true,
156+
isRecallButtonAvailable: Boolean = false
157157
): ButtonConfig {
158158
return ButtonConfig(
159-
isMapSwitchButtonUsed = isMapSwitchButtonUsed,
160-
isMyLocationButtonUsed = isMyLocationButtonUsed,
161-
isRecallButtonUsed = isRecallButtonUsed
159+
isMapSwitchButtonAvailable = isMapSwitchButtonAvailable,
160+
isMyLocationButtonAvailable = isMyLocationButtonAvailable,
161+
isRecallButtonAvailable = isRecallButtonAvailable
162162
)
163163
}
164164

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import com.what3words.components.compose.maps.models.W3WMarker
2828
import com.what3words.components.compose.maps.models.W3WMarkerColor
2929
import com.what3words.components.compose.maps.models.W3WMarkerWithList
3030
import com.what3words.components.compose.maps.models.W3WZoomOption
31+
import com.what3words.components.compose.maps.state.LocationStatus
3132
import com.what3words.components.compose.maps.state.W3WButtonsState
3233
import com.what3words.components.compose.maps.state.W3WMapState
3334
import com.what3words.components.compose.maps.state.camera.W3WCameraState
@@ -760,9 +761,9 @@ class W3WMapManager(
760761
}
761762
}
762763

763-
fun updateIsLocationActive(isActive: Boolean) {
764+
fun updateLocationStatus(locationStatus: LocationStatus) {
764765
_buttonState.update {
765-
it.copy(isLocationActive = isActive)
766+
it.copy(locationStatus = locationStatus)
766767
}
767768
}
768769

0 commit comments

Comments
 (0)