Sofiane Abbar
07/22/2024, 3:42 AMcompose = "1.6.11"
compose-plugin = "1.6.11"
navigationCompose = "2.7.0-alpha07"
Then here is the nav
NavHost(
navController = navController,
startDestination = AutomedonScreen.Splash.name,
modifier = Modifier.fillMaxSize()
) {
composable(route = AutomedonScreen.Login.name) {
LoginScreen(
modifier = Modifier.padding(
bottom = WindowInsets.systemBars.asPaddingValues().calculateBottomPadding()
).fillMaxSize(),
context = context,
nav = navController
)
}
composable(route = AutomedonScreen.Splash.name) {
SplashScreen(
modifier = Modifier.fillMaxSize(),
context = context,
nav = navController
)
}
composable(route = "${AutomedonScreen.Geolocation.name}/{routeTo}") { backStackEntry ->
GeolocationPermissionScreen(
modifier = Modifier.padding(
top = WindowInsets.systemBars.asPaddingValues().calculateTopPadding(),
bottom = WindowInsets.systemBars.asPaddingValues().calculateBottomPadding()
).fillMaxSize(),
routeTo = backStackEntry.arguments?.getString("routeTo")
?: AutomedonScreen.Login.name,
context = context,
nav = navController
)
}
From the Splash screen I am using this to navigate to Geolocation page, really simple:
routeTo = AutomedonScreen.Login.name
nav.navigate(AutomedonScreen.Geolocation.name + "/$routeTo")
that result in
Uncaught Kotlin exception: kotlin.IllegalArgumentException: No destination with route /Login is on the NavController's back stack. The current destination is Destination route=Geolocation/{routeTo}
Thanks…Richard
07/22/2024, 6:00 AMIvan Matkov
07/22/2024, 7:30 AMCompose Navigation support params on iOS?Yes
it just crash on iOS, but works like a charm on Android.Please open an issue with simplified reproduction in our issue tracker, I'll have a look
No destination with route /Login is on the NavController's back stack.It looks like "Geolocation" substring is missing. Can it be null or so in your code?
You could go with 1.7.0-alpha01 that has the latest navigation lib and where you can use type safety. 🙂It does not related to question/problem. string params should work just fine in 1.6.11/2.7.*
Sofiane Abbar
07/22/2024, 9:09 AMIt looks like “Geolocation” substring is missing. Can it be null or so in your code?No, impossible, I keep my pages as enum and it is always available everywhere.
enum class AutomedonScreen(val title: String) {
Splash("Splash"),
Login("Login"),
Geolocation("Geolocation")
}
On android it really works fine, but on iOS, it can’t even find this enum within the nav.
println("Geolocation/$routeTo") // this is printed correclty on iOS and routeTo is Automedon.Login.name (Login)
nav.navigate("Geolocation/$routeTo") // routeTo is Login and I have hardcoded Geolocation... still not working
Even if I hardcode the Geolocation I am still getting
No destination with route /Login is on the NavController's back stack. The current destination is Destination route=Geolocation/{routeTo}
Which is really weird.
If I navigate to another page without param, it works fine even on iOS
I will submit an issueIvan Matkov
07/22/2024, 9:42 AMIvan Matkov
07/22/2024, 9:43 AMIvan Matkov
07/22/2024, 9:43 AMIvan Matkov
07/22/2024, 9:45 AMIvan Matkov
07/22/2024, 9:55 AMThe error is about transaction FROMUncaught Kotlin exception: kotlin.IllegalArgumentException: No destination with route /Login is on the NavController's back stack. The current destination is Destination route=Geolocation/{routeTo}
Geolocation/{routeTo}
, not from splash. And you're trying to navigation to "/Login" instead of just "Login" that you registered in graph. It's not listed in any provided code, so it's probably why it's not reproducible.
Waiting for additional information from your side to continue investigation (if it's still needed)Sofiane Abbar
07/22/2024, 10:57 AM@Composable
fun GeolocationPermissionScreen(
modifier: Modifier,
routeTo: String,
context: Any?,
nav: NavHostController
) {
val viewModel: GeolocationPermissionViewModel =
viewModel { GeolocationPermissionViewModel(context) }
val navBackStackEntry =
remember { nav.getBackStackEntry("${AutomedonScreen.Geolocation.name}/$routeTo") }
LaunchedEffect(navBackStackEntry) {
println("GeolocationPermissionScreen LaunchedEffect IOS")
// Observer to detect when this entry is resumed
val observer = LifecycleEventObserver { _, event ->
if (event == Lifecycle.Event.ON_RESUME) {
// Call the function when the screen is revisited
viewModel.checkGeolocationPermission(nav, routeTo)
}
}
// Add observer
navBackStackEntry.lifecycle.addObserver(observer)
}
If I comment the LaunchedEffect
and the navbackStackEntry
, it can navigate to that page.
This piece of code works on Android, all I want to do is after the user is in the device app setting to modify the location permission, after returning to the app, I am checking the permission on the ON_RESUME
.
That part crash on iOS.
val navBackStackEntry =
remember { nav.getBackStackEntry("${AutomedonScreen.Geolocation.name}/$routeTo") }
The enum is not loaded here.
Sorry I really thought it never load that page at first
You can mark it as closed, sorry for the trouble…🙏Sofiane Abbar
07/22/2024, 10:58 AM