Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
) {
Expand All @@ -93,8 +92,6 @@ class W3WMapManager(
private val _buttonState: MutableStateFlow<W3WButtonsState> = MutableStateFlow(buttonState)
val buttonState: StateFlow<W3WButtonsState> = _buttonState.asStateFlow()

private val isRecallButtonEnabled = mapConfig.buttonConfig.isRecallButtonEnabled

private val gridCalculationFlow = MutableStateFlow<W3WCameraState<*>?>(null)

init {
Expand Down Expand Up @@ -233,7 +230,7 @@ class W3WMapManager(
}
gridCalculationFlow.value = newCameraState

if (isRecallButtonEnabled) {
if (_buttonState.value.isRecallButtonEnabled) {
handleRecallButton()
}
}
Expand Down Expand Up @@ -362,7 +359,7 @@ class W3WMapManager(
)
}

if (isRecallButtonEnabled) {
if (_buttonState.value.isRecallButtonEnabled) {
handleRecallButton()
}
}
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down