Skip to content

Commit

Permalink
Fix Android zoom button behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
ianthetechie committed Nov 26, 2024
1 parent 7cd7a1e commit e92e910
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,21 @@ package com.stadiamaps.ferrostar.composeui.config
data class VisualNavigationViewConfig(
// Mute
var showMute: Boolean = false,
var onMute: (() -> Unit)? = null,

// Zoom
var showZoom: Boolean = false,
var onZoomIn: (() -> Unit)? = null,
var onZoomOut: (() -> Unit)? = null,
) {
companion object {
fun Default() = VisualNavigationViewConfig(showMute = true, showZoom = true)
}
}

/** Enables the mute button in the navigation view. */
fun VisualNavigationViewConfig.useMuteButton(onMute: () -> Unit): VisualNavigationViewConfig {
return copy(showMute = true, onMute = onMute)
fun VisualNavigationViewConfig.useMuteButton(): VisualNavigationViewConfig {
return copy(showMute = true)
}

/** Enables the zoom button in the navigation view. */
fun VisualNavigationViewConfig.useZoomButton(
onZoomIn: () -> Unit,
onZoomOut: () -> Unit
): VisualNavigationViewConfig {
return copy(showZoom = true, onZoomIn = onZoomIn, onZoomOut = onZoomOut)
fun VisualNavigationViewConfig.useZoomButton(): VisualNavigationViewConfig {
return copy(showZoom = true)
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ fun LandscapeNavigationOverlayView(
cameraControlState: CameraControlState,
theme: NavigationUITheme = DefaultNavigationUITheme,
config: VisualNavigationViewConfig = VisualNavigationViewConfig.Default(),
onClickZoomIn: (() -> Unit)? = null,
onClickZoomOut: (() -> Unit)? = null,
views: NavigationViewComponentBuilder = NavigationViewComponentBuilder.Default(theme),
mapViewInsets: MutableState<PaddingValues>,
onTapExit: (() -> Unit)? = null,
Expand Down Expand Up @@ -96,8 +98,8 @@ fun LandscapeNavigationOverlayView(
buttonSize = theme.buttonSize,
cameraControlState = cameraControlState,
showZoom = config.showZoom,
onClickZoomIn = { config.onZoomIn?.invoke() },
onClickZoomOut = { config.onZoomOut?.invoke() },
onClickZoomIn = { onClickZoomIn?.invoke() },
onClickZoomOut = { onClickZoomOut?.invoke() },
bottomCenter = {
views.streetNameView(Modifier, uiState.currentStepRoadName, cameraControlState)
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ fun PortraitNavigationOverlayView(
cameraControlState: CameraControlState,
theme: NavigationUITheme = DefaultNavigationUITheme,
config: VisualNavigationViewConfig = VisualNavigationViewConfig.Default(),
onClickZoomIn: (() -> Unit)? = null,
onClickZoomOut: (() -> Unit)? = null,
views: NavigationViewComponentBuilder = NavigationViewComponentBuilder.Default(theme),
mapViewInsets: MutableState<PaddingValues>,
onTapExit: (() -> Unit)? = null,
Expand Down Expand Up @@ -77,8 +79,8 @@ fun PortraitNavigationOverlayView(
buttonSize = theme.buttonSize,
cameraControlState = cameraControlState,
showZoom = config.showZoom,
onClickZoomIn = { config.onZoomIn?.invoke() },
onClickZoomOut = { config.onZoomOut?.invoke() },
onClickZoomIn = { onClickZoomIn?.invoke() },
onClickZoomOut = { onClickZoomOut?.invoke() },
bottomCenter = {
views.streetNameView(Modifier, uiState.currentStepRoadName, cameraControlState)
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import androidx.compose.ui.platform.LocalConfiguration
import androidx.compose.ui.unit.DpSize
import androidx.compose.ui.unit.dp
import com.maplibre.compose.camera.MapViewCamera
import com.maplibre.compose.camera.extensions.incrementZoom
import com.maplibre.compose.ramani.LocationRequestProperties
import com.maplibre.compose.ramani.MapLibreComposable
import com.maplibre.compose.rememberSaveableMapViewCamera
Expand Down Expand Up @@ -115,6 +116,8 @@ fun DynamicallyOrientingNavigationView(
),
theme = theme,
config = config,
onClickZoomIn = { camera.value.incrementZoom(1.0) },
onClickZoomOut = { camera.value.incrementZoom(-1.0) },
views = views,
mapViewInsets = mapViewInsets,
onTapExit = onTapExit)
Expand All @@ -133,6 +136,8 @@ fun DynamicallyOrientingNavigationView(
),
theme = theme,
config = config,
onClickZoomIn = { camera.value = camera.value.incrementZoom(1.0) },
onClickZoomOut = { camera.value = camera.value.incrementZoom(-1.0) },
views = views,
mapViewInsets = mapViewInsets,
onTapExit = onTapExit)
Expand Down

0 comments on commit e92e910

Please sign in to comment.