Status Update
Comments
il...@google.com <il...@google.com>
hu...@google.com <hu...@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
ri...@gmail.com <ri...@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
ta...@gmail.com <ta...@gmail.com> #4
ta...@gmail.com <ta...@gmail.com> #5
```
java.lang.RuntimeException: Unable to resume activity {com.wayfair.waystation.debug.test/androidx.test.core.app.InstrumentationActivityInvoker$BootstrapActivity}: android.content.ActivityNotFoundException: No Activity found to handle null
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3784)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3816)
at android.app.servertransaction.ResumeActivityItem.execute(ResumeActivityItem.java:51)
at android.app.servertransaction.TransactionExecutor.executeLifecycleState(TransactionExecutor.java:145)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:70)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
Caused by: android.content.ActivityNotFoundException: No Activity found to handle null
```
ta...@gmail.com <ta...@gmail.com> #6
debugImplementation("androidx.fragment:fragment-testing:$version") {
exclude group: 'androidx.test'
} // debug since it adds a fake Activity
Description
Regarding the gradle dependency, it would be nice to clarify why "debugImplementation" is required, instead of the normal "testImplementation" instruction.
Ian Lake mentioned that "is required since you need the EmptyFragmentActivity that FragmentScenario relies on to be in the test target process". That brings me to another question, regarding Fragment Communication (
Is there a workaround? Or you're recommending everyone to move into ViewModels and communicate using shared view models?
(hope that was not very confusing^^)
---
Another question remained after reading the documentation, related to the fragment state:
If you call:
scenario = launchFragmentInContainer<MyFragment>()
>> FragmentScenario drives the fragment under test to the RESUMED state.
Then you mention that
>> To drive the fragment to a different lifecycle state, call moveToState()
So if we call:
val scenario = launchFragmentInContainer<MyFragment>()
scenario.moveToState(State.CREATED)
Does that mean, the fragment goes first to RESUMED state (upon calling launchFragment*), and then goes back to the CREATED state?
I reckon it would be helpful to just launch the fragment in the CREATED state.
---
If I misread the documentation and this post makes little sense, apologies in advance.
Cheers,
Ricardo