Status Update
Comments
jb...@google.com <jb...@google.com> #2
I'm marking this as "won't fix" as there's nothing Compose here can do, as this is a platform quirk that has been adjusted to be more predictable in recent API versions.
The crux of the issue here is the fitSystemWindows
in the extra View
, like you mentioned, and a platform change in API 30.
Prior to API 30, window insets were dispatched through the view hierarchy in a non-intuitive way: Rather than being a full breadth-first traversal, they would be dispatched in preorder. If the insets were consumed at any point (like if you use fitSystemWindows
), then the preorder would prevent insets from being dispatched to the rest of the view hierarchy. This is very unintuitive: It meant that sibling views (or views deeper in the tree) could stop later views from receiving the dispatch of insets.
In API 30, this behavior was changed to be more intuitive: Now, insets are dispatched in a top-down manner, so they can't be consumed in this weird, cross-tree way.
There's a couple solutions here:
- Avoid
fitSystemWindows
from views if you're handling insets manually - Override
dispatchApplyWindowInsets
in the view groups above where you havefitSystemWindows
defined, and manually perform the new, non-broken dispatching behavior. You can see a comparison of the two methods here:https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/view/ViewGroup.java;l=7341-7371;drc=6411c81462e3594c38a1be5d7c27d67294139ab8
Description
Version used: 2.7.5
Devices/Android versions reproduced on: Pixel 4XL API 33 arm64 AVD
Preconditions: turn on "Don't keep activities" settings in the Developers options, to simulate app killing
Steps to reproduce:
1. Open app.
2. Select the second or third page on the home screen.
3. Open a new screen via the bottom menu.
4. Minimize app, and open app from recent apps.
5. Do the same thing as in the 4 step again.
6. Press the hardware back button to return to the first screen.
Expected result:
The state of the first screen was saved and restored successfully: we returned to the same page.
Actual result:
The state of the first screen wasn't restored: we returned to the first page.
Note:
The problem is reproduced only if navGraph is set programmatically (navGraphProgrammatically.webm). If we set it in the XML layout for the FragmentContainer everything works as expected (navGraphInXml.webm).
Also, the problem won't reproduce if we minimize/open app only once (navGraphMinimizeOnce.webm).