Navigation3 - Part 1, 2, and 3 Dependencies

Navigation 3 

Part 1, 2, and 3 Dependencies

Add these dependencies before you start with the examples. Just add / adjust as required. You should not need to remove any existing entries from a new project.

Here is a good official reference.

build.gradle.kts (Project: ProjectName)

plugins {
...
// Added - Optional / Add-on Navigation3
alias(libs.plugins.kotlin.serialization) apply false

// Added for SaveStateHandler support
alias(libs.plugins.kotlin.parcelize) apply false
}

build.gradle.kts (Module: app) 

Note: I've updated to SDK 37 for this as we are using experimental features.
plugins {
...
// Added for Navigation3
alias(libs.plugins.kotlin.serialization)

// Added for SaveStateHandler support
alias(libs.plugins.kotlin.parcelize)
}

android {
...
compileSdk {
version = release(37)
}
...
defaultConfig {

targetSdk = 37

}
}

dependencies {
...
    // Added - ViewModel
implementation(libs.androidx.lifecycle.viewmodel.compose)

// Added - Core Navigation3
implementation(libs.androidx.navigation3.ui)
implementation(libs.androidx.navigation3.runtime)

// Added - Optional / Add-on Navigation3
implementation(libs.androidx.lifecycle.viewmodel.navigation3)
implementation(libs.androidx.material3.adaptive.navigation3)
implementation(libs.kotlinx.serialization.core)
}

libs.versions.toml

It was far easier to post the full code - GitHub Gist Full List.

NavigationScreen - Shared

@Serializable
sealed interface NavigationScreen : NavKey {

@Serializable
data object Home : NavigationScreen

@Serializable
data object List : NavigationScreen

@Serializable
data class Detail(val id: Int) : NavigationScreen
}

NavColors - Shared

object NavColors {
val homeColor = Color.Red.copy(alpha = .05f)
val listColor = Color.Blue.copy(alpha = .05f)
val detailColor = Color.Green.copy(alpha = .05f)
}

TransitionAnimations - Shared

object TransitionAnimations {
private val screenInLeftOldOutRight = slideInHorizontally(
animationSpec = tween(150)
) { width -> -width } togetherWith slideOutHorizontally(
animationSpec = tween(150)
) { width -> width }

private val screenInRightOldOutLeft = slideInHorizontally(
animationSpec = tween(150)
) { fullWidth -> fullWidth } togetherWith slideOutHorizontally(
animationSpec = tween(150)
) { fullWidth -> -fullWidth }

val forwardTransition:
AnimatedContentTransitionScope<Scene<NavKey>>.() ->
ContentTransform = { screenInRightOldOutLeft }

val popTransition:
AnimatedContentTransitionScope<Scene<NavKey>>.() ->
ContentTransform = { screenInLeftOldOutRight }

val predictivePopTransitionSpec:
AnimatedContentTransitionScope<Scene<NavKey>>.(Int) ->
ContentTransform = { _ -> screenInLeftOldOutRight }
}

Part 3 - CarList


Cute Dependency Picture

Comments

Popular Posts