Status Update
Comments
ti...@google.com <ti...@google.com> #2
Oh I forgot to mention that I thought it might be connected to this issue:
qu...@gmail.com <qu...@gmail.com> #3
Please provide a minimal sample project along with the minimal steps to recreate the issue in the project.
ti...@google.com <ti...@google.com> #4
Sorry for the delay. I got a working example here:
I poked into it a little bit and it seems to be connected to
Steps to reproduce:
- Navigate from Second Fragment to Child nav graph (with non-nullable parameters).
- Navigate to Third fragment using SafeArgs and the app crashes.
Crash log:
Process: cz.dels.issues, PID: 1743
java.lang.NullPointerException: null cannot be cast to non-null type kotlin.Long
at androidx.navigation.NavType$Companion$LongType$1.get(NavType.kt:352)
at androidx.navigation.NavType$Companion$LongType$1.get(NavType.kt:342)
at androidx.navigation.NavArgument.verify(NavArgument.kt:76)
at androidx.navigation.NavDestination.addInDefaultArgs(NavDestination.kt:502)
at androidx.navigation.NavController.addEntryToBackStack(NavController.kt:1865)
at androidx.navigation.NavController.addEntryToBackStack$default(NavController.kt:1813)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1721)
at androidx.navigation.NavController$navigate$4.invoke(NavController.kt:1719)
at androidx.navigation.NavController$NavControllerNavigatorState.push(NavController.kt:287)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:246)
at androidx.navigation.fragment.FragmentNavigator.navigate(FragmentNavigator.kt:162)
at androidx.navigation.NavController.navigateInternal(NavController.kt:260)
at androidx.navigation.NavController.navigate(NavController.kt:1719)
at androidx.navigation.NavController.navigate(NavController.kt:1545)
at androidx.navigation.NavController.navigate(NavController.kt:1472)
at androidx.navigation.NavController.navigate(NavController.kt:1930)
at cz.dels.issues.SecondFragment.onViewCreated$lambda-0(SecondFragment.kt:38)
at cz.dels.issues.SecondFragment.$r8$lambda$XDYnOS_cYrafiNQ5rcCu1WCn0IE(Unknown Source:0)
at cz.dels.issues.SecondFragment$$ExternalSyntheticLambda0.onClick(Unknown Source:2)
Note: If in step 2 SaveArgs is not used then navigation works correctly. More information is here:
ma...@google.com <ma...@google.com> #5
Ups a typo: Navigate from Second First Fragment to Child nav graph (with non-nullable parameters).
Note: sorry for the spam but I am not able to edit my own comment.
lp...@google.com <lp...@google.com> #6
This has been fixed and will be available in navigation 2.6.0-alpha08
qu...@gmail.com <qu...@gmail.com> #7
Branch: androidx-main
commit 6b358154b794a0456b089ac8e548bfb830dd6c22
Author: Clara Fok <clarafok@google.com>
Date: Tue Mar 14 17:56:12 2023
Fix missing non-nullable arg when rebuilding hierarchy
When navigating with NavDirections, args is populated with an empty bundle. This causes issue when we rebuild parent hierarchy while adding a new entry to NavBackStack. If the Entry being rebuilt contains a non-nullalbe arg, i.e. Long, this empty bundle will cause an exception.
Test: ./gradlew navigation:navigation-runtime:cC
Bug: 249988437
Change-Id: I5c8ce739ad9a3428c8a8de13eae391bfff0db5df
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
ma...@gmail.com <ma...@gmail.com> #8
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.navigation:navigation-runtime:2.6.0-alpha08
an...@google.com <an...@google.com> #9
The issue is inside NavHost.
val modifier = Modifier.padding(padding)
NavHost(navController, startDestination = FIRST_SCREEN) {
composable(FIRST_SCREEN) {
MyScreen(modifier, Color.Blue) {
navController.navigate(SECOND_SCREEN)
}
}
composable(SECOND_SCREEN) {
MyScreen(modifier, Color.Red) {
navController.navigate(FIRST_SCREEN)
}
}
}
When the size has been changed the first line is recomposed and the new modifier object is constructed. Then NavHost is reinvoked with a new builder which contains new lambdas which captures a new modifier. But currently NavHost is not supporting nav graph updates so the new lambdas are ignored. As a result we end up using the initial value of the captured modifier object forever which had size 0. The current workaround would be something like
val modifier = rememberUpdatedState(Modifier.padding(padding))
NavHost(navController, startDestination = FIRST_SCREEN) {
composable(FIRST_SCREEN) {
MyScreen(modifier.value, Color.Blue) {
navController.navigate(SECOND_SCREEN)
}
}
composable(SECOND_SCREEN) {
MyScreen(modifier.value, Color.Red) {
navController.navigate(FIRST_SCREEN)
}
}
}
In this case we wrap the value inside the state object so we can update the state and the old lambda would still use the correct modifier.
Jeremy, assigning it to you as the only correct solution is to support graph updates
an...@google.com <an...@google.com> #11
qu...@gmail.com <qu...@gmail.com> #12
an...@google.com <an...@google.com> #13
qu...@gmail.com <qu...@gmail.com> #14
Alright. I guess this would hit two issues at the same time then. Thank you!
il...@google.com <il...@google.com> #15
Note that if you want to pad in all screens, you should passing the padding directly to NavHost
rather than manually to each screen:
) { padding ->
NavHost(navController, startDestination = FIRST_SCREEN, Modifier.padding(padding)) {
composable(FIRST_SCREEN) {
MyScreen(Color.Blue) {
navController.navigate(SECOND_SCREEN)
}
}
composable(SECOND_SCREEN) {
MyScreen(Color.Red) {
navController.navigate(FIRST_SCREEN)
}
}
}
}
}
This was made possible in
ap...@google.com <ap...@google.com> #16
Branch: androidx-main
commit 294e5e2a1f2933cb927f9ad2bdd7763923295f49
Author: Jeremy Woods <jbwoods@google.com>
Date: Mon Jun 21 14:15:54 2021
Override equals in NavGraph and NavDestinations
Instead of relying on the default equals() behavior that requires
NavGraphs and NavDestinations to be the exact instance to be
considered equal, we should specifically define equals to be objects
with the same values, even if they instances are not exactly the same.
RelNote: "`NavGraph` and `NavDestination`s now override the equals method so
two objects with the same values will be considered equal."
Test: NavGraphTest and NavDestinationAndroidTest
Bug: 175392262
Change-Id: I166eb54122cabc12cc569daea8eefcf8e0ec95a7
M navigation/navigation-common/src/androidTest/java/androidx/navigation/NavDestinationAndroidTest.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavDeepLink.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavDestination.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavGraph.kt
M navigation/navigation-common/src/test/java/androidx/navigation/NavGraphTest.kt
M navigation/navigation-dynamic-features-fragment/src/main/java/androidx/navigation/dynamicfeatures/fragment/DynamicFragmentNavigator.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicActivityNavigator.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicGraphNavigator.kt
M navigation/navigation-dynamic-features-runtime/src/main/java/androidx/navigation/dynamicfeatures/DynamicIncludeGraphNavigator.kt
M navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/DialogFragmentNavigator.kt
M navigation/navigation-fragment/src/main/java/androidx/navigation/fragment/FragmentNavigator.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/ActivityNavigator.kt
ap...@google.com <ap...@google.com> #17
Branch: androidx-main
commit 5e187e759d673ea9c45d7fafe8e98260fe090bd4
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed Jun 23 13:30:16 2021
Allow the NavGraph to be changed in NavHost
Since NavGraph now implements its own equals based on the data in the
graph rather than the instance, we can stop always remembering the
NavGraph and allow it to be changed on recompose.
RelNote: "You can now make changes to the graph of a NavHost. Graphs
with the same startDestination and destinations in the graph will be
considered equal and will not clear the navController back stack."
Test: setSameGraph
Bug: 175392262
Change-Id: I0b8dbcea4186232c3280c4a43be11e4fafcc6ce3
M navigation/navigation-common/src/main/java/androidx/navigation/NavBackStackEntry.kt
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostTest.kt
M navigation/navigation-compose/src/main/java/androidx/navigation/compose/NavHost.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
jb...@google.com <jb...@google.com> #18
This has been fixed internally and will be part of the Navigation 2.4.0-alpha05
release.
Description
Jetpack Compose release version: 1.0.0-alpha08 Android Studio Build: Android Studio Arctic Fox | 2020.3.1 Canary 2
BottomBar no longer updates Scaffold's contentPadding whenever bottomBar changes "visibility".
Here is the sample code to reproduce: