maui: Status bar transparency doesn't work for Modal Pages
Description
just for the record I created an issue before and it was closed and moved to discussions as it would be like just a QA, but it’s not its just a bug in Maui.
So i want to show a modal page using Navigation.PushModalAsync(new MyPage()); and i need this to be overlayed on Status Bar for android (i didn’t test it on iOS), meaning the status bar should be transparent, i use this code:
events.AddAndroid(android => android.OnCreate((activity, bundle) => MakeStatusBarTranslucent(activity)));
static void MakeStatusBarTranslucent(Android.App.Activity activity)
{
activity.Window.SetFlags(Android.Views.WindowManagerFlags.LayoutNoLimits, Android.Views.WindowManagerFlags.LayoutNoLimits);
activity.Window.ClearFlags(Android.Views.WindowManagerFlags.TranslucentStatus);
activity.Window.SetStatusBarColor(Android.Graphics.Color.Transparent);
}
this works perfectly fine for MainPage, but for modal pages it wont make any difference and the modal pages start right below of status bar which is not desired behaviour. let me just show some screenshots to make myself clear:
this is Main Page which is behaving as my desire:
but this is a modal page, which is not working as expected, it’s below of status bar:
so seems like another guy has the same problem and he described his investigation quite clearly, thanks to @johannes-keinestam we now have a clue where the bug might be, and i just quote his words:
I’m having the exact same problem. It’s kind of an issue that the contents of the modal page can’t extend under the status bar. We push both NavigationPages (with toolbars) as well as plain ContentPages when we want to give an “edge-to-edge” feel to the app, but now when migrating from Xamarin.Forms this hasn’t been possible and quite severely affects the look of our app to the degree that we feel we cannot ship it until this has been resolved.
From what I can tell, the offending code is here: https://github.com/dotnet/maui/blob/d7a37e37333c0739f0ca360dd773423a807d251c/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs#L333 Here it uses the top inset of the status bar (“IgnoringVisibility”, which I take to mean it will completely disregard that we’ve set SetDecorFitsSystemWindows to false and added the WindowManagerFlags.TranslucentNavigation flag on the Window). Unfortunately, since everything is marked internal and non-virtual in that file, there seems to be no hacking around this.
I’ve tried a few hacky solutions, to see if I could change the behavior here: https://github.com/dotnet/maui/blob/d7a37e37333c0739f0ca360dd773423a807d251c/src/Controls/src/Core/Platform/ModalNavigationManager/ModalNavigationManager.Android.cs#L325 I could get the ModalContainer instance by just looping until I found the right parent view (matching on GetType().Name.Contains("ModalContainer") since, again, everything is internal…), and with this I tried setting its LayoutParameters property to a non-ViewGroup.MarginLayoutParams instance so that the margin is never set. This causes a crash, since some Java code somewhere expects that the LayoutParameters is a subtype of FrameLayout.LayoutParams. Creating my own subclass of FrameLayout.LayoutParams and assigning an instance of that to the property doesn’t help because the TopMargin property isn’t virtual either, so there’s no way of modifying its behavior (by e.g. always returning 0 in the getter).
Seems like we might be out of luck here for now…
_Originally posted by @johannes-keinestam in https://github.com/dotnet/maui/discussions/17759#discussioncomment-7241847_
END OF QUOTE
Steps to Reproduce
No response
Link to public reproduction project repository
No response
Version with bug
7.0.96
Is this a regression from previous behavior?
Not sure, did not test other versions
Last version that worked well
Unknown/Other
Affected platforms
Android
Affected platform versions
Android 8.0 and 12.0
Did you find any workaround?
No response
Relevant log output
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 10
- Comments: 15 (2 by maintainers)
Yes this is a really big issue for me as well. We ported a Xamarin.Forms App to Maui which uses a lot of modal pages and all of them have this issue. On IOS you can simply set a parameter on the pages to make it fell the screen (this works but is also needlessly complicated) but on android everything just looks off and horrible.
This also has an impact on the screen borders. On Android we need to set a bottom margin on these pages which pushes the content up by the size of the status bar in the top, to make the content at least fit properly but all pages still look bad because of the space in the top. Since this was not an issue in Xamarin I feel like this should be a priority to fix it fast because it screws up some App’s flow completely.
any update on this guys? or at least any workaround?