From 9d3e2fb1037024fb982e7f1c8b18cbace7a6754e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mikael=20Nens=C3=A9n?= Date: Sun, 25 Feb 2024 14:51:54 +0100 Subject: [PATCH] Updated StatusBarBehavior to use the NavigatedTo event (#1471) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Updated StatusBarBehavior to use the NavigatedTo event for setting the color and style and updated the Sample app. * Added fact to verify expected exception on NavigatedTo event. * Update src/CommunityToolkit.Maui.UnitTests/Behaviors/StatusBarBehaviorTests.cs It wasn't inside the if before so forgot to remove it after wrapping it :) Co-authored-by: Pedro Jesus * Removed unit test I do not know how to trigger OnAttachedTo without using reflection. * Added enum StatusBarApplyOn to control when the StatusBarBehavior applies its configured color and style. * Updated sample to use the new enum --------- Co-authored-by: Mikael Nensén Co-authored-by: Pedro Jesus Co-authored-by: Shaun Lawrence --- .../Pages/Behaviors/BehaviorsGalleryPage.cs | 16 ++++- .../Behaviors/StatusBarBehaviorPage.xaml | 9 ++- .../StatusBar/StatusBarBehavior.shared.cs | 71 ++++++++++++++++--- 3 files changed, 80 insertions(+), 16 deletions(-) diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/BehaviorsGalleryPage.cs b/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/BehaviorsGalleryPage.cs index 6132d060a3..4fbcb787f1 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/BehaviorsGalleryPage.cs +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/BehaviorsGalleryPage.cs @@ -1,4 +1,5 @@ -using CommunityToolkit.Maui.Sample.ViewModels.Behaviors; +using CommunityToolkit.Maui.Behaviors; +using CommunityToolkit.Maui.Sample.ViewModels.Behaviors; namespace CommunityToolkit.Maui.Sample.Pages.Behaviors; @@ -7,5 +8,18 @@ public class BehaviorsGalleryPage : BaseGalleryPage public BehaviorsGalleryPage(IDeviceInfo deviceInfo, BehaviorsGalleryViewModel behaviorsGalleryViewModel) : base("Behaviors", deviceInfo, behaviorsGalleryViewModel) { +#if ANDROID || IOS + AddStatusBarBehavior(); +#endif + } + + void AddStatusBarBehavior() + { + Behaviors.Add(new StatusBarBehavior + { + StatusBarColor = Color.FromRgb(25, 118, 210), + StatusBarStyle = Core.StatusBarStyle.LightContent, + ApplyOn = StatusBarApplyOn.OnPageNavigatedTo, + }); } } \ No newline at end of file diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml index 6f90c362f5..3bb0f52bda 100644 --- a/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml +++ b/samples/CommunityToolkit.Maui.Sample/Pages/Behaviors/StatusBarBehaviorPage.xaml @@ -115,11 +115,10 @@