Status Update
Comments
il...@google.com <il...@google.com> #2
reemission of the same liveData is racy
sa...@gmail.com <sa...@gmail.com> #3
ch...@google.com <ch...@google.com> #4
ki...@gmail.com <ki...@gmail.com> #5
@Test
fun raceTest() {
val subLiveData = MutableLiveData(1)
val subject = liveData(testScope.coroutineContext) {
emitSource(subLiveData)
emitSource(subLiveData) //crashes
}
subject.addObserver().apply {
testScope.advanceUntilIdle()
}
}
il...@google.com <il...@google.com> #6
ki...@gmail.com <ki...@gmail.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} )
}
ap...@google.com <ap...@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
il...@google.com <il...@google.com> #9
Bad news: Nested AnimationSet
instances are broken at a fundamental layer that Fragments can't work around. We strongly recommend switching to Animator
or AndroidX Transition
and are doing that internally in
Good news: We're reverting to the equivalent behavior of the old state manager in that we won't use an additional layer of AnimationSet
for entering Animations. This means that unlike Animators or Transitions, a Fragment using Animation
will immediately move to RESUMED
before the Animation
completes when using the new state manager.
g....@gmail.com <g....@gmail.com> #10
The only reason why I'm using Animation
is that I need to use percent values, as in the animation of FragmentTransaction
(and by extension Navigation
) only accepts @AnimatorRes
and @AnimRes
, I can't create the animation programmatically.
Is there any alternative to Animation
in this case?
il...@google.com <il...@google.com> #11
Re #10 - note that even when you do not pass a resource ID, you can still override onCreateAnimation()
or onCreateAnimator()
on your Fragment and return any custom Animation
or Animator
you want - there is no requirement that you only use Animations/Animators inflated from XML when using Fragments (and by extension, when using Navigation).
g....@gmail.com <g....@gmail.com> #12
Thank you, that does the trick. I even used to patch animations on the fly before you fixed all the issues I had with FragmentContainerView
, how could not I think of doing that.
For those reading that might be in a similar situation:
I have few animations that I use throughout the applications and they are all defined in the actions of the navigation graph. Since I have a common base Fragment class, I added something like the following to that base class (using the animation in
@Nullable
@Override
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) {
if (nextAnim == R.anim.transition_slide_left_show) {
int width = requireActivity().getWindow().getDecorView().getWidth();
ObjectAnimator anim = ObjectAnimator.ofFloat(getView(), View.TRANSLATION_X, -width, 0);
anim.setStartDelay(300);
anim.setDuration(300);
anim.setInterpolator(new DecelerateInterpolator());
return anim;
} else {
return super.onCreateAnimator(transit, enter, nextAnim);
}
}
This is probably not ideal given that now the XML animation is ignored, that could be not very obvious (you could also not outright ignore it), but it's a quick and easy solution to turn several XML based Animation
s into Animator
s.
il...@google.com <il...@google.com> #13
For full screen slides, you should strongly consider using a Slide
Transition
yc...@gmail.com <yc...@gmail.com> #14
I have got this bug with 'sharedElementReturnTransition', it causes blinking too. Also it doesn't happens with FragmentManager.enableNewStateManager(false). Any ideas? I don't want to use it unless I have to.
il...@google.com <il...@google.com> #15
Re #14 - Transitions do not use Animations so that would be unrelated to this issue. Please file a new issue with a sample project that reproduces your issue using the latest Fragment 1.3.2.
yc...@gmail.com <yc...@gmail.com> #16
I have tried to make a sample depends in
but I can't found the blinking, maybe there is something wrong in my project, I will try more, anyway ,thanks for reply!
yc...@gmail.com <yc...@gmail.com> #17
Re #15 - I have figured out the problem! It's just because I did some Job at "onPause()" in the return blinking Fragment!
Description
Component used: Fragment
Version used: 1.3.0-Snapshot (Build Id: 6743994)
Devices/Android versions reproduced on: Samsung Galaxy S10 running Android 10
When using "setCustomAnimations" on Fragment Transitions, the animations are broken (flashing) when using the new state manager.
Steps:
FragmentManager.enableNewStateManager(false)
inMainActivity
and re-run the appAttached is a sample and 2 videos detailing the difference in animations with the state manager being turned on and off