Maui
Maui copied to clipboard
[BUG] Setting StatusBarBehavior breaks it on iOS in landscape mode
Is there an existing issue for this?
- [X] I have searched the existing issues
Did you read the "Reporting a bug" section on Contributing file?
- [X] I have read the "Reporting a bug" section on Contributing file: https://github.com/CommunityToolkit/Maui/blob/main/CONTRIBUTING.md#reporting-a-bug
Current Behavior
When setting a ContentPage's StatusBarBehavior on a page like this:
<ContentPage.Behaviors>
<toolkit:StatusBarBehavior StatusBarColor="{StaticResource Primary}" StatusBarStyle="LightContent" />
</ContentPage.Behaviors>
Navigating to another page and turn the phone to landscape mode, the result is this:
However, after navigating to another page that has the StatusBarBehavior setting, there is no problem:
Expected Behavior
The StatusBarBehaviour should be needed to set one time only, and have no issue after navigating from the page it has set on.
Steps To Reproduce
Please find it in my repository
Link to public reproduction project repository
https://github.com/RsZoli/GitHubRepros
Environment
- .NET MAUI CommunityToolkit: 7.0.1
- OS: iOS 16.7.5, iOS 17.3.1
- .NET MAUI: 8.0.6
Anything else?
No response
Debugging this in my head I suspect the SizeChanged event isn't firing from the page when the orientation changes. I wonder if that is a change in MAUI?
@RsZoli Are you able to subscribe to the SizeChanged event in your page, change the orientation and see if it fires?
@bijington I have tried it, it does fire! On appearing and on orientation changing as well!
@RsZoli I have tested this issue as part of the PR here: https://github.com/CommunityToolkit/Maui/pull/1471 and it appears to work. Interestingly I see a status bar in landscape mode though. What iPad are you testing on?
@bijington I'm testing only on iPhones.
Is this still an issue on version 8 of the community toolkit? I'm also seeing this behavior on .net7 with version 6.1 of this package, so it doesn't appear to be a new issue to version 7.0.1 of the package.
I am using version 9.0.0 of the CommunityToolkit.Maui package and am also experiencing this issue.
My app is using MAUI Blazor Hybrid and once I change the status bar color on iOS, if I change to landscape mode, then I get the same reported behavior of where there is a colored rectangle at the top of the page that takes up about 45% of the width of the page. When the device rotates to a vertical orientation the issue goes away and when I rotate back to a horizontal orientation the issue appears again.
Here is an example of how I'm changing the status bar:
CommunityToolkit.Maui.Core.Platform.StatusBar.SetColor(Colors.Red);
CommunityToolkit.Maui.Core.Platform.StatusBar.SetStyle(StatusBarStyle.LightContent);
I was able fix the issue by subscribing to display info changes and calling StatusBar.UpdateBarSize
like so:
#if IOS
DeviceDisplay.Current.MainDisplayInfoChanged += (sender, e) =>
{
CommunityToolkit.Maui.Core.Platform.StatusBar.UpdateBarSize();
};
#endif
Some form of the above code should be incorporated into this library to fix the issue.