Skip to content

Make iOS StatusBarBehavior more robust and not throw exceptions#2128

Merged
TheCodeTraveler merged 3 commits into
mainfrom
better-ios-statusbar
Aug 18, 2024
Merged

Make iOS StatusBarBehavior more robust and not throw exceptions#2128
TheCodeTraveler merged 3 commits into
mainfrom
better-ios-statusbar

Conversation

@jfversluis
Copy link
Copy Markdown
Member

Description of Change

While working on a Blazor Hybrid project I implemented the StatusBarBehavior. I also added the new way of setting the root page for a .NET MAUI app by not using MainPage (also see #2054)

I ran into an issue that when setting the status bar color from XAML, I would get an exception. Probably due to the fact that the window isn't created yet, but the page is being created that wants to set the status bar.

To be ahead of the curve for this new change in .NET MAUI, I adapted this code a little so that it doesn't thrown an exception but handles it more gracefully. The actual functionality still seems to work fine.

pictos
pictos previously approved these changes Aug 18, 2024
Since it it no longer guaranteed that the status bar will update we will prepend the method name with `Try` and return a `bool` noting its success.

We will also print to `Trace.WriteLine` the status when it fails
Copy link
Copy Markdown
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 Gerald!

Just FYI - I fixed a bug on the StatusBarBehavior page. The min/max values were incorrect, causing StatusBarColor to always return [Color: Red=1, Green=1, Blue=1, Alpha=1] instead of the actual color requested by the sliders.

I also renamed UpdateStatusBarAppearance to TryUpdateStatusBarAppearance since it is no longer guaranteed that the method will succeed. And I have it now print to Trace.WriteLine when it fails.

@TheCodeTraveler TheCodeTraveler enabled auto-merge (squash) August 18, 2024 21:21
@TheCodeTraveler TheCodeTraveler merged commit 9cabfd1 into main Aug 18, 2024
@TheCodeTraveler TheCodeTraveler deleted the better-ios-statusbar branch August 18, 2024 21:35
@github-actions github-actions Bot locked and limited conversation to collaborators Nov 18, 2024
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.

3 participants