Skip to content

Commit

Permalink
Some issue fixes cherry picked from v2
Browse files Browse the repository at this point in the history
  • Loading branch information
raamcosta committed Jul 20, 2024
1 parent 7c8f45f commit 38fded8
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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

/**
Expand Down Expand Up @@ -54,10 +56,8 @@ interface DestinationSpec<T> : 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ interface NavGraphSpec : Direction, Route {
* Nested navigation graphs of this navigation graph.
*/
val nestedNavGraphs: List<NavGraphSpec> get() = emptyList()

override val baseRoute: String get() = route
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@file:OptIn(ExperimentalCompilerApi::class)

package com.ramcosta.composedestinations.ksp

import com.tschuchort.compiletesting.KotlinCompilation
Expand All @@ -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
Expand Down

0 comments on commit 38fded8

Please sign in to comment.