Status Update
Comments
jb...@google.com <jb...@google.com> #2
reemission of the same liveData is racy
ju...@gmail.com <ju...@gmail.com> #3
ju...@gmail.com <ju...@gmail.com> #4
ap...@google.com <ap...@google.com> #5
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
ju...@veepee.com <ju...@veepee.com> #6
il...@google.com <il...@google.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> #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
ju...@veepee.com <ju...@veepee.com> #9
We were always allowed to create a new Fragment and to commit a Fragment instance in FragmentManager, could you align with that as well? My abstraction returns a Fragment instance because this allows us to avoid directly depending on the gradle module that provides the Fragment and this strategy improves compilation time by making the gradle dependency graph flatter.
il...@google.com <il...@google.com> #10
You'll want your abstraction to be implemented in terms of a FragmentFactory.
ju...@veepee.com <ju...@veepee.com> #11
My abstraction does not use fragmentFactory, and don't need to. How is that related to this issue? Devs have always been able to instantiate a fragment using default fragment constructor, I am not exposing which Fragment subclass is being instantiated in the calling site or using the className as key to find which fragment to instantiate, to add a fragment to FragmentManager we just need the base class Fragment.
ba...@gmail.com <ba...@gmail.com> #12
il...@google.com <il...@google.com> #13
Re AndroidFragment
with key(url)
to reset that subtree whenever url
changes.
ba...@gmail.com <ba...@gmail.com> #14
Thanks, using key(url)
works like a charm. I thought this function was only available for LazyList|Column
...
ba...@gmail.com <ba...@gmail.com> #15
For your information we have the following crash using AndroidView
:
Exception java.lang.IllegalStateException: Can not perform this action after onSaveInstanceState at androidx.fragment.app.FragmentManager.checkStateLoss (FragmentManager.java:1) at androidx.fragment.app.FragmentManager.ensureExecReady (FragmentManager.java:1) at androidx.fragment.app.FragmentManager.execSingleAction (FragmentManager.java:1) at androidx.fragment.app.BackStackRecord.commitNow (BackStackRecord.java:1) at androidx.fragment.compose.AndroidFragmentKt$AndroidFragment$4.invoke (AndroidFragment.kt:110) at androidx.fragment.compose.AndroidFragmentKt$AndroidFragment$4.invoke (AndroidFragment.kt:3) at androidx.compose.runtime.DisposableEffectImpl.onRemembered (Effects.kt:7) at androidx.compose.runtime.CompositionImpl$RememberEventDispatcher.dispatchRememberObservers (Composition.kt:144) at androidx.compose.runtime.CompositionImpl.applyChangesInLocked (Composition.kt:1) at androidx.compose.runtime.CompositionImpl.applyChanges (Composition.kt:6) at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke (Recomposer.kt:1) at androidx.compose.runtime.Recomposer$runRecomposeAndApplyChanges$2$1.invoke (Recomposer.kt:7) at androidx.compose.ui.platform.AndroidUiFrameClock$withFrameNanos$2$callback$1.doFrame (AndroidUiFrameClock.android.kt:11) at androidx.compose.ui.platform.AndroidUiDispatcher.performFrameDispatch (AndroidUiDispatcher.android.kt:34) at androidx.compose.ui.platform.AndroidUiDispatcher.access$performFrameDispatch (AndroidUiDispatcher.android.kt:1) at androidx.compose.ui.platform.AndroidUiDispatcher$dispatchCallback$1.doFrame (AndroidUiDispatcher.android.kt:17) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1229) at android.view.Choreographer$CallbackRecord.run (Choreographer.java:1239) at android.view.Choreographer.doCallbacks (Choreographer.java:899) at android.view.Choreographer.doFrame (Choreographer.java:827) at android.view.Choreographer$FrameDisplayEventReceiver.run (Choreographer.java:1214) at android.os.Handler.handleCallback (Handler.java:942) at android.os.Handler.dispatchMessage (Handler.java:99) at android.os.Looper.loopOnce (Looper.java:201) at android.os.Looper.loop (Looper.java:288) at android.app.ActivityThread.main (ActivityThread.java:7918) at java.lang.reflect.Method.invoke at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:936)
lo...@gmail.com <lo...@gmail.com> #16
Will there also be an overload in which we can directly pass in an already created fragment instance? Like:
fun <T : Fragment> AndroidFragment(
fragment: T,
modifier: Modifier = Modifier,
fragmentState: FragmentState = rememberFragmentState(),
arguments: Bundle = Bundle.EMPTY,
onUpdate: (T) -> Unit = { },
) { ... }
il...@google.com <il...@google.com> #17
Re
il...@google.com <il...@google.com> #18
Re
Description
What is the correct strategy to restoring a fragment commited inside a compose AndroidView? I would expect that something like the example below to be enough to handle the fragment state restoration in an orientation change, but when rotating the screen the fragment is no longer drawn.
It would be nice to have a composable version of
FragmentContainerView
that could handle Fragment state restoration properly.