From e92e9100ec924abc99deea913bedea9467494ff0 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Tue, 26 Nov 2024 13:13:28 +0900 Subject: [PATCH 1/4] 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) From 86eeb4c3a05988e983b2d216b1e081f97f49bd5b Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Tue, 26 Nov 2024 13:20:02 +0900 Subject: [PATCH 2/4] Copy logic to the non-dynamic views --- .../ferrostar/maplibreui/views/LandscapeNavigationView.kt | 3 +++ .../ferrostar/maplibreui/views/PortraitNavigationView.kt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/LandscapeNavigationView.kt b/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/LandscapeNavigationView.kt index 9f0c18b3..0cbbce6c 100644 --- a/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/LandscapeNavigationView.kt +++ b/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/LandscapeNavigationView.kt @@ -17,6 +17,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.tooling.preview.Preview 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 @@ -108,6 +109,8 @@ fun LandscapeNavigationView( ), 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) diff --git a/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/PortraitNavigationView.kt b/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/PortraitNavigationView.kt index 39dbac4e..034fffdc 100644 --- a/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/PortraitNavigationView.kt +++ b/android/maplibreui/src/main/java/com/stadiamaps/ferrostar/maplibreui/views/PortraitNavigationView.kt @@ -20,6 +20,7 @@ import androidx.compose.ui.tooling.preview.Devices import androidx.compose.ui.tooling.preview.Preview 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 @@ -119,6 +120,8 @@ fun PortraitNavigationView( ), 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) From 484e0555840a67b6acd7bdd3eac2b189836269f2 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Tue, 26 Nov 2024 13:33:13 +0900 Subject: [PATCH 3/4] Fix dropped value --- .../maplibreui/views/DynamicallyOrientingNavigationView.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 d3c02469..e6281e54 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 @@ -116,8 +116,8 @@ fun DynamicallyOrientingNavigationView( ), theme = theme, config = config, - onClickZoomIn = { camera.value.incrementZoom(1.0) }, - onClickZoomOut = { camera.value.incrementZoom(-1.0) }, + onClickZoomIn = { camera.value = camera.value.incrementZoom(1.0) }, + onClickZoomOut = { camera.value = camera.value.incrementZoom(-1.0) }, views = views, mapViewInsets = mapViewInsets, onTapExit = onTapExit) From 6bc7cd9f3dcaddd779666ad1bdf0fee0e14d1fd7 Mon Sep 17 00:00:00 2001 From: Ian Wagner Date: Tue, 26 Nov 2024 13:45:25 +0900 Subject: [PATCH 4/4] Fix tests --- .../maplibreui/config/VisualNavigationViewConfigTest.kt | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/android/maplibreui/src/test/java/com/stadiamaps/ferrostar/maplibreui/config/VisualNavigationViewConfigTest.kt b/android/maplibreui/src/test/java/com/stadiamaps/ferrostar/maplibreui/config/VisualNavigationViewConfigTest.kt index 698ce3b3..20dd3b50 100644 --- a/android/maplibreui/src/test/java/com/stadiamaps/ferrostar/maplibreui/config/VisualNavigationViewConfigTest.kt +++ b/android/maplibreui/src/test/java/com/stadiamaps/ferrostar/maplibreui/config/VisualNavigationViewConfigTest.kt @@ -24,22 +24,19 @@ class VisualNavigationViewConfigTest { @Test fun testUseMuteButton() { - val config = VisualNavigationViewConfig().useMuteButton(onMute = {}) + val config = VisualNavigationViewConfig().useMuteButton() assert(config.showMute) } @Test fun testUseZoomButton() { - val config = VisualNavigationViewConfig().useZoomButton(onZoomIn = {}, onZoomOut = {}) + val config = VisualNavigationViewConfig().useZoomButton() assert(config.showZoom) } @Test fun testUseMuteButtonAndZoomButton() { - val config = - VisualNavigationViewConfig() - .useMuteButton(onMute = {}) - .useZoomButton(onZoomIn = {}, onZoomOut = {}) + val config = VisualNavigationViewConfig().useMuteButton().useZoomButton() assert(config.showMute) assert(config.showZoom) }