-
Notifications
You must be signed in to change notification settings - Fork 471
Fix statusBar color changes on modal pages #2413
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
Merged
Merged
Changes from 12 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
0630c5c
create services for DialogFragment
pictos 0a7d0c8
register the service on android during the builder phase
pictos 410fe31
move interface to Interfaces folder
pictos 2364d10
move services to CommunityToolkit.Maui
pictos 29aac74
add option to not use the default MCT impl
pictos 1e2142f
move the registration bits into to CommunityToolkit.Maui project
pictos 0e38c75
removed files
pictos b2fa42f
code cleanup
pictos 03eb3cf
add trace
pictos d7a53c7
remove debug assert
pictos 048a024
Update Naming
TheCodeTraveler 6704cd7
Move to `CommunityToolkit.Maui.Core`
TheCodeTraveler 5753c2d
`dotnet format`
TheCodeTraveler 6e45f20
`dotnet format`
TheCodeTraveler 4cdb611
Merge branch 'main' into pj/fix-status-bar-on-modal
TheCodeTraveler bcd13da
Merge branch 'main' into pj/fix-status-bar-on-modal
TheCodeTraveler c78e1ba
Promote to `public`
TheCodeTraveler d9145dd
Update CONTRIBUTING.md
TheCodeTraveler 1775a81
Add XML Comments
TheCodeTraveler 0462d85
Add `[EditorBrowsable(EditorBrowsableState.Never)]`
TheCodeTraveler b490d35
Merge branch 'main' into pj/fix-status-bar-on-modal
TheCodeTraveler 1752606
Merge branch 'pj/fix-status-bar-on-modal' of https://github.com/Commu…
TheCodeTraveler 6f4220c
Merge branch 'main' into pj/fix-status-bar-on-modal
TheCodeTraveler fd4c9c8
Merge branch 'main' into pj/fix-status-bar-on-modal
TheCodeTraveler 6c85020
Merge branch 'main' into pj/fix-status-bar-on-modal
TheCodeTraveler 1205dd6
Merge branch 'main' into pj/fix-status-bar-on-modal
jfversluis ae5a867
Merge branch 'main' into pj/fix-status-bar-on-modal
TheCodeTraveler b2e1019
Show it to the world
pictos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/CommunityToolkit.Maui.Core/Interfaces/IDialogFragmentService.android.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| using Android.Content; | ||
| using Android.Views; | ||
|
|
||
| namespace CommunityToolkit.Maui.Core; | ||
|
|
||
| public interface IDialogFragmentService | ||
| { | ||
| void OnFragmentAttached(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f, Context context); | ||
| void OnFragmentCreated(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f, Bundle? savedInstanceState); | ||
| void OnFragmentDestroyed(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f); | ||
| void OnFragmentDetached(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f); | ||
| void OnFragmentPaused(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f); | ||
| void OnFragmentPreAttached(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f, Context context); | ||
| void OnFragmentPreCreated(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f, Bundle? savedInstanceState); | ||
| void OnFragmentResumed(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f); | ||
| void OnFragmentSaveInstanceState(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f, Bundle outState); | ||
| void OnFragmentStarted(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f); | ||
| void OnFragmentStopped(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f); | ||
| void OnFragmentViewCreated(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f, View v, Bundle? savedInstanceState); | ||
| void OnFragmentViewDestroyed(AndroidX.Fragment.App.FragmentManager fm, AndroidX.Fragment.App.Fragment f); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
149 changes: 149 additions & 0 deletions
149
src/CommunityToolkit.Maui.Core/Services/DialogFragmentService.android.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,149 @@ | ||
| using System.Diagnostics.CodeAnalysis; | ||
| using Android.Content; | ||
| using Android.Views; | ||
| using AndroidX.AppCompat.App; | ||
| using DialogFragment = AndroidX.Fragment.App.DialogFragment; | ||
| using Fragment = AndroidX.Fragment.App.Fragment; | ||
| using FragmentManager = AndroidX.Fragment.App.FragmentManager; | ||
|
|
||
| namespace CommunityToolkit.Maui.Core.Services; | ||
|
|
||
| sealed partial class DialogFragmentService : IDialogFragmentService | ||
| { | ||
| public void OnFragmentAttached(FragmentManager fm, Fragment f, Context context) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentCreated(FragmentManager fm, Fragment f, Bundle? savedInstanceState) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentDestroyed(FragmentManager fm, Fragment f) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentDetached(FragmentManager fm, Fragment f) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentPaused(FragmentManager fm, Fragment f) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentPreAttached(FragmentManager fm, Fragment f, Context context) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentPreCreated(FragmentManager fm, Fragment f, Bundle? savedInstanceState) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentResumed(FragmentManager fm, Fragment f) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentSaveInstanceState(FragmentManager fm, Fragment f, Bundle outState) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentStarted(FragmentManager fm, Fragment f) | ||
| { | ||
| if (!TryConvertToDialogFragment(f, out var dialogFragment) || Microsoft.Maui.ApplicationModel.Platform.CurrentActivity is not AppCompatActivity activity) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| HandleStatusBarColor(dialogFragment, activity); | ||
| } | ||
|
|
||
| static void HandleStatusBarColor(DialogFragment dialogFragment, AppCompatActivity activity) | ||
| { | ||
| if (activity.Window is null) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var statusBarColor = activity.Window.StatusBarColor; | ||
| var platformColor = new Android.Graphics.Color(statusBarColor); | ||
| if (dialogFragment.Dialog?.Window is not Window dialogWindow) | ||
| { | ||
| throw new InvalidOperationException("Dialog window cannot be null"); | ||
| } | ||
|
|
||
| var isColorTransparent = platformColor == Android.Graphics.Color.Transparent; | ||
|
|
||
| if (OperatingSystem.IsAndroidVersionAtLeast(30)) | ||
| { | ||
| var windowInsetsController = dialogWindow.InsetsController; | ||
| var appearance = activity.Window.InsetsController?.SystemBarsAppearance; | ||
|
|
||
| if (windowInsetsController is null) | ||
| { | ||
| System.Diagnostics.Trace.WriteLine("WindowInsetsController is null, cannot set system bars appearance."); | ||
| return; | ||
| } | ||
|
|
||
| if (appearance.HasValue) | ||
| { | ||
| windowInsetsController.SetSystemBarsAppearance(appearance.Value, appearance.Value); | ||
| } | ||
| else | ||
| { | ||
| windowInsetsController.SetSystemBarsAppearance( | ||
| isColorTransparent ? 0 : (int)WindowInsetsControllerAppearance.LightStatusBars, | ||
| (int)WindowInsetsControllerAppearance.LightStatusBars); | ||
| } | ||
|
|
||
| dialogWindow.SetStatusBarColor(platformColor); | ||
|
|
||
| if (!OperatingSystem.IsAndroidVersionAtLeast(35)) | ||
| { | ||
| dialogWindow.SetDecorFitsSystemWindows(!isColorTransparent); | ||
| } | ||
| else | ||
| { | ||
| AndroidX.Core.View.WindowCompat.SetDecorFitsSystemWindows(dialogWindow, !isColorTransparent); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| dialogWindow.SetStatusBarColor(platformColor); | ||
|
|
||
| if (isColorTransparent) | ||
| { | ||
| dialogWindow.ClearFlags(WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| dialogWindow.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits); | ||
| } | ||
| else | ||
| { | ||
| dialogWindow.ClearFlags(WindowManagerFlags.LayoutNoLimits); | ||
| dialogWindow.SetFlags(WindowManagerFlags.DrawsSystemBarBackgrounds, WindowManagerFlags.DrawsSystemBarBackgrounds); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| public void OnFragmentStopped(FragmentManager fm, Fragment f) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentViewCreated(FragmentManager fm, Fragment f, Android.Views.View v, Bundle? savedInstanceState) | ||
| { | ||
| } | ||
|
|
||
| public void OnFragmentViewDestroyed(FragmentManager fm, Fragment f) | ||
| { | ||
| } | ||
|
|
||
| static bool TryConvertToDialogFragment(Fragment fragment, [NotNullWhen(true)] out DialogFragment? dialogFragment) | ||
| { | ||
| dialogFragment = null; | ||
|
|
||
| if (fragment is not DialogFragment dialog) | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| dialogFragment = dialog; | ||
| return true; | ||
| } | ||
| } | ||
6 changes: 6 additions & 0 deletions
6
src/CommunityToolkit.Maui.Core/Services/DialogFragmentService.shared.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| namespace CommunityToolkit.Maui.Core.Services; | ||
|
|
||
| sealed partial class DialogFragmentService | ||
| { | ||
|
|
||
| } |
87 changes: 87 additions & 0 deletions
87
src/CommunityToolkit.Maui.Core/Services/FragmentLifecycleManager.android.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| using Android.Content; | ||
| using FragmentManager = AndroidX.Fragment.App.FragmentManager; | ||
|
|
||
| namespace CommunityToolkit.Maui.Core.Services; | ||
|
|
||
| sealed class FragmentLifecycleManager(IDialogFragmentService dialogFragmentService) : FragmentManager.FragmentLifecycleCallbacks | ||
| { | ||
| readonly IDialogFragmentService dialogFragmentService = dialogFragmentService; | ||
TheCodeTraveler marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| public override void OnFragmentAttached(FragmentManager fm, AndroidX.Fragment.App.Fragment f, Context context) | ||
| { | ||
| base.OnFragmentAttached(fm, f, context); | ||
| dialogFragmentService.OnFragmentAttached(fm, f, context); | ||
| } | ||
|
|
||
| public override void OnFragmentCreated(FragmentManager fm, AndroidX.Fragment.App.Fragment f, Bundle? savedInstanceState) | ||
| { | ||
| base.OnFragmentCreated(fm, f, savedInstanceState); | ||
| dialogFragmentService.OnFragmentCreated(fm, f, savedInstanceState); | ||
| } | ||
|
|
||
| public override void OnFragmentDestroyed(FragmentManager fm, AndroidX.Fragment.App.Fragment f) | ||
| { | ||
| base.OnFragmentDestroyed(fm, f); | ||
| dialogFragmentService.OnFragmentDestroyed(fm, f); | ||
| } | ||
|
|
||
| public override void OnFragmentDetached(FragmentManager fm, AndroidX.Fragment.App.Fragment f) | ||
| { | ||
| base.OnFragmentDetached(fm, f); | ||
| dialogFragmentService.OnFragmentDetached(fm, f); | ||
| } | ||
|
|
||
| public override void OnFragmentPaused(FragmentManager fm, AndroidX.Fragment.App.Fragment f) | ||
| { | ||
| base.OnFragmentPaused(fm, f); | ||
| dialogFragmentService.OnFragmentPaused(fm, f); | ||
| } | ||
|
|
||
| public override void OnFragmentPreAttached(FragmentManager fm, AndroidX.Fragment.App.Fragment f, Context context) | ||
| { | ||
| base.OnFragmentPreAttached(fm, f, context); | ||
| dialogFragmentService.OnFragmentPreAttached(fm, f, context); | ||
| } | ||
|
|
||
| public override void OnFragmentPreCreated(FragmentManager fm, AndroidX.Fragment.App.Fragment f, Bundle? savedInstanceState) | ||
| { | ||
| base.OnFragmentPreCreated(fm, f, savedInstanceState); | ||
| dialogFragmentService.OnFragmentPreCreated(fm, f, savedInstanceState); | ||
| } | ||
|
|
||
| public override void OnFragmentResumed(FragmentManager fm, AndroidX.Fragment.App.Fragment f) | ||
| { | ||
| base.OnFragmentResumed(fm, f); | ||
| dialogFragmentService.OnFragmentResumed(fm, f); | ||
| } | ||
|
|
||
| public override void OnFragmentSaveInstanceState(FragmentManager fm, AndroidX.Fragment.App.Fragment f, Bundle outState) | ||
| { | ||
| base.OnFragmentSaveInstanceState(fm, f, outState); | ||
| dialogFragmentService.OnFragmentSaveInstanceState(fm, f, outState); | ||
| } | ||
|
|
||
| public override void OnFragmentStarted(FragmentManager fm, AndroidX.Fragment.App.Fragment f) | ||
| { | ||
| base.OnFragmentStarted(fm, f); | ||
| dialogFragmentService.OnFragmentStarted(fm, f); | ||
| } | ||
|
|
||
| public override void OnFragmentStopped(FragmentManager fm, AndroidX.Fragment.App.Fragment f) | ||
| { | ||
| base.OnFragmentStopped(fm, f); | ||
| dialogFragmentService.OnFragmentStopped(fm, f); | ||
| } | ||
|
|
||
| public override void OnFragmentViewCreated(FragmentManager fm, AndroidX.Fragment.App.Fragment f, Android.Views.View v, Bundle? savedInstanceState) | ||
| { | ||
| base.OnFragmentViewCreated(fm, f, v, savedInstanceState); | ||
| dialogFragmentService.OnFragmentViewCreated(fm, f, v, savedInstanceState); | ||
| } | ||
|
|
||
| public override void OnFragmentViewDestroyed(FragmentManager fm, AndroidX.Fragment.App.Fragment f) | ||
| { | ||
| base.OnFragmentViewDestroyed(fm, f); | ||
| dialogFragmentService.OnFragmentViewDestroyed(fm, f); | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.