-
Notifications
You must be signed in to change notification settings - Fork 409
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
Fix statusBar color changes on modal pages #2413
base: main
Are you sure you want to change the base?
Conversation
src/CommunityToolkit.Maui/Services/DialogFragmentService.android.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (2)
src/CommunityToolkit.Maui/Services/DialogFragmentService.android.cs:73
- The use of Debug.Assert might not be appropriate for production code. Consider using explicit error handling instead.
Debug.Assert(dialog is not null);
src/CommunityToolkit.Maui/Services/DialogFragmentService.android.cs:136
- The method IsDialogFragment could be more explicit in its error handling. Consider adding more descriptive error messages.
static bool IsDialogFragment(Fragment fragment, [NotNullWhen(true)] out DialogFragment? dialogFragment)
src/CommunityToolkit.Maui/Services/DialogFragmentService.android.cs
Outdated
Show resolved
Hide resolved
Thanks Pedro! Is there any reason to keep the previous implementation? I saw that you implemented it under a feature flag to give devs the option to opt-out. Would it be cool if we just ripped out the old code? Or is there a known-issue where devs would want to fall back to the previous implementation? |
@brminnick, we should keep both implementations, this PR adds support for Modal pages in Android maui apps. Our code for status bar looks for Let me give the full context, so it will be clear why this is needed For .NET 9 Shane and I worked to migrate all modal navigations to use MCT wasn't the only package that has problem with this change, I saw that Mpopups and a bottomSheet lib also faced issues due to this change in .NET Maui, and I believe we can face other issues in the future, like for our Popup implementation. So, we land on this PR, where I choose to create a proxy for the Now answering your questions:
Yes, because the old code handles all scenarios but Modal navigation. Sadly, there's not out of the box way to know if there's a
The idea of having it as a feature flag, is to give more power to devs. Right now, our implementation just handles StatusBarColor, but in their apps they want to work around/fix issues on other packages, so they can implement the interface and have full control over all Android Modal Navigation aspects. Let me know if you've any question or consideration |
Thanks Pedro!! Yup - that makes perfect sense. FYI - I tweaked some of the naming and moved all of the code to Could you open a Docs PR documenting this new option and include an example for devs who are interested in expanding upon our implementation? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 6 out of 8 changed files in this pull request and generated no comments.
Files not reviewed (2)
- src/CommunityToolkit.Maui.Core/AppBuilderExtensions.shared.cs: Evaluated as low risk
- src/CommunityToolkit.Maui.Core/Interfaces/IDialogFragmentService.android.cs: Evaluated as low risk
Comments suppressed due to low confidence (1)
src/CommunityToolkit.Maui.Core/Services/DialogFragmentService.android.cs:70
- [nitpick] The error message 'Dialog window cannot be null' could be more descriptive. Consider changing it to 'Dialog window cannot be null. Ensure that the dialog fragment is properly initialized and attached to a window.'
throw new InvalidOperationException("Dialog window cannot be null");
var window = dialog.Window; | ||
if (dialogFragment.Dialog?.Window is not Window dialogWindow) | ||
{ | ||
throw new InvalidOperationException("Dialog window cannot be null"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@brminnick we shouldn't throw here, since there's no way for devs to catch this exception. I used Debug.Assert
because it's what the runtime/sdk uses to safe check for null . But here you're checking against a type which can be false and throw this exception.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Debug.Assert()
is a bit of an anti-pattern because it only works when building in Debug configuration:
Debug.Assert method works only in debug builds.
This means that when users consume our library and the value of dialog.Window
is null
, the following code in Release builds is guaranteed to throw an unhelpful NullReferenceException
:
Debug.Assert(dialog is not null);
Debug.Assert(dialog.Window is not null);
var window = dialog.Window;
In what scenario would this code be executed called and dialog.Window
also be null? If this scenario exists, I agree that we should implement a solution.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think just returning is enough, the only scenario I can imagine that will happening is when the app is backgrounded or is moving into background.
@brminnick I added the implementation outside |
Is this documented? I don't recall setting this rule when I created CONTRIBUTING.md only includes one rule, that new code belongs in I'll add the |
@brminnick , I would love to join, let me see here and I'll confirm with you and team on discord |
Description of Change
Created and register new service for handle the DialogFragment (Modal pages on Android).
Linked Issues
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information