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 8846d248..8134d659 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 @@ -2,7 +2,6 @@ package com.what3words.components.compose.maps import android.Manifest import android.graphics.PointF -import android.util.Log import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.padding import androidx.compose.runtime.Composable @@ -69,6 +68,10 @@ fun W3WMapComponent( val mapState by mapManager.mapState.collectAsState() val buttonState by mapManager.buttonState.collectAsState() + + // TODO: Find optimal way to set isRecallButtonEnabled + mapManager.setRecallButtonEnabled(mapConfig.buttonConfig.isRecallButtonEnabled) + val coroutineScope = rememberCoroutineScope { Dispatchers.IO } val onMarkerClicked = remember(mapManager) { 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 34793d1d..94c103e1 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 @@ -125,15 +125,15 @@ object W3WMapDefaults { ) } - private fun defaultButtonConfig( + fun defaultButtonConfig( isMapSwitchButtonEnabled: Boolean = true, - isMyLocationButtonEnable: Boolean = true, - isRecallButtonEnable: Boolean = false + isMyLocationButtonEnabled: Boolean = true, + isRecallButtonEnabled: Boolean = false ): ButtonConfig { return ButtonConfig( isMapSwitchButtonEnabled = isMapSwitchButtonEnabled, - isMyLocationButtonEnabled = isMyLocationButtonEnable, - isRecallButtonEnabled = isRecallButtonEnable + isMyLocationButtonEnabled = isMyLocationButtonEnabled, + isRecallButtonEnabled = isRecallButtonEnabled ) } diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapManager.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapManager.kt index d49e464e..15750800 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapManager.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/W3WMapManager.kt @@ -79,7 +79,6 @@ class W3WMapManager( private val textDataSource: W3WTextDataSource, private val dispatcher: CoroutineDispatcher = IO, val mapProvider: MapProvider, - mapConfig: W3WMapDefaults.MapConfig = W3WMapDefaults.defaultMapConfig(), mapState: W3WMapState = W3WMapState(), buttonState: W3WButtonsState = W3WButtonsState(), ) { @@ -93,8 +92,6 @@ class W3WMapManager( private val _buttonState: MutableStateFlow = MutableStateFlow(buttonState) val buttonState: StateFlow = _buttonState.asStateFlow() - private val isRecallButtonEnabled = mapConfig.buttonConfig.isRecallButtonEnabled - private val gridCalculationFlow = MutableStateFlow?>(null) init { @@ -233,7 +230,7 @@ class W3WMapManager( } gridCalculationFlow.value = newCameraState - if (isRecallButtonEnabled) { + if (_buttonState.value.isRecallButtonEnabled) { handleRecallButton() } } @@ -362,7 +359,7 @@ class W3WMapManager( ) } - if (isRecallButtonEnabled) { + if (_buttonState.value.isRecallButtonEnabled) { handleRecallButton() } } @@ -454,6 +451,12 @@ class W3WMapManager( } } + fun setRecallButtonEnabled(isEnabled: Boolean) { + _buttonState.update { + it.copy(isRecallButtonEnabled = isEnabled) + } + } + private suspend fun updateSelectedScreenLocation() { withContext(dispatcher) { val selectedAddress = mapState.value.selectedAddress?.latLng diff --git a/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WButtonsState.kt b/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WButtonsState.kt index 5fffa157..88fe39ac 100644 --- a/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WButtonsState.kt +++ b/lib-compose/src/main/java/com/what3words/components/compose/maps/state/W3WButtonsState.kt @@ -15,6 +15,7 @@ data class W3WButtonsState( // Recall button val isRecallButtonVisible: Boolean = false, + val isRecallButtonEnabled: Boolean = false, val arrowColor: Color = Color.White, val backgroundColor: Color = Color.Red, val rotationDegree: Float = 0F,