Status Update
Comments
il...@google.com <il...@google.com> #2
Branch: androidx-main
commit 57ca221882695bd6a52549f4d9ea3b812e6fe87c
Author: Simon Schiller <simonschiller@users.noreply.github.com>
Date: Mon Mar 22 16:09:30 2021
[GH] [FragmentStrictMode] Detect <fragment> tag usage
## Proposed Changes
- Detect `<fragment>` tag usage inside XML layouts
## Testing
Test: See `FragmentStrictModeTest#detectFragmentTagUsage`
## Issues Fixed
Fixes: 153738235
This is an imported pull request from
Resolves #141
Github-Pr-Head-Sha: 4ea052596e4341b9f11bcf335e2bc38045a91f19
GitOrigin-RevId: 62e7487aa4874eef6bb556490e193717cf937251
Change-Id: Iae48578e85e4e4897f806d7ade2e2a660adf9479
M fragment/fragment/api/public_plus_experimental_current.txt
M fragment/fragment/api/restricted_current.txt
M fragment/fragment/src/androidTest/java/androidx/fragment/app/strictmode/FragmentStrictModeTest.kt
M fragment/fragment/src/main/java/androidx/fragment/app/FragmentLayoutInflaterFactory.java
M fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentStrictMode.java
A fragment/fragment/src/main/java/androidx/fragment/app/strictmode/FragmentTagUsageViolation.java
ja...@google.com <ja...@google.com> #3
Update from an offline discussion:
We do actually allow fragment reordering, but it seems that we are running into the problem because our fragments are not being added to a Fragment container due to an existing legacy navigation system.
Is there something that can be done to ensure that these containerless fragments don't get destroyed when the gesture starts and still properly get cleaned up when the gesture is committed? And in the interim, perhaps a more stern warning for those attempting to support predictive back if they are not part of a fragment container?
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
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.