Status Update
Comments
il...@google.com <il...@google.com>
wa...@reaktor.fi <wa...@reaktor.fi> #2
I just encountered the same issue. This causes unexpected behavior as navigation does not occur when navigate
is called, but does suddenly occur if recomposition is triggered externally.
I attached a video demonstrating the behavior, it runs the following code:
package com.example.delayednavigation
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.*
import androidx.compose.material.Button
import androidx.compose.material.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.*
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
val navController = rememberNavController()
var counter by remember { mutableStateOf(0) }
Column(
Modifier.fillMaxSize().padding(24.dp)
) {
NavHost(
navController = navController,
startDestination = "home"
) {
composable("home") {
Text(text = "Route: /home")
Spacer(Modifier.height(24.dp))
NavigationButtons(navController = navController)
}
composable("page/{id}") {
Column(verticalArrangement = Arrangement.Center) {
Text(text = "Route: page/${it.arguments!!["id"]}")
Spacer(Modifier.height(24.dp))
Text(text = "Counter: $counter")
Spacer(Modifier.height(24.dp))
NavigationButtons(navController = navController)
Button(onClick = { counter += 1 }) {
Text("Recompose")
}
}
}
}
}
}
}
}
@Composable
fun NavigationButtons(
navController: NavController
) {
Column {
(1..3).forEach { pageId ->
Button(
modifier = Modifier.padding(bottom = 24.dp),
onClick = {
navController.navigate("page/$pageId") {
launchSingleTop = true
}
}) {
Text("Navigate to page $pageId")
}
}
}
}
This was with navigation-compose:2.4.0-alpha03
and compose:1.0.0-beta09
.
th...@gmail.com <th...@gmail.com> #3
ap...@google.com <ap...@google.com> #4
Branch: androidx-main
commit 131e54a109dc6234a9da799a969751d11903b536
Author: Jeremy Woods <jbwoods@google.com>
Date: Tue Jun 22 20:03:42 2021
Ensure recompose on launchSingleTop arg changes
When using single top and changing the arguments on the current
navBackStackEntry, there is no recompose since we do not actually change
the backstack.
RelNote: "Changing the arguments on a `NavBackStackEntry` will now
trigger a recompose"
Test: NavHostControllerTest
Bug: 186392337
Change-Id: I3bfea9a4551806140cf18c6d3e9258218aae2d37
M navigation/navigation-common/api/current.txt
M navigation/navigation-common/api/public_plus_experimental_current.txt
M navigation/navigation-common/api/restricted_current.txt
M navigation/navigation-common/src/main/java/androidx/navigation/Navigator.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavigatorState.kt
M navigation/navigation-compose/src/androidTest/java/androidx/navigation/compose/NavHostControllerTest.kt
jb...@google.com <jb...@google.com> #5
This has been fixed internally and will be available in the Navigation 2.4.0-alpha07
release.
You can try this out by following the #7634339
.
ro...@gmail.com <ro...@gmail.com> #6
I tried the new snapshot version, but it doesn't seem to be working for me.
Using a debugger, I verified that the new NavigatorState.onLaunchSingleTop()
was called, and the updatedBackStack
that was set with the expected argument update.
However, the NavHost
's composable
still doesn't get recomposed. Is it possible that arguments
are somehow being filtered out in state update changes?
jb...@google.com <jb...@google.com> #7
Please file a new bug with a minimal sample project that reproduces your issue.
ro...@gmail.com <ro...@gmail.com> #9
The issue in Empty
. But if you leave the app open and toggle the system dark mode, now the app will get recomposed with the new value2
.
If it helps, I can share the project, but it's really just the code from
th...@gmail.com <th...@gmail.com> #10
th...@gmail.com <th...@gmail.com> #11
Also, IMO, this is a core issue and should be marked as a high priority.
ap...@google.com <ap...@google.com> #13
Branch: androidx-main
commit 5f1bdbbffc8c06355b22fdfe72ef1cf666b0d904
Author: Jeremy Woods <jbwoods@google.com>
Date: Wed Aug 18 03:45:03 2021
Ensure changing arguments causes recompose
Now that NavBackStackEntries are immutable and we don't just change
arguements, we change entire entries, we should make sure NavigatorState
properly handles launchSingleTop.
The only thing we need to do is to update both the navController and
navigator state back stacks with the proper entry.
RelNote: "Navigation Compose now properly recomposes when changing back
stack arguments and using launchSingleTop=true."
Test: all tests pass, and tested in samples from bug
Bug: 186392337
Fixes: 196390311
Change-Id: Iebd698c9e310ad84ce65238c8a5a33db86a9f1f7
M navigation/navigation-common/api/current.txt
M navigation/navigation-common/api/public_plus_experimental_current.txt
M navigation/navigation-common/api/restricted_current.txt
M navigation/navigation-common/src/main/java/androidx/navigation/Navigator.kt
M navigation/navigation-common/src/main/java/androidx/navigation/NavigatorState.kt
M navigation/navigation-runtime/src/androidTest/java/androidx/navigation/NavControllerTest.kt
M navigation/navigation-runtime/src/main/java/androidx/navigation/NavController.kt
jb...@google.com <jb...@google.com> #14
We were able to get a fix for this in Navigation 2.4.0-alpha08
.
You can try this out by following the #7677699
.
ma...@gmail.com <ma...@gmail.com> #15
jb...@google.com <jb...@google.com> #16
Please file a new bug with a minimal sample project that reproduces the issue.
so...@gmail.com <so...@gmail.com> #17
The same issue still exists.
il...@google.com <il...@google.com> #18
Re
Description
Component used: Navigation-Compose Version used: 1.0.0-alpha10, Compose 1.0.0-beta05
A bit short on time, so just posting a simple repro here. When trying to navigate to a destination that is the current destination but with different arguments using
NavOptions.launchSingleTop
, the NavController will replace the current NavBackStackEntry's arguments. Consider the following example:In
NavController#currentBackStackEntryAsState
, theState
's value won't be changed because the reference stays the same and the NavBackStackEntry held by the state has already been mutated, so theNavHost
won't recompose after that change. Maybe theNeverEqualPolicy
could be used as a quick fix.Let me know if you need more info, cheers!