Fix Android FlyoutPage crash when changing orientation of tablet #24394
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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
Description of Change
Issues Fixed
Fixes #18161