-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Toggling FlyoutLayoutBehavior on Android causes the app to crash #18161
Comments
We've added this issue to our backlog, and we will work to address it as time and resources allow. If you have any additional information or questions about this issue, please leave a comment. For additional info about issue management, please read our Triage Process. |
any updates on this? Facing same issue with a very simple flyout behaviour. |
Error probably not fixed as written just above.
After changing the orientation of the tablet, exactly the same error occurs (same stack but with different line numbers) |
I've created a minimal MAUI 8.0.80 app with a Flyoutpage. All test are done on a physical tablet. When considering the FlyoutPageRenderer of Xamarin (was working perfectly) https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.Android/AppCompat/FlyoutPageRenderer.cs I notice in the code 2 hacks with await Task.Delay(100); There is no such code in the MAUI FlyoutViewHandler https://github.com/dotnet/maui/blob/main/src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Android.cs I don't know if it is related. The reality however is that it is impossible to release an app on a tablet that crashes when you change the orientation. |
After investigations, it appears the root cause of this problem is in Maui-main\src\Essentials\src\DeviceDisplay\DeviceDisplay.android.cs
The code is awaiting half a second (why so long?) but if in the interval another rotation occurs, the FlyoutPage enter in race conditions. This is not an acceptable solution but if I replace OnOrientationChanged by this code, the error does not occur anymore. And it solves other errors like split mode visible in portrait.
Hoping this will help someone to provide a real solution. |
Switch from landscape to portrait, and from portrait to landscape repeatedly produces this error: androidx.appcompat.widget.LinearLayoutCompat$LayoutParams cannot be cast to androidx.drawerlayout.widget.DrawerLayout$LayoutParams The root cause is in the OnOrientationChanged implementation in Android that awaits 0.5 second and creates race conditions if the orientation changes again during this interval. dotnet#18161
Fix proposed: main...guyvaio:maui:patch-1 |
On an Android tablet, switching from landscape to portrait, and from portrait to landscape repeatedly produces this error: androidx.appcompat.widget.LinearLayoutCompat$LayoutParams cannot be cast to androidx.drawerlayout.widget.DrawerLayout$LayoutParams This error can be easily reproduced on a physical tablet by quickly changing orientation. dotnet#18161 The change of orientation triggers method UpdateFlyoutBehavior of src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Android.cs, that calls method LayoutViews to determine if the views are to be created in “side by side” mode or “as flyout”. The problem is after the rotation, DrawerLayout.GetPlatformViewBounds() called (for investigation) in this method shows that the Android view still has the height/width before the rotation. The MAUI code is ahead of the android reality. Waiting 100ms is enough to let Android adapt its interface. A similar issue had been addressed by Xamarin developers: the comment on line 324 of https://github.com/xamarin/Xamarin.Forms/blob/5.0.0/Xamarin.Forms.Platform.Android/AppCompat/FlyoutPageRenderer.cs is //hack : when the orientation changes and we try to close the Flyout on Android //sometimes Android picks the width of the screen previous to the rotation
Will this make it to SR9? |
Temporary fix https://gist.github.com/guyvaio/5ca11a6aa373c1fe486cc9e25137aeec |
Why is this issue closed? I see no open issue addressing it. The crash is rather easy to reproduce with latest MAUI. |
I am also still experiencing this issue on an Android tablet using the latest .NET 8 and 8.0.82 maui compatibility packages. |
Description
Toggling the FlyoutLayoutBehavior property on a Flyout page on Android causes the app to crash. The problem occurs in .NET 8 SR1 and SR2, and this problem also existed in .NET 7.
Steps to Reproduce
Link to public reproduction project repository
https://github.com/mjo151/maui-flyout-behavior-bug
Version with bug
8.0.0-rc.1.9171
Is this a regression from previous behavior?
No, this is something new
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 13 (did not test other Android versions)
Did you find any workaround?
I did not find a workaround for this issue.
Relevant log output
The text was updated successfully, but these errors were encountered: