From 38fded8aaf385ea36062faa803dc668450ec0747 Mon Sep 17 00:00:00 2001 From: Rafael Costa Date: Sat, 20 Jul 2024 12:48:19 +0100 Subject: [PATCH 1/3] Some issue fixes cherry picked from v2 --- .../composedestinations/DefaultNavHostEngine.kt | 5 ++++- .../parcelable/DefaultParcelableNavTypeSerializer.kt | 8 +++++++- .../composedestinations/spec/DestinationSpec.kt | 10 +++++----- .../ramcosta/composedestinations/spec/NavGraphSpec.kt | 2 ++ .../com/ramcosta/composedestinations/spec/Route.kt | 9 +++++++++ .../composedestinations/ksp/ProcessorProviderTests.kt | 3 +++ 6 files changed, 30 insertions(+), 7 deletions(-) diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/DefaultNavHostEngine.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/DefaultNavHostEngine.kt index 0de16507..9ca2999d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/DefaultNavHostEngine.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/DefaultNavHostEngine.kt @@ -80,7 +80,10 @@ internal class DefaultNavHostEngine( ) = with(defaultAnimationParams) { androidx.navigation.compose.NavHost( navController = navController, - startDestination = startRoute.route, + // since start destinations of NavHosts can't have + // mandatory arguments, we can use baseRoute here safely + // prevents official lib to consider weird arg values like "{argName}" + startDestination = startRoute.baseRoute, modifier = modifier, route = route, contentAlignment = navHostContentAlignment, diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt index 9473a1db..0e04a326 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/navargs/parcelable/DefaultParcelableNavTypeSerializer.kt @@ -25,7 +25,13 @@ class DefaultParcelableNavTypeSerializer( } override fun fromRouteString(routeStr: String): Parcelable { - val (className, base64) = routeStr.split("@").let { it[0] to it[1] } + val splits = routeStr.split("@") + // must throw IllegalArgumentException here, such as with require function + require(splits.size == 2) { + "Impossible to get Parcelable from $routeStr" + } + + val (className, base64) = splits.let { it[0] to it[1] } val creator = if (jClass.isFinal) { // Since we have this, small optimization to avoid additional reflection call of Class.forName diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationSpec.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationSpec.kt index 50abeba8..7ad606bb 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationSpec.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/DestinationSpec.kt @@ -1,10 +1,12 @@ package com.ramcosta.composedestinations.spec import android.os.Bundle -import androidx.annotation.RestrictTo import androidx.compose.runtime.Composable import androidx.lifecycle.SavedStateHandle -import androidx.navigation.* +import androidx.navigation.NamedNavArgument +import androidx.navigation.NavBackStackEntry +import androidx.navigation.NavController +import androidx.navigation.NavDeepLink import com.ramcosta.composedestinations.scope.DestinationScope /** @@ -54,10 +56,8 @@ interface DestinationSpec : Route { /** * Prefix of the route - basically [route] without argument info. - * Meant for internal usage only. */ - @get:RestrictTo(RestrictTo.Scope.SUBCLASSES) - val baseRoute: String + override val baseRoute: String /** * All [NamedNavArgument]s that will be added to the navigation diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavGraphSpec.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavGraphSpec.kt index ade3c268..535f2211 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavGraphSpec.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/NavGraphSpec.kt @@ -26,4 +26,6 @@ interface NavGraphSpec : Direction, Route { * Nested navigation graphs of this navigation graph. */ val nestedNavGraphs: List get() = emptyList() + + override val baseRoute: String get() = route } diff --git a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Route.kt b/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Route.kt index 622cf50b..82e6254d 100644 --- a/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Route.kt +++ b/compose-destinations/src/main/java/com/ramcosta/composedestinations/spec/Route.kt @@ -12,5 +12,14 @@ package com.ramcosta.composedestinations.spec */ sealed interface Route { + /** + * Full route pattern that will be added to the navigation graph. + * Navigation arguments are not filled in. + */ val route: String + + /** + * Prefix of the route - basically [route] without argument info. + */ + val baseRoute: String } diff --git a/playground/src/test/kotlin/com/ramcosta/composedestinations/ksp/ProcessorProviderTests.kt b/playground/src/test/kotlin/com/ramcosta/composedestinations/ksp/ProcessorProviderTests.kt index 79d22587..ce14b2dc 100644 --- a/playground/src/test/kotlin/com/ramcosta/composedestinations/ksp/ProcessorProviderTests.kt +++ b/playground/src/test/kotlin/com/ramcosta/composedestinations/ksp/ProcessorProviderTests.kt @@ -1,3 +1,5 @@ +@file:OptIn(ExperimentalCompilerApi::class) + package com.ramcosta.composedestinations.ksp import com.tschuchort.compiletesting.KotlinCompilation @@ -6,6 +8,7 @@ import com.tschuchort.compiletesting.SourceFile.Companion.kotlin import com.tschuchort.compiletesting.kspIncremental import com.tschuchort.compiletesting.kspSourcesDir import com.tschuchort.compiletesting.symbolProcessorProviders +import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi import org.junit.Assert.assertEquals import org.junit.Assert.assertTrue import org.junit.Rule From d03907cf3532147984ac3ace5fa83068d4dae959 Mon Sep 17 00:00:00 2001 From: extmkv Date: Fri, 6 Sep 2024 08:51:50 +0100 Subject: [PATCH 2/3] Updates libraries to the latest milestone (cherry picked from commit ffcd7ffb7681369389539c2017692f3044f7981b) --- gradle/libs.versions.toml | 18 +++++++++--------- gradle/wrapper/gradle-wrapper.properties | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index f037983e..820167be 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -4,25 +4,25 @@ minSdk = "21" compileSdk = "34" targetSdk = "34" -kotlin = "2.0.0" +kotlin = "2.0.20" dependencyCheckPluginVersion = "0.51.0" -agp = "8.4.2" +agp = "8.5.2" mavenPublishPluginVersion = "0.28.0" -composeViewModel = "2.8.3" -activityCompose = "1.9.0" +composeViewModel = "2.8.5" +activityCompose = "1.9.2" material = "1.12.0" -lifecycleRuntimeKtx = "2.8.3" +lifecycleRuntimeKtx = "2.8.5" -ksp = "2.0.0-1.0.22" +ksp = "2.0.20-1.0.25" junit = "4.13.2" -compose = "1.7.0-beta05" -composeMaterial = "1.7.0-beta05" +compose = "1.7.0" +composeMaterial = "1.7.0" composeNavigationMaterial = "1.7.0-beta01" -composeNavigation = "2.8.0-beta05" +composeNavigation = "2.8.0" ktxSerialization = "1.7.1" mockk = "1.13.11" diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 1e88da37..b56f434a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Mon Aug 23 16:48:14 WEST 2021 distributionBase=GRADLE_USER_HOME -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip distributionPath=wrapper/dists zipStorePath=wrapper/dists zipStoreBase=GRADLE_USER_HOME From 52399eb88e7319f1d5db853dc72a93c9c29ff4a7 Mon Sep 17 00:00:00 2001 From: Rafael Costa Date: Sun, 8 Sep 2024 15:30:04 +0100 Subject: [PATCH 3/3] Fixed issue with sample bottom bar --- .../destinations/sample/ui/composables/BottomBar.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/sample/src/main/java/com/ramcosta/destinations/sample/ui/composables/BottomBar.kt b/sample/src/main/java/com/ramcosta/destinations/sample/ui/composables/BottomBar.kt index 95663239..4076a1dd 100644 --- a/sample/src/main/java/com/ramcosta/destinations/sample/ui/composables/BottomBar.kt +++ b/sample/src/main/java/com/ramcosta/destinations/sample/ui/composables/BottomBar.kt @@ -6,14 +6,15 @@ import androidx.compose.material.BottomNavigationItem import androidx.compose.material.Icon import androidx.compose.material.Text import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.List +import androidx.compose.material.icons.automirrored.filled.List import androidx.compose.material.icons.filled.Person import androidx.compose.material.icons.filled.Settings import androidx.compose.runtime.Composable +import androidx.compose.runtime.getValue import androidx.compose.ui.graphics.vector.ImageVector import androidx.compose.ui.res.stringResource import androidx.navigation.NavHostController -import com.ramcosta.composedestinations.utils.isRouteOnBackStack +import com.ramcosta.composedestinations.utils.isRouteOnBackStackAsState import com.ramcosta.composedestinations.utils.rememberDestinationsNavigator import com.ramcosta.destinations.sample.NavGraphs import com.ramcosta.destinations.sample.R @@ -29,7 +30,7 @@ fun BottomBar( val navigator = navController.rememberDestinationsNavigator() BottomNavigation { BottomBarItem.values().forEach { destination -> - val isCurrentDestOnBackStack = navController.isRouteOnBackStack(destination.direction) + val isCurrentDestOnBackStack by navController.isRouteOnBackStackAsState(destination.direction) BottomNavigationItem( selected = isCurrentDestOnBackStack, onClick = { @@ -72,7 +73,7 @@ enum class BottomBarItem( val icon: ImageVector, @StringRes val label: Int ) { - TaskList(TaskListScreenDestination, Icons.Default.List, R.string.task_list_screen), + TaskList(TaskListScreenDestination, Icons.AutoMirrored.Filled.List, R.string.task_list_screen), Account(AccountScreenDestination, Icons.Default.Person, R.string.account_screen), Settings(SettingsScreenDestination, Icons.Default.Settings, R.string.settings_screen) } \ No newline at end of file