Status Update
Comments
al...@gmail.com <al...@gmail.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
al...@gmail.com <al...@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
ag...@gmail.com <ag...@gmail.com> #4
lc...@gmail.com <lc...@gmail.com> #7
i have encoutered a similiar issue where popbackstack would frequently not work, and eventually leading to IllegalStateException: Fragment already added
.
The weird thing is using the back gesture will work, but invoking findNavController().popBackStack()
will often times not do anything and sometimes the fragment will get popped but the UI remains unchanged.
All these issues went away when i disabled predictive back via android:enableOnBackInvokedCallback="false
.
using fragment 1.8.3 and navigation 2.8.0 on Android 14
pa...@gmail.com <pa...@gmail.com> #8
dk...@3cx.com <dk...@3cx.com> #9
Facing the same issue on Android 14 with fragment 1.8.2 & navigation 2.7.7 when switching fast between several fragments via NavController.navigate
.
The navigation rule in the nav_graph.xml for each fragment is like this:
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/nav_graph"
app:startDestination="@id/splashFragment">
...
<action
android:id="@+id/switchToSomething"
app:destination="@id/someFragment"
app:popUpTo="@+id/dialerFragment"
app:popUpToInclusive="false" />
...
</navigation>
Fatal Exception: java.lang.IllegalStateException
Fragment already added: DialerFragment{...} (....)
androidx.fragment.app.FragmentStore.addFragment (FragmentStore.java:93)
androidx.fragment.app.FragmentManager.addFragment (FragmentManager.java:1723)
androidx.fragment.app.BackStackRecord.executePopOps (BackStackRecord.java:448)
androidx.fragment.app.FragmentManager.executeOps (FragmentManager.java:2227)
androidx.fragment.app.FragmentManager.executeOpsTogether (FragmentManager.java:2115)
androidx.fragment.app.FragmentManager.removeRedundantOperationsAndExecute (FragmentManager.java:2065)
androidx.fragment.app.FragmentManager.execPendingActions (FragmentManager.java:2002)
androidx.fragment.app.FragmentManager$5.run (FragmentManager.java:702)
android.os.Handler.handleCallback (Handler.java:958)
android.os.Handler.dispatchMessage (Handler.java:99)
android.os.Looper.loopOnce (Looper.java:230)
android.os.Looper.loop (Looper.java:319)
android.app.ActivityThread.main (ActivityThread.java:8919)
java.lang.reflect.Method.invoke (Method.java)
com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run (RuntimeInit.java:578)
com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1103)
Description
Component used: Navigation
Version used: 2.7.7, 2.8.0-alpha08
Devices/Android versions reproduced on: Pixel 6a, Android 14
The latest release and alpha versions of the navigation component depend on androidx-fragment 1.6.2. Updating androidx-fragment to 1.7.0 causes navigation to crash and display other undesired behavior.
Sample project:https://drive.google.com/open?id=1J88xhvdPozKLeSIigNIpN2p9lc8APK0Y&authuser=0
Steps to reproduce with the sample project: Tap the icon in the top left to navigate between the "Home" and "Settings" fragments. Before long, the icon stops actually navigating between fragments, and/or the app crashes.
Screen recording:https://drive.google.com/open?id=1BfX7wczN5mQvQZY4DChB34GbhuaLneoR&authuser=0
The crash is usually caused by one of two exceptions: