Skip to content

Conversation

@kubaflo
Copy link
Contributor

@kubaflo kubaflo commented Oct 30, 2024

Description of Change

I've encountered this bug while working with MAUI: dotnet/maui#24972 and it turns out that it is rather an issue that should be linked to this repository.

Basically the status bar is wrong for some screens. I've found this comments here: https://forums.developer.apple.com/forums/thread/662466

Screenshot 2024-10-30 at 19 33 40

It makes sense because when I based the status bar height on the top safe area I have the following result:

Expected Before After

Linked Issues

It might also fix this one: dotnet/maui#25435, but I'm not 100% sure if it is a status bar's or MAUI's issue. Maybe even both

PR Checklist

Additional information

pictos
pictos previously approved these changes Oct 30, 2024
Copy link
Member

@pictos pictos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@TheCodeTraveler
Copy link
Collaborator

TheCodeTraveler commented Oct 30, 2024

The StatusBar overlaps the navigation bar in the After photo.

To help visualize this, I've added a green bar in the photo below that is the same height as the NavigationBar. The green bar is the same height in both the Before and After image.

Screenshot 2024-10-30 at 11 56 09 AM

Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please link to a bug (or open a new Issue) in our GitHub repo to help us understand + reproduce the problem you are trying to fix.

Please also update edit the title of this PR; Improve status bar does not explain the bug or the proposed solution.

Please ensure the status bar does not overlap the navigation bar

Screenshot 2024-10-30 at 11 56 09 AM

@TheCodeTraveler TheCodeTraveler dismissed pictos’s stale review October 30, 2024 19:01

This PR increases the size of the StatusBar where it now overlaps the NavigationBar

@kubaflo
Copy link
Contributor Author

kubaflo commented Oct 30, 2024

Please link to a bug (or open a new Issue) in our GitHub repo to help us understand + reproduce the problem you are trying to fix.

Please also update edit the title of this PR; Improve status bar does not explain the bug or the proposed solution.

Please ensure the status bar does not overlap the navigation bar

Screenshot 2024-10-30 at 11 56 09 AM

Yea, but it is the iOS's native behaviour. Generally status bar should have the same color as the navigation bar. The only point for customising it is when we don't have a navigation bar. And the current MCT solution would give the following outcome:

Screenshot 2024-10-30 at 20 09 22

@Axemasta
Copy link
Contributor

Please link to a bug (or open a new Issue) in our GitHub repo to help us understand + reproduce the problem you are trying to fix.

This is the issue #2287, Originally I thought it was a maui issue but its not and actually a status bar behaviour issue, since the repro app doesn't apply the padding when not using the behavior

@kubaflo kubaflo changed the title [iOS] Improve status bar [iOS] StatusBarBehavior does not occupy entire notch for modal pages when NavigationPage.HasNavigationBar="False" - fix Oct 30, 2024
@kubaflo kubaflo changed the title [iOS] StatusBarBehavior does not occupy entire notch for modal pages when NavigationPage.HasNavigationBar="False" - fix [iOS] StatusBarBehavior does not occupy entire notch - fix Oct 30, 2024
@jfversluis
Copy link
Member

Another report of this bug: dotnet/maui#25435

Additionally I also ran into this myself while working on the https://github.com/jfversluis/blazor-hybrid-workshop

@kubaflo
Copy link
Contributor Author

kubaflo commented Nov 21, 2024

Hi! Any update concerning this PR?

@pictos
Copy link
Member

pictos commented Nov 21, 2024

@brminnick what do you think about @kubaflo's answer?

@TheCodeTraveler
Copy link
Collaborator

This is a tough one. Both the Community Toolkit and .NET MAUI are correctly using SafeAreaInserts. This appears to be how iOS has designed their operating system UI.

I've searched Apple's Human Interface Design Guidelines to learn more about their recommendations around the status bar and modality, but they don't provide any specific instructions.

Since this "bug" only seems to affect Modal Pages, my recommendation is to use PageSheet for modal all modal pages on iOS. I've provided the code here: #2287 (comment)

My vote is to close both this PR and the Issue as this is the design that Apple is pushing us developers into.

@TheCodeTraveler
Copy link
Collaborator

Hi! Any update concerning this PR?

To answer @kubaflo's question, we are blocked from merging any PRs until we are able to merge our .NET 9 PR which is currently blocked by a bug in .NET MAUI.

Once the MAUI engineering team resolves this bug, we will be unblocked and can resume merging PRs for the Community Toolkit: dotnet/maui#25871

@kubaflo
Copy link
Contributor Author

kubaflo commented Nov 22, 2024

Okay, @brminnick do whatever you think is the best :) But I don't think it happens only on modal pages, it happens on pages without a navigation bar

@Axemasta
Copy link
Contributor

Axemasta commented Jan 2, 2025

I'm thinking about this PR because I've just forked this behaviour and had to make this change as I can't live with the random line between my nav bar and notch and it got me thinking...

Should we add a toggle option for iOS to use the safe area:
statusBarBehavior.On<iOS>().UseSafeArea(true)

The default behavior would be to use the status bar frame, and the override would use the top of the safe area. This way we have a fix for this issue, which IS quite common. We don't force developers down the road of making all modals PageSheets (there are still some rough edges with using these in Maui...) and we keep the default implementation as is!

@brminnick thoughts?

@TheCodeTraveler TheCodeTraveler added the needs discussion Discuss it on the next Monthly standup label Jan 2, 2025
@TheCodeTraveler
Copy link
Collaborator

Should we add a toggle option for iOS to use the safe area:
statusBarBehavior.On().UseSafeArea(true)

@Axemasta That actually makes a lot of sense! Do you have a proof-of-concept with it working that I could dig into?

@Axemasta
Copy link
Contributor

Axemasta commented Jan 3, 2025

I've put together a proof of concept although to be totally honest I think adding a BindableProperty named iOSUseSafeArea might just be easier.

Proof of concept is here, annoyingly the IPlatformElementConfiguration generic is constrained to Element so we can apply one directly to our behavior. We can however apply the configuration to the element we apply our behavior to & read it from there...

For the proof of concept:

In the specific case of the StatusBarBehavior using this approach, our element config could apply to the page, so we would have an ios config such as mct:Page.StatusBarShouldUseSafeArea="true" in our xaml.

Looking at the current implementation of status bar, we'd probably want to pass the BindableObject reference through to the platform, so that the iOS platform code can lookup whether the user has opted into the feature flag and then apply:

if (StatusBarIosConfiguration.GetUseSafeArea(bindable))
{
	new CGRect(statusBar.Frame.X, statusBar.Frame.Y, statusBar.Frame.Width, window.SafeAreaInsets.Top);
}
else
{
	statusBar.Frame = UIApplication.SharedApplication.StatusBarFrame;
}

Adding a toggle to the page might be a bit confusing, I was hoping it wouldn't be as messy as it turned out to be (accounting for the Element constraint.

@TheCodeTraveler TheCodeTraveler removed the needs discussion Discuss it on the next Monthly standup label Jan 9, 2025
@jfversluis
Copy link
Member

@kubaflo @Axemasta as discussed yesterday on the .NET MAUI Community Toolkit standup, if we compare the behavior with the behavior of native iOS apps this seems to be correct.

Reading through this I think the suggestion by @Axemasta makes a lot of sense! Do we need a separate setting? Can't we just look at the .NET MAUI configured setting for this on the page that we're on and decide based on that? But I'm fine with adding a platform-specific setting for this too.

Can we make that happen? :)

@kubaflo kubaflo force-pushed the status-bar-improvement branch from 68e0ba2 to 589d13c Compare January 12, 2025 11:35
@kubaflo
Copy link
Contributor Author

kubaflo commented Jan 12, 2025

I've added

xmlns:ios="clr-namespace:CommunityToolkit.Maui.PlatformConfiguration.iOSSpecific;assembly=CommunityToolkit.Maui"
ios:StatusBar.UseSafeArea="True"

Let me know what you think :)

…etUseSafeArea`, Remove `CommunityToolkit.Maui.PlatformConfiguration.iOSSpecific.StatusBar`, Remove `OperatingSystem.IsIOSVersionAtLeast(13))` (Toolkit now supports iOS 15+)
Copy link
Collaborator

@TheCodeTraveler TheCodeTraveler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kubaflo! Approved

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) January 16, 2025 21:43
@TheCodeTraveler
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@TheCodeTraveler TheCodeTraveler merged commit 46fb9a2 into CommunityToolkit:main Jan 16, 2025
7 of 9 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Jan 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] StatusBarBehavior does not occupy entire notch for modal pages when NavigationPage.HasNavigationBar="False" (iOS)

5 participants