Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Android zoom button behavior #371

Merged
merged 4 commits into from
Nov 26, 2024
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 @@ -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 = camera.value.incrementZoom(1.0) },
onClickZoomOut = { camera.value = 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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Loading