Status Update
Comments
pa...@cardinalblue.com <pa...@cardinalblue.com> #2
reemission of the same liveData is racy
pa...@cardinalblue.com <pa...@cardinalblue.com> #3
jb...@google.com <jb...@google.com> #4
pa...@cardinalblue.com <pa...@cardinalblue.com> #5
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
mi...@gmail.com <mi...@gmail.com> #6
pa...@cardinalblue.com <pa...@cardinalblue.com> #7
I actually have a WIP fix for it:
if your case is the one i found (emitting same LiveData multiple times, as shown in #5) you can work around it by adding a dummy transformation.
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData.map {it })
emitSource(subLiveData.map {it} )
}
il...@google.com <il...@google.com>
ti...@google.com <ti...@google.com> #8
Branch: androidx-master-dev
commit af12e75e6b4110f48e44ca121466943909de8f06
Author: Yigit Boyar <yboyar@google.com>
Date: Tue Sep 03 12:58:11 2019
Fix coroutine livedata race condition
This CL fixes a bug in liveData builder where emitting same
LiveData source twice would make it crash because the second
emission registry could possibly happen before first one is
removed as source.
We fix it by using a suspending dispose function. It does feel
a bit hacky but we cannot make DisposableHandle.dispose async
and we do not want to block there. This does not mean that there
is a problem if developer disposes it manually since our emit
functions take care of making sure it disposes (and there is
no other way to add source to the underlying MediatorLiveData)
Bug: 140249349
Test: BuildLiveDataTest#raceTest_*
Change-Id: I0b464c242a583da4669af195cf2504e2adc4de40
M lifecycle/lifecycle-livedata-ktx/api/2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/current.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/public_plus_experimental_current.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_2.2.0-alpha05.txt
M lifecycle/lifecycle-livedata-ktx/api/restricted_current.txt
M lifecycle/lifecycle-livedata-ktx/src/main/java/androidx/lifecycle/CoroutineLiveData.kt
M lifecycle/lifecycle-livedata-ktx/src/test/java/androidx/lifecycle/BuildLiveDataTest.kt
ti...@google.com <ti...@google.com> #9
I was able to repro the issue with the project linked in
It seems to me like a layout issue that was recently fixed, as the issue is fixed if I use a later version of the ui lib: implementation("androidx.compose.ui:ui:1.6.0-alpha03")
or newer.
pa...@cardinalblue.com <pa...@cardinalblue.com> #10
Please consider adding navigation to the compose BOM. Or at least when there's a stable release of the navigation library make sure it works well with the latest compose BOM. Updating the stable minor version of the navigation library should not break anything.
pa...@cardinalblue.com <pa...@cardinalblue.com> #11
Thanks for the info btw, I've decided to stay at 2.7.0-beta02
for now, since I know that works in my project and I am not comfortable with updating my compose ui to some alpha version
ti...@google.com <ti...@google.com> #12
Over to Jeremy for plans regarding releasing future versions of navigation.
hi...@gmail.com <hi...@gmail.com> #13
mi...@fresha.com <mi...@fresha.com> #14
ma...@gmail.com <ma...@gmail.com> #15
Another way to reproduce the issue between 2.7.0 (works) and 2.7.1 (broken) is a simple slideIntoContainer and slideOutOfContainer navigation. Hit the button in the example below fast and you'll see animations flying in from the corner instead of sliding!! (btw tested 2.7.5 and its still broken)
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
MaterialTheme {
val navController = rememberNavController()
NavHost(navController = navController, startDestination = "first_screen") {
composable(
route = "first_screen",
enterTransition = {
slideIntoContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
)
},
exitTransition = {
slideOutOfContainer(
towards = AnimatedContentTransitionScope.SlideDirection.Left,
)
},
) {
FirstScreen {
navController.navigate("first_screen")
}
}
}
}
}
}
}
@Composable
fun FirstScreen(navigate: () -> Unit) {
Column(
modifier = Modifier.fillMaxSize(),
verticalArrangement = Arrangement.Center,
horizontalAlignment = Alignment.CenterHorizontally
) {
Button(onClick = {
navigate()
}) {
Text(text = "Navigate!")
}
}
}
jb...@google.com <jb...@google.com> #16
In 2.7.1
we provided a fix for androidx.compose.ui:ui:1.6.0-alpha03
, but since it added new APIs it cannot be backported into a point release of Compose 1.5.x
.
Once compose 1.6.0 is stable, we can bump the dependency and release a new version of Navigation with the fix, but until then you can resolve it by either bumping your own compose dependency to use 1.6.x
or continuing to use Navigation 2.7.0
if you don't need any of the fixes from the other Navigation point releases.
jb...@google.com <jb...@google.com> #17
Navigation 2.8.0-alpha01
has upgraded the Compose dependency to 1.7.0-alpha01
so this will be addressed in the next release.
j....@gmail.com <j....@gmail.com> #18
Since compose 1.6.0 is live can we have a fix for that?
ma...@gmail.com <ma...@gmail.com> #19
al...@gmail.com <al...@gmail.com> #20
ir...@gmail.com <ir...@gmail.com> #21
We have the same issue (Compose 1.6.2 and Navigation-Compose 2.7.6).
After explicitly setting the enter and exit transitions, I noticed that on some screens it was working correctly, on others it wasn't. The nav destination screens working correctly were calling the .fillMaxSize() modifier on the outermost/topmost Composable in the view composition hierarchy.
So the accidental/unwanted scale animation seems to have something to do with the sizing of the view children during layouting.
Instead of now having to add sizing modifiers to all destination Composables/screens, adding the .fillMaxSize() modifier to the NavHost itself does the trick. As a result, the specified enter and exit transitions are never overriden by whatever causes the bug.
NavHost(
modifier = Modifier.fillMaxSize(),
navController = navController,
startDestination = navController.currentBackStackEntry?.destination?.route ?: ProfileDestination.Overview.route(),
enterTransition = { fadeIn(animationSpec = tween(200)) },
exitTransition = { fadeOut(animationSpec = tween(200)) }
)
al...@gmail.com <al...@gmail.com> #22
We observe the same behaviour as described in the previous comment – if size of the NavHost was not zero and changing as a result of navigation, we can see weird left slide-in animation. So I doubt this issue is fixed
il...@google.com <il...@google.com> #23
Please make sure you've updated to the recently released
Description
Version used: 2.7.1
Devices/Android versions reproduced on: Pixel 7
Using the navigation compose in the previous version I was able to immediately navigate away from the landing screen, if the user is logged in, with a nice crossfade animation playing between my landing screen and main screen. See: it-was-working-in-2.7.0-beta02.mp4
Upon updating the experience has gotten worse: when navigating away from the landing screen (while it's enter animation hasn't finished yet), a weird inflating animation is playing. See: expanding-bug.mp4
Since these are only cross fade animations the size of the container should never change. Why does the size of the container animating for a simple crossfade animation?
Expected behavior:
Since the size of the initial screen doesn't change during it's enter transition, I would expect the second screen to only play a fade in animation without the weird clipping/size changing that's happening at the moment.
Code to reproduce: (see also NavHostBugReport.zip)
```
NavHostBugReportTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
val navController = rememberNavController()
NavHost(navController = navController, "@landing") {
navigation("landing", "@landing") {
composable("landing") {
Box(modifier = Modifier
.fillMaxSize()
.background(Color.Red))
LaunchedEffect(key1 = Unit) {
navController.navigate("main")
}
}
}
navigation("main", "@main") {
composable("main") {
Box(modifier = Modifier
.fillMaxSize()
.background(Color.Blue))
}
}
}
}
}
```
If this is a bug in the library, we would appreciate if you could attach:
- Sample project to trigger the issue. (attached: NavHostBugReport.zip)
- A screenrecord or screenshots showing the issue (if UI related).
working correctly in 2.7.0-beta02: it-was-working-in-2.7.0-beta02.mp4
working unexpectedly in 2.7.1: expanding-bug.mp4