-
Notifications
You must be signed in to change notification settings - Fork 495
Add Support for StatusBarBehavior in Android Modal Page
#3123
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
Changes from all commits
b14025f
286b267
c3c7306
ac477de
88e0956
dc669f7
672dd76
9b09d52
5f7db2d
bb68654
cfd07ef
6d110fd
6e6fcd4
a2c1784
80e8d04
645029e
8e10c72
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -35,57 +35,58 @@ static void PlatformSetColor(Color color) | |
| return; | ||
| } | ||
|
|
||
| if (Activity.Window is not null) | ||
| if (Activity.GetCurrentWindow() is not Window { DecorView.RootView: not null } window) | ||
| { | ||
| var platformColor = color.ToPlatform(); | ||
| return; | ||
| } | ||
|
TheCodeTraveler marked this conversation as resolved.
|
||
|
|
||
| if (OperatingSystem.IsAndroidVersionAtLeast(35)) | ||
| { | ||
| const string statusBarOverlayTag = "StatusBarOverlay"; | ||
| var platformColor = color.ToPlatform(); | ||
|
|
||
| var window = Activity.GetCurrentWindow(); | ||
| if (OperatingSystem.IsAndroidVersionAtLeast(35)) | ||
| { | ||
| const string statusBarOverlayTag = "StatusBarOverlay"; | ||
|
|
||
| var decorGroup = (ViewGroup)window.DecorView; | ||
| var statusBarOverlay = decorGroup.FindViewWithTag(statusBarOverlayTag); | ||
| var decorGroup = (ViewGroup)window.DecorView.RootView; | ||
|
TheCodeTraveler marked this conversation as resolved.
|
||
| var statusBarOverlay = decorGroup.FindViewWithTag(statusBarOverlayTag); | ||
|
TheCodeTraveler marked this conversation as resolved.
|
||
|
|
||
| if (statusBarOverlay is null) | ||
| { | ||
| var statusBarHeight = Activity.Resources?.GetIdentifier("status_bar_height", "dimen", "android") ?? 0; | ||
| var statusBarPixelSize = statusBarHeight > 0 ? Activity.Resources?.GetDimensionPixelSize(statusBarHeight) ?? 0 : 0; | ||
| if (statusBarOverlay is null) | ||
| { | ||
| var statusBarHeight = Activity.Resources?.GetIdentifier("status_bar_height", "dimen", "android") ?? 0; | ||
| var statusBarPixelSize = statusBarHeight > 0 ? Activity.Resources?.GetDimensionPixelSize(statusBarHeight) ?? 0 : 0; | ||
|
|
||
| statusBarOverlay = new(Activity) | ||
| statusBarOverlay = new(Activity) | ||
| { | ||
| LayoutParameters = new FrameLayout.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, statusBarPixelSize + 3) | ||
| { | ||
| LayoutParameters = new FrameLayout.LayoutParams(Android.Views.ViewGroup.LayoutParams.MatchParent, statusBarPixelSize + 3) | ||
| { | ||
| Gravity = GravityFlags.Top | ||
| } | ||
| }; | ||
|
|
||
| decorGroup.AddView(statusBarOverlay); | ||
| statusBarOverlay.SetZ(0); | ||
| } | ||
| Gravity = GravityFlags.Top | ||
| } | ||
| }; | ||
|
|
||
|
TheCodeTraveler marked this conversation as resolved.
|
||
| statusBarOverlay.SetBackgroundColor(platformColor); | ||
| } | ||
| else | ||
| { | ||
| Activity.Window.SetStatusBarColor(platformColor); | ||
| statusBarOverlay.Tag = statusBarOverlayTag; | ||
| decorGroup.AddView(statusBarOverlay); | ||
| statusBarOverlay.SetZ(0); | ||
| } | ||
|
|
||
| bool isColorTransparent = platformColor == PlatformColor.Transparent; | ||
| if (isColorTransparent) | ||
| { | ||
| Activity.Window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| Activity.Window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits); | ||
| } | ||
| else | ||
| { | ||
| Activity.Window.ClearFlags(WindowManagerFlags.LayoutNoLimits); | ||
| Activity.Window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| } | ||
| statusBarOverlay.SetBackgroundColor(platformColor); | ||
| } | ||
| else | ||
| { | ||
| window.SetStatusBarColor(platformColor); | ||
| } | ||
|
|
||
| WindowCompat.SetDecorFitsSystemWindows(Activity.Window, !isColorTransparent); | ||
| bool isColorTransparent = platformColor == PlatformColor.Transparent; | ||
| if (isColorTransparent) | ||
| { | ||
| window.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know any other way to deal with issue of status bar transparency but settings and clearing flags can and will interfere with developers attempts to set or use full screen and in a test app I had to remove all the settings and clearing of flags to have my app do what I wanted. I removed it throughout the toolkit where I found it in statusbar. I am not sure what we should do here. This is more a comment about the current state of the behavior of hiding/showing status bar is a complicated mess atm and depending on API level settings these options will have completely different behavior on each API. I do not advocate ripping out the flags I am simply stating all of my use cases do require it. It would have significant impact on all API below 36 so I am not suggesting we do that. Just maybe add checks and block the changes for android 36? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might be a good idea to add full-screen mode to CommunityToolkit.Maui so it doesn't interfere with the color change. We could also use an IsVisible boolean on the status bar and navigation bar.
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @IgrisModz sure! What specifically do we need to add? Do you have any links to documentation you could share? |
||
| window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits); | ||
| } | ||
| else | ||
| { | ||
| window.ClearFlags(WindowManagerFlags.LayoutNoLimits); | ||
| window.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| } | ||
|
|
||
| WindowCompat.SetDecorFitsSystemWindows(window, !isColorTransparent); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is deprecated on Android API 36. It is highly recommended that we add a check and only use it on an OS using a lower API. |
||
| } | ||
|
|
||
| static void PlatformSetStyle(StatusBarStyle style) | ||
|
|
@@ -98,23 +99,23 @@ static void PlatformSetStyle(StatusBarStyle style) | |
| switch (style) | ||
| { | ||
| case StatusBarStyle.DarkContent: | ||
| SetStatusBarAppearance(Activity, true); | ||
| SetStatusBarAppearance(true); | ||
| break; | ||
|
|
||
| case StatusBarStyle.Default: | ||
| case StatusBarStyle.LightContent: | ||
| SetStatusBarAppearance(Activity, false); | ||
| SetStatusBarAppearance(false); | ||
| break; | ||
|
|
||
| default: | ||
| throw new NotSupportedException($"{nameof(StatusBarStyle)} {style} is not yet supported on Android"); | ||
| } | ||
| } | ||
|
|
||
| static void SetStatusBarAppearance(Activity activity, bool isLightStatusBars) | ||
| static void SetStatusBarAppearance(bool isLightStatusBars) | ||
| { | ||
| var window = activity.GetCurrentWindow(); | ||
| if (WindowCompat.GetInsetsController(window, window.DecorView) is WindowInsetsControllerCompat windowController) | ||
| if (Activity.GetCurrentWindow() is Window window | ||
| && WindowCompat.GetInsetsController(window, window.DecorView) is WindowInsetsControllerCompat windowController) | ||
| { | ||
| windowController.AppearanceLightStatusBars = isLightStatusBars; | ||
| } | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.