Fixed
Status Update
Comments
il...@google.com <il...@google.com> #2
Hi Ed, Thank you so much for these suggestions. I've been reviewing them and merging them in. Hopefully it should be live. I've included a thank you note too in the article.
ja...@google.com <ja...@google.com> #3
Great! Thanks a lot, I'll look for the live updates soon!
il...@google.com <il...@google.com> #4
Ah, that does change things. Yes, our current code for
It will also require fixing the
il...@google.com <il...@google.com>
ap...@google.com <ap...@google.com> #5
Project: platform/frameworks/support
Branch: androidx-main
commit 0e93825ab0a4c1df975c47dcbb9df60d94613d6b
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jun 13 22:53:18 2024
No longer drop fragments not in container for predictive back
When using predictive back, if a fragment is not in a container then we
can't run any animations on it. The current behavior is to immediately
move that fragment to the final state, but that means that if you cancel
the transition the fragment will now be destroyed.
Instead of dropping it immediately, we should move any fragments that do
not have a container to their final state after the predicitive back
gesture has completed.
RelNote: "Fixed an issue where fragment without a container were
immediately DESTROYED when starting a predictive back gesture."
Test: modified the original test
Bug: 345244539
Change-Id: If6b83f7dbb655e0bebc99c3c769625626a7c4e8d
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentAnimationTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
https://android-review.googlesource.com/3132935
Branch: androidx-main
commit 0e93825ab0a4c1df975c47dcbb9df60d94613d6b
Author: Jeremy Woods <jbwoods@google.com>
Date: Thu Jun 13 22:53:18 2024
No longer drop fragments not in container for predictive back
When using predictive back, if a fragment is not in a container then we
can't run any animations on it. The current behavior is to immediately
move that fragment to the final state, but that means that if you cancel
the transition the fragment will now be destroyed.
Instead of dropping it immediately, we should move any fragments that do
not have a container to their final state after the predicitive back
gesture has completed.
RelNote: "Fixed an issue where fragment without a container were
immediately DESTROYED when starting a predictive back gesture."
Test: modified the original test
Bug: 345244539
Change-Id: If6b83f7dbb655e0bebc99c3c769625626a7c4e8d
M fragment/fragment/src/androidTest/java/androidx/fragment/app/FragmentAnimationTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentManager.java
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentStateManager.java
jb...@google.com <jb...@google.com> #6
This has been fixed internally and will be available in the Fragment version 1.8.1
release.
pr...@google.com <pr...@google.com> #7
The following release(s) address this bug.It is possible this bug has only been partially addressed:
androidx.fragment:fragment:1.8.1
Description
Component used: Fragment
The new "predictive back" feature has surfaced some interesting issues when dealing with the Fragment backstack. In general, there seems to be a mismatch in expectations as to whether a "destroyed" instance of a Fragment will be re-created or not.
On one hand, when the FragmentManager's predictive back detects that the user canceled the gesture, it will take the Fragment instance that was previously destroyed and add it back to the top of the stack, driving the create/start/resume lifecycle again. It does this by by re-committing the FragmentTransaction that added it .
On the other hand, utilities like the lifecycle-bound coroutine scope do not handle the state re-entering "creation" after its destruction. The scope is created once here and when the destroyed state is reached the supervisor job is canceled and the lifecycle observer is removed.
These two behaviors are incompatible, if I'm following this code correctly.
Technically, the destruction of a Fragment does not prohibit its reuse, and so the FragmentManager behavior is not wrong from what I can tell. However, in practice I can imagine that reusing Fragments this way will inherently lead to bugs that will be difficult to diagnose whenever a lifecycle-dependent behavior assumes that destruction is final. In essence, this introduces a lifecycle transition (destroyed -> created) that many fragments may not be designed to support.
If instead the FragmentManager recreates the Fragment from scratch, that would avoid these issues but there will likely be negative performance implications.
It's worth noting that a user may in fact trigger a predictive back gesture without realizing it. In some cases, a tap near the side edge of the device will trigger the beginning and cancellation of the gesture, without any visual cue that this happened. That will exacerbate the difficulty of reproducing and diagnosing these types of lifecycle state bugs.