├── .gitignore ├── .idea ├── .gitignore ├── compiler.xml ├── gradle.xml └── misc.xml ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── plcoding │ │ └── composenavdestinationsdemo │ │ └── ExampleInstrumentedTest.kt │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── plcoding │ │ │ └── composenavdestinationsdemo │ │ │ ├── MainActivity.kt │ │ │ ├── User.kt │ │ │ └── ui │ │ │ └── theme │ │ │ ├── Color.kt │ │ │ ├── Shape.kt │ │ │ ├── Theme.kt │ │ │ └── Type.kt │ └── res │ │ ├── drawable-v24 │ │ └── ic_launcher_foreground.xml │ │ ├── drawable │ │ └── ic_launcher_background.xml │ │ ├── mipmap-anydpi-v26 │ │ ├── ic_launcher.xml │ │ └── ic_launcher_round.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.webp │ │ └── ic_launcher_round.webp │ │ ├── values-night │ │ └── themes.xml │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── themes.xml │ └── test │ └── java │ └── com │ └── plcoding │ └── composenavdestinationsdemo │ └── ExampleUnitTest.kt ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/caches 5 | /.idea/libraries 6 | /.idea/modules.xml 7 | /.idea/workspace.xml 8 | /.idea/navEditor.xml 9 | /.idea/assetWizardSettings.xml 10 | .DS_Store 11 | /build 12 | /captures 13 | .externalNativeBuild 14 | .cxx 15 | local.properties 16 | -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 18 | 19 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 9 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | plugins { 2 | id 'com.android.application' 3 | id 'kotlin-android' 4 | id 'kotlin-parcelize' 5 | } 6 | 7 | android { 8 | compileSdk 32 9 | 10 | defaultConfig { 11 | applicationId "com.plcoding.composenavdestinationsdemo" 12 | minSdk 26 13 | targetSdk 32 14 | versionCode 1 15 | versionName "1.0" 16 | 17 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" 18 | vectorDrawables { 19 | useSupportLibrary true 20 | } 21 | } 22 | 23 | buildTypes { 24 | release { 25 | minifyEnabled false 26 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' 27 | } 28 | } 29 | compileOptions { 30 | sourceCompatibility JavaVersion.VERSION_1_8 31 | targetCompatibility JavaVersion.VERSION_1_8 32 | } 33 | kotlinOptions { 34 | jvmTarget = '1.8' 35 | useIR = true 36 | } 37 | buildFeatures { 38 | compose true 39 | } 40 | composeOptions { 41 | kotlinCompilerExtensionVersion '1.1.0-rc02' 42 | kotlinCompilerVersion compose_version 43 | } 44 | packagingOptions { 45 | resources { 46 | excludes += '/META-INF/{AL2.0,LGPL2.1}' 47 | } 48 | } 49 | } 50 | 51 | dependencies { 52 | implementation 'androidx.core:core-ktx:1.7.0' 53 | implementation 'androidx.appcompat:appcompat:1.4.0' 54 | implementation 'com.google.android.material:material:1.4.0' 55 | implementation "androidx.compose.ui:ui:$compose_version" 56 | implementation "androidx.compose.material:material:$compose_version" 57 | implementation "androidx.compose.ui:ui-tooling-preview:$compose_version" 58 | implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.4.0' 59 | implementation 'androidx.activity:activity-compose:1.4.0' 60 | testImplementation 'junit:junit:4.+' 61 | androidTestImplementation 'androidx.test.ext:junit:1.1.3' 62 | androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' 63 | androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version" 64 | debugImplementation "androidx.compose.ui:ui-tooling:$compose_version" 65 | 66 | implementation "androidx.navigation:navigation-compose:2.4.0-rc01" 67 | 68 | } -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile -------------------------------------------------------------------------------- /app/src/androidTest/java/com/plcoding/composenavdestinationsdemo/ExampleInstrumentedTest.kt: -------------------------------------------------------------------------------- 1 | package com.plcoding.composenavdestinationsdemo 2 | 3 | import androidx.test.platform.app.InstrumentationRegistry 4 | import androidx.test.ext.junit.runners.AndroidJUnit4 5 | 6 | import org.junit.Test 7 | import org.junit.runner.RunWith 8 | 9 | import org.junit.Assert.* 10 | 11 | /** 12 | * Instrumented test, which will execute on an Android device. 13 | * 14 | * See [testing documentation](http://d.android.com/tools/testing). 15 | */ 16 | @RunWith(AndroidJUnit4::class) 17 | class ExampleInstrumentedTest { 18 | @Test 19 | fun useAppContext() { 20 | // Context of the app under test. 21 | val appContext = InstrumentationRegistry.getInstrumentation().targetContext 22 | assertEquals("com.plcoding.composenavdestinationsdemo", appContext.packageName) 23 | } 24 | } -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 12 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /app/src/main/java/com/plcoding/composenavdestinationsdemo/MainActivity.kt: -------------------------------------------------------------------------------- 1 | package com.plcoding.composenavdestinationsdemo 2 | 3 | import android.os.Bundle 4 | import androidx.activity.ComponentActivity 5 | import androidx.activity.compose.setContent 6 | import androidx.compose.foundation.layout.Arrangement 7 | import androidx.compose.foundation.layout.Box 8 | import androidx.compose.foundation.layout.Column 9 | import androidx.compose.foundation.layout.fillMaxSize 10 | import androidx.compose.material.Button 11 | import androidx.compose.material.MaterialTheme 12 | import androidx.compose.material.Surface 13 | import androidx.compose.material.Text 14 | import androidx.compose.runtime.Composable 15 | import androidx.compose.runtime.remember 16 | import androidx.compose.ui.Alignment 17 | import androidx.compose.ui.Modifier 18 | import androidx.compose.ui.text.style.TextAlign 19 | import androidx.compose.ui.tooling.preview.Preview 20 | import androidx.navigation.NavController 21 | import androidx.navigation.NavType 22 | import androidx.navigation.compose.NavHost 23 | import androidx.navigation.compose.composable 24 | import androidx.navigation.compose.rememberNavController 25 | import androidx.navigation.navArgument 26 | import com.plcoding.composenavdestinationsdemo.ui.theme.ComposeNavDestinationsDemoTheme 27 | import java.time.Instant 28 | import java.time.LocalDateTime 29 | import java.time.ZoneId 30 | 31 | class MainActivity : ComponentActivity() { 32 | override fun onCreate(savedInstanceState: Bundle?) { 33 | super.onCreate(savedInstanceState) 34 | setContent { 35 | ComposeNavDestinationsDemoTheme { 36 | val navController = rememberNavController() 37 | NavHost( 38 | navController = navController, 39 | startDestination = "login" 40 | ) { 41 | composable("login") { 42 | LoginScreen(navController) 43 | } 44 | composable( 45 | route = "profile/{name}/{userId}/{timestamp}", 46 | arguments = listOf( 47 | navArgument("name") { 48 | type = NavType.StringType 49 | }, 50 | navArgument("userId") { 51 | type = NavType.StringType 52 | }, 53 | navArgument("timestamp") { 54 | type = NavType.LongType 55 | }, 56 | ) 57 | ) { 58 | val name = it.arguments?.getString("name")!! 59 | val userId = it.arguments?.getString("userId")!! 60 | val timestamp = it.arguments?.getLong("timestamp")!! 61 | 62 | ProfileScreen( 63 | navController = navController, 64 | name = name, 65 | userId = userId, 66 | created = timestamp 67 | ) 68 | } 69 | composable("post/{showOnlyPostsByUser}", arguments = listOf( 70 | navArgument("showOnlyPostsByUser") { 71 | type = NavType.BoolType 72 | defaultValue = false 73 | } 74 | )) { 75 | val showOnlyPostsByUser = 76 | it.arguments?.getBoolean("showOnlyPostsByUser") ?: false 77 | PostScreen(showOnlyPostsByUser) 78 | } 79 | } 80 | } 81 | } 82 | } 83 | } 84 | 85 | @Composable 86 | fun LoginScreen( 87 | navController: NavController 88 | ) { 89 | Column( 90 | modifier = Modifier.fillMaxSize(), 91 | verticalArrangement = Arrangement.Center, 92 | horizontalAlignment = Alignment.CenterHorizontally 93 | ) { 94 | Text("Login Screen") 95 | Button(onClick = { 96 | navController.navigate("profile/philipp/userid/123456789") 97 | }) { 98 | Text("Go to Profile Screen") 99 | } 100 | } 101 | } 102 | 103 | @Composable 104 | fun ProfileScreen( 105 | navController: NavController, 106 | name: String, 107 | userId: String, 108 | created: Long 109 | ) { 110 | val user = remember { 111 | User( 112 | name = name, 113 | id = userId, 114 | created = LocalDateTime.ofInstant( 115 | Instant.ofEpochMilli(created), ZoneId.systemDefault() 116 | ) 117 | ) 118 | } 119 | Column( 120 | modifier = Modifier.fillMaxSize(), 121 | verticalArrangement = Arrangement.Center, 122 | horizontalAlignment = Alignment.CenterHorizontally 123 | ) { 124 | Text("Profile Screen: $user", textAlign = TextAlign.Center) 125 | Button(onClick = { 126 | navController.navigate("post/true") 127 | }) { 128 | Text("Go to Post Screen") 129 | } 130 | } 131 | } 132 | 133 | @Composable 134 | fun PostScreen( 135 | showOnlyPostsByUser: Boolean = false 136 | ) { 137 | Box( 138 | modifier = Modifier.fillMaxSize(), 139 | contentAlignment = Alignment.Center 140 | ) { 141 | Text(text = "Post Screen, $showOnlyPostsByUser") 142 | } 143 | } -------------------------------------------------------------------------------- /app/src/main/java/com/plcoding/composenavdestinationsdemo/User.kt: -------------------------------------------------------------------------------- 1 | package com.plcoding.composenavdestinationsdemo 2 | 3 | import android.os.Parcelable 4 | import kotlinx.parcelize.Parcelize 5 | import java.time.LocalDateTime 6 | 7 | @Parcelize 8 | data class User( 9 | val name: String, 10 | val id: String, 11 | val created: LocalDateTime 12 | ): Parcelable 13 | -------------------------------------------------------------------------------- /app/src/main/java/com/plcoding/composenavdestinationsdemo/ui/theme/Color.kt: -------------------------------------------------------------------------------- 1 | package com.plcoding.composenavdestinationsdemo.ui.theme 2 | 3 | import androidx.compose.ui.graphics.Color 4 | 5 | val Purple200 = Color(0xFFBB86FC) 6 | val Purple500 = Color(0xFF6200EE) 7 | val Purple700 = Color(0xFF3700B3) 8 | val Teal200 = Color(0xFF03DAC5) -------------------------------------------------------------------------------- /app/src/main/java/com/plcoding/composenavdestinationsdemo/ui/theme/Shape.kt: -------------------------------------------------------------------------------- 1 | package com.plcoding.composenavdestinationsdemo.ui.theme 2 | 3 | import androidx.compose.foundation.shape.RoundedCornerShape 4 | import androidx.compose.material.Shapes 5 | import androidx.compose.ui.unit.dp 6 | 7 | val Shapes = Shapes( 8 | small = RoundedCornerShape(4.dp), 9 | medium = RoundedCornerShape(4.dp), 10 | large = RoundedCornerShape(0.dp) 11 | ) -------------------------------------------------------------------------------- /app/src/main/java/com/plcoding/composenavdestinationsdemo/ui/theme/Theme.kt: -------------------------------------------------------------------------------- 1 | package com.plcoding.composenavdestinationsdemo.ui.theme 2 | 3 | import androidx.compose.foundation.isSystemInDarkTheme 4 | import androidx.compose.material.MaterialTheme 5 | import androidx.compose.material.darkColors 6 | import androidx.compose.material.lightColors 7 | import androidx.compose.runtime.Composable 8 | 9 | private val DarkColorPalette = darkColors( 10 | primary = Purple200, 11 | primaryVariant = Purple700, 12 | secondary = Teal200 13 | ) 14 | 15 | private val LightColorPalette = lightColors( 16 | primary = Purple500, 17 | primaryVariant = Purple700, 18 | secondary = Teal200 19 | 20 | /* Other default colors to override 21 | background = Color.White, 22 | surface = Color.White, 23 | onPrimary = Color.White, 24 | onSecondary = Color.Black, 25 | onBackground = Color.Black, 26 | onSurface = Color.Black, 27 | */ 28 | ) 29 | 30 | @Composable 31 | fun ComposeNavDestinationsDemoTheme( 32 | darkTheme: Boolean = isSystemInDarkTheme(), 33 | content: @Composable() () -> Unit 34 | ) { 35 | val colors = if (darkTheme) { 36 | DarkColorPalette 37 | } else { 38 | LightColorPalette 39 | } 40 | 41 | MaterialTheme( 42 | colors = colors, 43 | typography = Typography, 44 | shapes = Shapes, 45 | content = content 46 | ) 47 | } -------------------------------------------------------------------------------- /app/src/main/java/com/plcoding/composenavdestinationsdemo/ui/theme/Type.kt: -------------------------------------------------------------------------------- 1 | package com.plcoding.composenavdestinationsdemo.ui.theme 2 | 3 | import androidx.compose.material.Typography 4 | import androidx.compose.ui.text.TextStyle 5 | import androidx.compose.ui.text.font.FontFamily 6 | import androidx.compose.ui.text.font.FontWeight 7 | import androidx.compose.ui.unit.sp 8 | 9 | // Set of Material typography styles to start with 10 | val Typography = Typography( 11 | body1 = TextStyle( 12 | fontFamily = FontFamily.Default, 13 | fontWeight = FontWeight.Normal, 14 | fontSize = 16.sp 15 | ) 16 | /* Other default text styles to override 17 | button = TextStyle( 18 | fontFamily = FontFamily.Default, 19 | fontWeight = FontWeight.W500, 20 | fontSize = 14.sp 21 | ), 22 | caption = TextStyle( 23 | fontFamily = FontFamily.Default, 24 | fontWeight = FontWeight.Normal, 25 | fontSize = 12.sp 26 | ) 27 | */ 28 | ) -------------------------------------------------------------------------------- /app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 7 | 8 | 9 | 15 | 18 | 21 | 22 | 23 | 24 | 30 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 10 | 15 | 20 | 25 | 30 | 35 | 40 | 45 | 50 | 55 | 60 | 65 | 70 | 75 | 80 | 85 | 90 | 95 | 100 | 105 | 110 | 115 | 120 | 125 | 130 | 135 | 140 | 145 | 150 | 155 | 160 | 165 | 170 | 171 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-hdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-hdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-mdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-mdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-xhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp -------------------------------------------------------------------------------- /app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/philipplackner/ComposeNavDestinationsDemo/ced34ca4d263f22d10fbcaf5e53b47024d516921/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp -------------------------------------------------------------------------------- /app/src/main/res/values-night/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | -------------------------------------------------------------------------------- /app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFBB86FC 4 | #FF6200EE 5 | #FF3700B3 6 | #FF03DAC5 7 | #FF018786 8 | #FF000000 9 | #FFFFFFFF 10 | -------------------------------------------------------------------------------- /app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | ComposeNavDestinationsDemo 3 | -------------------------------------------------------------------------------- /app/src/main/res/values/themes.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 16 | 17 | 21 | 22 |