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
io...@gmail.com <io...@gmail.com> #3
Using composable version 1.2.1, I could fix it using:
override fun onCreate(bundle: Bundle?) {
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(bundle)
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q){
window.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
}
}
Then statusBarsPadding works as expected on Api 29
jb...@google.com <jb...@google.com> #4
jb...@google.com <jb...@google.com> #5
Going to use this bug to track updating the
io...@gmail.com <io...@gmail.com> #6
Thank you for the detailed explaination, now it makes sense why onSavedInstanceState()
is called and I don't have my binding ready.
Do you mind telling me what is the view's API that you are referring to, for saving the state? Is it the
Another option that I was thinking about was to ignore the entire saving in case the binding is invalid(to avoid the case you explained where the fragment is called when in the backstack), but can you please tell me if there is a guarantee I will still be getting onSavedInstanceState()
called when the fragment goes in background or has a config change?
Description
Component used: Fragment
Version used: 1.2.5
Devices/Android versions reproduced on:
This issue is not reproducible 100% and was reported as Crash Reports on Google Play - on local devices and normal scenarios this does not happen (e.g. put Application in Foreground and Background).
Current exception:
The implementation and usage of view binding is very simple and follows Android guidelines:
I'm getting a
NullPointerException
inonSaveInstanceState()
as thebinding
isnull
as this was called afteronDestroyView()
(or beforeonCreateView()
).