From e92e9100ec924abc99deea913bedea9467494ff0 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Tue, 26 Nov 2024 13:13:28 +0900 Subject: [PATCH] Fix Android zoom button behavior --- .../composeui/config/VisualNavigationViewConfig.kt | 14 ++++---------- .../overlays/LandscapeNavigationOverlayView.kt | 6 ++++-- .../overlays/PortraitNavigationOverlayView.kt | 6 ++++-- .../views/DynamicallyOrientingNavigationView.kt | 5 +++++ 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/config/VisualNavigationViewConfig.kt b/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/config/VisualNavigationViewConfig.kt index 509a3949..f2579a86 100644 --- a/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/config/VisualNavigationViewConfig.kt +++ b/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/config/VisualNavigationViewConfig.kt @@ -3,12 +3,9 @@ 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) @@ -16,14 +13,11 @@ data class VisualNavigationViewConfig( } /** 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) } diff --git a/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/LandscapeNavigationOverlayView.kt b/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/LandscapeNavigationOverlayView.kt index 035e1174..828643ee 100644 --- a/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/LandscapeNavigationOverlayView.kt +++ b/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/LandscapeNavigationOverlayView.kt @@ -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, onTapExit: (() -> Unit)? = null, @@ -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) }) diff --git a/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/PortraitNavigationOverlayView.kt b/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/PortraitNavigationOverlayView.kt index f8b136dd..1605417c 100644 --- a/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/PortraitNavigationOverlayView.kt +++ b/android/composeui/src/main/java/com/stadiamaps/ferrostar/composeui/views/overlays/PortraitNavigationOverlayView.kt @@ -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, onTapExit: (() -> Unit)? = null, @@ -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) }, diff --git a/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/DynamicallyOrientingNavigationView.kt b/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/DynamicallyOrientingNavigationView.kt index 42ab0424..d3c02469 100644 --- a/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/DynamicallyOrientingNavigationView.kt +++ b/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/DynamicallyOrientingNavigationView.kt @@ -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 @@ -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) @@ -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)