Skip to content

Commit

Permalink
feat: Add NavigationViewDelegate
Browse files Browse the repository at this point in the history
Adds NavigationViewDelegate to support NavigationView in the navigation sample app.

This change allows the navigation sample app to use NavigationView, which provides turn-by-turn navigation functionality.

The NavigationViewDelegate handles the lifecycle and rendering of the NavigationView, ensuring that it is properly integrated into the Jetpack Compose UI.

Uses a MarkerComposable to demonstrate the map really is a composable
  • Loading branch information
dkhawk committed Jan 9, 2025
1 parent bcdf6b0 commit 934fee6
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 100 deletions.
4 changes: 3 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
android.useAndroidX=true
# Automatically convert third-party libraries to use AndroidX
# (not needed, since no requested libraries are pre-AndroidX)
android.enableJetifier=false
#android.enableJetifier=false
# This is needed for the navigation SDK library. It needs the recycler view.
android.enableJetifier=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official

Expand Down
2 changes: 0 additions & 2 deletions navigation-app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ dependencies {

implementation(libs.play.services.location)

// testImplementation(libs.robolectric)
testImplementation(libs.androidx.core)
testImplementation(libs.truth)

Expand All @@ -94,7 +93,6 @@ dependencies {

// Accompanist permission helper
implementation(libs.accompanist.permissions)

}

secrets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ import androidx.lifecycle.compose.collectAsStateWithLifecycle
import com.google.accompanist.permissions.ExperimentalPermissionsApi
import com.google.accompanist.permissions.rememberMultiplePermissionsState
import com.google.android.gms.maps.model.LatLng
import com.google.android.libraries.navigation.NavigationApi
import com.google.maps.android.compose.navigation.ui.theme.AndroidmapscomposeTheme
import kotlinx.coroutines.launch

val defaultLocation = LatLng(39.9828503662161, -105.71835147137016)

@OptIn(ExperimentalPermissionsApi::class)
class MainActivity : ComponentActivity() {
private val myViewModel: MainViewModel by viewModels { MainViewModel.Factory }
private val myViewModel: NavigationViewModel by viewModels { NavigationViewModel.Factory }

override fun onResume() {
super.onResume()
Expand All @@ -40,6 +41,9 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()

NavigationApi.getNavigator(this, myViewModel)

setContent {
val context = LocalContext.current
val snackbarHostState by remember { mutableStateOf(SnackbarHostState()) }
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
package com.google.maps.android.compose.navigation

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp
import com.google.android.gms.maps.CameraUpdateFactory
import com.google.android.gms.maps.model.CameraPosition
import com.google.android.gms.maps.model.LatLng
import com.google.android.libraries.navigation.NavigationView
import com.google.maps.android.compose.ComposeMapColorScheme
import com.google.maps.android.compose.GoogleMap
import com.google.maps.android.compose.MarkerComposable
import com.google.maps.android.compose.navigation.components.MovableMarker
import com.google.maps.android.compose.rememberCameraPositionState
import com.google.maps.android.compose.rememberMarkerState

@Composable
fun NavigationScreen(
Expand Down Expand Up @@ -54,6 +67,25 @@ fun NavigationScreen(
title = "User location",
)
}

MarkerComposable(
title = "Bigfoot",
state = rememberMarkerState(position = LatLng(39.99932703674056, -105.28152457787887)),
) {
Box(
modifier = Modifier
.width(48.dp)
.height(48.dp)
.clip(RoundedCornerShape(16.dp))
.background(Color.Transparent),
contentAlignment = Alignment.Center,
) {
Image(
painter = painterResource(R.drawable.bigfoot),
contentDescription = ""
)
}
}
}
}
}
}
Loading

0 comments on commit 934fee6

Please sign in to comment.