dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.28k stars 1.76k forks source link

Android crashing when rotating a flyout page #24779

Open Brosten opened 2 months ago

Brosten commented 2 months ago

Description

I'm opening a new issue on this topic, since the existing once are incorrectly closed.

I use a flyout page and when rotating the screen, ~1 time out of 10 the app crashes. The error message is something like: androidx.drawerlayout.widget.DrawerLayout.getDrawerViewAbsoluteGravity java.lang.ClassCastException: androidx.appcompat.widget.LinearLayoutCompat$LayoutParams cannot be cast to androidx.drawerlayout.widget.DrawerLayout$LayoutParams

Other similar, closed reports: https://github.com/dotnet/maui/issues/20858 https://github.com/dotnet/maui/issues/18161

Steps to Reproduce

  1. Create a maui project with a flyout page
  2. On details page, put some random content (e.g. I added 50 lables within a VerticalStackLayout).
  3. Rotate the screen a bit back and fourth. Eventually, the app will crash with the above error, or something similar.

Link to public reproduction project repository

No response

Version with bug

8.0.82 SR8.2

Is this a regression from previous behavior?

Yes, this used to work in Xamarin.Forms

Last version that worked well

Unknown/Other

Affected platforms

Android

Affected platform versions

All versions, what I know of

Did you find any workaround?

From what I found, setting FlyoutLayoutBehavior = FlyoutLayoutBehavior.Popover; seems to prevent the crashes. But you also loose the visible flyout that can be nice to have, at least on landscape tablets.

Relevant log output

androidx.drawerlayout.widget.DrawerLayout.getDrawerViewAbsoluteGravity DrawerLayout.java:991
androidx.drawerlayout.widget.DrawerLayout.checkDrawerViewAbsoluteGravity DrawerLayout.java:996
androidx.drawerlayout.widget.DrawerLayout$ViewDragCallback.onViewPositionChanged DrawerLayout.java:2292
androidx.customview.widget.ViewDragHelper.continueSettling ViewDragHelper.java:779
androidx.drawerlayout.widget.DrawerLayout.computeScroll DrawerLayout.java:1375
android.view.View.updateDisplayListIfDirty View.java:24009
android.view.View.draw View.java:24907
android.view.ViewGroup.drawChild ViewGroup.java:4780
android.view.ViewGroup.dispatchDraw ViewGroup.java:4538
android.view.View.updateDisplayListIfDirty View.java:24022
android.view.View.draw View.java:24907
android.view.ViewGroup.drawChild ViewGroup.java:4780
android.view.ViewGroup.dispatchDraw ViewGroup.java:4538
android.view.View.updateDisplayListIfDirty View.java:24022
android.view.View.draw View.java:24907
android.view.ViewGroup.drawChild ViewGroup.java:4780
android.view.ViewGroup.dispatchDraw ViewGroup.java:4538
android.view.View.updateDisplayListIfDirty View.java:24022
android.view.View.draw View.java:24907
android.view.ViewGroup.drawChild ViewGroup.java:4780
android.view.ViewGroup.dispatchDraw ViewGroup.java:4538
android.view.View.updateDisplayListIfDirty View.java:24022
android.view.View.draw View.java:24907
android.view.ViewGroup.drawChild ViewGroup.java:4780
android.view.ViewGroup.dispatchDraw ViewGroup.java:4538
android.view.View.updateDisplayListIfDirty View.java:24022
android.view.View.draw View.java:24907
android.view.ViewGroup.drawChild ViewGroup.java:4780
android.view.ViewGroup.dispatchDraw ViewGroup.java:4538
com.android.internal.policy.DecorView.dispatchDraw DecorView.java:1179
android.view.View.draw View.java:25180
com.android.internal.policy.DecorView.draw DecorView.java:1161
android.view.View.updateDisplayListIfDirty View.java:24036
android.view.ThreadedRenderer.updateViewTreeDisplayList ThreadedRenderer.java:768
android.view.ThreadedRenderer.updateRootDisplayList ThreadedRenderer.java:774
android.view.ThreadedRenderer.draw ThreadedRenderer.java:872
android.view.ViewRootImpl.draw ViewRootImpl.java:6051
android.view.ViewRootImpl.performDraw ViewRootImpl.java:5706
android.view.ViewRootImpl.performTraversals ViewRootImpl.java:4795
android.view.ViewRootImpl.doTraversal ViewRootImpl.java:3288
android.view.ViewRootImpl$TraversalRunnable.run ViewRootImpl.java:11344
android.view.Choreographer$CallbackRecord.run Choreographer.java:1689
android.view.Choreographer$CallbackRecord.run Choreographer.java:1698
android.view.Choreographer.doCallbacks Choreographer.java:1153
android.view.Choreographer.doFrame Choreographer.java:1079
android.view.Choreographer$FrameDisplayEventReceiver.run Choreographer.java:1646
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
github-actions[bot] commented 2 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one and thumbs upping the other issue to help us prioritize it. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

jaosnz-rep commented 2 months ago

@Brosten I tried to verify the issue but it didn't reproduce. Can you share a sample project with us so I can investigate further? Looking forward to your reply!

Brosten commented 2 months ago

@jaosnz-rep: Sure, her's a repo. RotationCrash.zip

I run this on an android tablet emulator, running Android 14 (API 34) After rapidly rotating the screen in random directions, it crashes after 5-10 rotations.

jaosnz-rep commented 2 months ago

I can repro this issue at Android platform on the latest 17.12.0 Preview 2.0 (8.0.90 & 8.0.82& 8.0.80).

kped1 commented 1 week ago

Is there any known workaround for this? It is affecting many of our users. I tried forcing the orientation to landscape on Android Tablet (RequestedOrientation = ScreenOrientation.Landscape;) however some users still experience the crash (on devices Galaxy Tab Active2, Galaxy Tab Active3, Galaxy Z Fold6)