Skip to content

Commit

Permalink
Merge pull request #201 from stadiamaps/fix/android/navigation-dispos…
Browse files Browse the repository at this point in the history
…able

Removed automatic full screen and added keep screen on method
  • Loading branch information
ianthetechie authored Aug 28, 2024
2 parents 4c4915e + 6fe0664 commit e0ece74
Show file tree
Hide file tree
Showing 16 changed files with 53 additions and 102 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ if useLocalFramework {
path: "./common/target/ios/libferrostar-rs.xcframework"
)
} else {
let releaseTag = "0.9.0"
let releaseTag = "0.9.1"
let releaseChecksum = "e42ab56e8038d3020c2eb52e3234d03235cc5374481255475b70c24497541efc"
binaryTarget = .binaryTarget(
name: "FerrostarCoreRS",
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ plugins {

allprojects {
group = "com.stadiamaps.ferrostar"
version = "0.9.0"
version = "0.9.1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,14 @@ import android.view.WindowManager
import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.ui.platform.LocalContext
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsControllerCompat

/** Get the Window for the current scene (Activity). */
@Composable
fun window(): Window? {
private fun window(): Window? {
val context = LocalContext.current
return (context as? Activity)?.window ?: return null
}

/** Get the WindowInsetsController for the provided window. */
@Composable
fun windowInsetsController(window: Window): WindowInsetsControllerCompat {
return WindowCompat.getInsetsController(window, window.decorView)
}

/**
* A Composable that keeps the screen on while the hosting Composable is in the view hierarchy. On
* dispose, the flag is cleared and the screen will return to its normal behavior.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ object DefaultArrivalViewTheme : ArrivalViewTheme {
override val measurementTextStyle: TextStyle
@Composable
get() =
MaterialTheme.typography.titleLarge.copy(
MaterialTheme.typography.titleMedium.copy(
color = MaterialTheme.colorScheme.onSurface, fontWeight = FontWeight.SemiBold)

override val secondaryTextStyle: TextStyle
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ fun DemoNavigationScene(
locationProvider: SimulatedLocationProvider = AppModule.locationProvider,
core: FerrostarCore = AppModule.ferrostarCore
) {
// Keeps the screen on at a consistent brightness while this Composable is in the view hierarchy.
// This is typically a good idea for scenes hosting navigation trips or a NavigationView.
// Keeps the screen on at consistent brightness while this Composable is in the view hierarchy.
KeepScreenOnDisposableEffect()

var viewModel by remember { mutableStateOf<NavigationViewModel?>(null) }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fun navigationMapViewCamera(
val screenOrientation = LocalConfiguration.current.orientation
val start = if (screenOrientation == Configuration.ORIENTATION_LANDSCAPE) 0.5f else 0.0f

val cameraPadding = cameraPaddingFractionOfScreen(start = start, top = 0.7f)
val cameraPadding = cameraPaddingFractionOfScreen(start = start, top = 0.6f)

return MapViewCamera.TrackingUserLocationWithBearing(
zoom = activity.zoom, pitch = activity.pitch, padding = cameraPadding)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package com.stadiamaps.ferrostar.maplibreui.views
import android.content.res.Configuration
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.navigationBarsPadding
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.statusBarsPadding
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.State
Expand All @@ -22,7 +20,6 @@ import com.stadiamaps.ferrostar.maplibreui.NavigationMapView
import com.stadiamaps.ferrostar.maplibreui.config.VisualNavigationViewConfig
import com.stadiamaps.ferrostar.maplibreui.config.mapControlsFor
import com.stadiamaps.ferrostar.maplibreui.extensions.NavigationDefault
import com.stadiamaps.ferrostar.maplibreui.runtime.AutoHideSystemUIDisposableEffect
import com.stadiamaps.ferrostar.maplibreui.runtime.navigationMapViewCamera
import com.stadiamaps.ferrostar.maplibreui.views.overlays.LandscapeNavigationOverlayView
import com.stadiamaps.ferrostar.maplibreui.views.overlays.PortraitNavigationOverlayView
Expand All @@ -40,6 +37,9 @@ import com.stadiamaps.ferrostar.maplibreui.views.overlays.PortraitNavigationOver
* @param locationRequestProperties The location request properties to use for the map's location
* engine.
* @param config The configuration for the navigation view.
* @param landscapeOverlayModifier The modifier to apply to the overlay view.
* @param portraitOverlayModifier The modifier to apply to the overlay view.
* @param onTapExit The callback to invoke when the exit button is tapped.
* @param content Any additional composable map symbol content to render.
*/
@Composable
Expand All @@ -52,11 +52,11 @@ fun DynamicallyOrientingNavigationView(
locationRequestProperties: LocationRequestProperties =
LocationRequestProperties.NavigationDefault(),
config: VisualNavigationViewConfig = VisualNavigationViewConfig.Default(),
landscapeOverlayModifier: Modifier = Modifier.fillMaxSize().padding(16.dp),
portraitOverlayModifier: Modifier = Modifier.fillMaxSize().padding(16.dp),
onTapExit: (() -> Unit)? = null,
content: @Composable @MapLibreComposable() ((State<NavigationUiState>) -> Unit)? = null,
) {
AutoHideSystemUIDisposableEffect()

val orientation = LocalConfiguration.current.orientation
val isLandscape = orientation == Configuration.ORIENTATION_LANDSCAPE

Expand All @@ -74,22 +74,15 @@ fun DynamicallyOrientingNavigationView(
when (orientation) {
Configuration.ORIENTATION_LANDSCAPE -> {
LandscapeNavigationOverlayView(
modifier =
Modifier.fillMaxSize()
.padding(top = 32.dp, start = 16.dp, end = 16.dp, bottom = 16.dp),
modifier = landscapeOverlayModifier,
camera = camera,
viewModel = viewModel,
config = config,
onTapExit = onTapExit)
}
else -> {
PortraitNavigationOverlayView(
modifier =
Modifier.fillMaxSize()
.statusBarsPadding()
.navigationBarsPadding()
.padding(horizontal = 16.dp)
.padding(bottom = 24.dp),
modifier = portraitOverlayModifier,
camera = camera,
viewModel = viewModel,
config = config,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import com.stadiamaps.ferrostar.maplibreui.NavigationMapView
import com.stadiamaps.ferrostar.maplibreui.config.VisualNavigationViewConfig
import com.stadiamaps.ferrostar.maplibreui.config.mapControlsFor
import com.stadiamaps.ferrostar.maplibreui.extensions.NavigationDefault
import com.stadiamaps.ferrostar.maplibreui.runtime.AutoHideSystemUIDisposableEffect
import com.stadiamaps.ferrostar.maplibreui.runtime.navigationMapViewCamera
import com.stadiamaps.ferrostar.maplibreui.views.overlays.LandscapeNavigationOverlayView
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -31,10 +30,18 @@ import kotlinx.coroutines.flow.asStateFlow
* A portrait orientation of the navigation view with instructions, default controls and the
* navigation map view.
*
* @param modifier
* @param styleUrl
* @param viewModel
* @param locationRequestProperties
* @param modifier The modifier to apply to the view.
* @param styleUrl The MapLibre style URL to use for the map.
* @param camera The bi-directional camera state to use for the map.
* @param navigationCamera The default camera state to use for navigation. This is applied on launch
* and when centering.
* @param viewModel The navigation view model provided by Ferrostar Core.
* @param locationRequestProperties The location request properties to use for the map's location
* engine.
* @param config The configuration for the navigation view.
* @param overlayModifier The modifier to apply to the overlay view.
* @param onTapExit The callback to invoke when the exit button is tapped.
* @param content Any additional composable map symbol content to render.
*/
@Composable
fun LandscapeNavigationView(
Expand All @@ -46,11 +53,10 @@ fun LandscapeNavigationView(
locationRequestProperties: LocationRequestProperties =
LocationRequestProperties.NavigationDefault(),
config: VisualNavigationViewConfig = VisualNavigationViewConfig.Default(),
overlayModifier: Modifier = Modifier.fillMaxSize().padding(16.dp),
onTapExit: (() -> Unit)? = null,
content: @Composable @MapLibreComposable() ((State<NavigationUiState>) -> Unit)? = null
) {
AutoHideSystemUIDisposableEffect()

Box(modifier) {
NavigationMapView(
styleUrl,
Expand All @@ -63,7 +69,7 @@ fun LandscapeNavigationView(
content)

LandscapeNavigationOverlayView(
modifier = Modifier.fillMaxSize().padding(16.dp),
modifier = overlayModifier,
config = config,
camera = camera,
viewModel = viewModel,
Expand All @@ -81,5 +87,7 @@ private fun LandscapeNavigationViewPreview() {
MutableStateFlow<NavigationUiState>(NavigationUiState.pedestrianExample()).asStateFlow())

LandscapeNavigationView(
Modifier.fillMaxSize(), "https://demotiles.maplibre.org/style.json", viewModel = viewModel)
Modifier.fillMaxSize(),
styleUrl = "https://demotiles.maplibre.org/style.json",
viewModel = viewModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import com.stadiamaps.ferrostar.maplibreui.NavigationMapView
import com.stadiamaps.ferrostar.maplibreui.config.VisualNavigationViewConfig
import com.stadiamaps.ferrostar.maplibreui.config.mapControlsFor
import com.stadiamaps.ferrostar.maplibreui.extensions.NavigationDefault
import com.stadiamaps.ferrostar.maplibreui.runtime.AutoHideSystemUIDisposableEffect
import com.stadiamaps.ferrostar.maplibreui.runtime.navigationMapViewCamera
import com.stadiamaps.ferrostar.maplibreui.views.overlays.PortraitNavigationOverlayView
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -32,10 +31,18 @@ import kotlinx.coroutines.flow.asStateFlow
* A portrait orientation of the navigation view with instructions, default controls and the
* navigation map view.
*
* @param modifier
* @param styleUrl
* @param viewModel
* @param locationRequestProperties
* @param modifier The modifier to apply to the view.
* @param styleUrl The MapLibre style URL to use for the map.
* @param camera The bi-directional camera state to use for the map.
* @param navigationCamera The default camera state to use for navigation. This is applied on launch
* and when centering.
* @param viewModel The navigation view model provided by Ferrostar Core.
* @param locationRequestProperties The location request properties to use for the map's location
* engine.
* @param config The configuration for the navigation view.
* @param overlayModifier The modifier to apply to the overlay view.
* @param onTapExit The callback to invoke when the exit button is tapped.
* @param content Any additional composable map symbol content to render.
*/
@Composable
fun PortraitNavigationView(
Expand All @@ -47,11 +54,10 @@ fun PortraitNavigationView(
locationRequestProperties: LocationRequestProperties =
LocationRequestProperties.NavigationDefault(),
config: VisualNavigationViewConfig = VisualNavigationViewConfig.Default(),
overlayModifier: Modifier = Modifier.fillMaxSize().padding(16.dp),
onTapExit: (() -> Unit)? = null,
content: @Composable @MapLibreComposable() ((State<NavigationUiState>) -> Unit)? = null
) {
AutoHideSystemUIDisposableEffect()

Box(modifier) {
NavigationMapView(
styleUrl,
Expand All @@ -64,8 +70,7 @@ fun PortraitNavigationView(
content)

PortraitNavigationOverlayView(
modifier =
Modifier.fillMaxSize().padding(start = 16.dp, end = 16.dp, top = 16.dp, bottom = 16.dp),
modifier = overlayModifier,
config = config,
camera = camera,
viewModel = viewModel,
Expand All @@ -81,5 +86,7 @@ private fun PortraitNavigationViewPreview() {
MutableStateFlow<NavigationUiState>(NavigationUiState.pedestrianExample()).asStateFlow())

PortraitNavigationView(
Modifier.fillMaxSize(), "https://demotiles.maplibre.org/style.json", viewModel = viewModel)
Modifier.fillMaxSize(),
styleUrl = "https://demotiles.maplibre.org/style.json",
viewModel = viewModel)
}
2 changes: 1 addition & 1 deletion common/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common/ferrostar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ lints.workspace = true

[package]
name = "ferrostar"
version = "0.9.0"
version = "0.9.1"
readme = "README.md"
description = "The core of modern turn-by-turn navigation."
keywords = ["navigation", "routing", "valhalla", "osrm"]
Expand Down
4 changes: 4 additions & 0 deletions guide/src/android-getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ Here’s an example:
}
```

### Tools for Improving a NavigationView

- `KeepScreenOnDisposableEffect` is a simple disposable effect that automatically keeps the screen on and at consistent brightness while a user is on the scene using the effect. On dispose, the screen will return to default and auto lock and dim. See the demo app for an example of this being used alongside the `DynamicallyOrientingNavigationView`.

## Demo app

We've put together a minimal [demo app](https://github.com/stadiamaps/ferrostar/tree/main/android/demo-app) with an example integration.
Expand Down

0 comments on commit e0ece74

Please sign in to comment.