Skip to content

Commit 14f6161

Browse files
Tamilarasan-ParanthamanPureWeen
authored andcommitted
NavigationPage NavBar changes
# Conflicts: # src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs
1 parent c743049 commit 14f6161

File tree

7 files changed

+94
-33
lines changed

7 files changed

+94
-33
lines changed

src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public class NavigationRenderer : UINavigationController, INavigationViewHandler
4545
public static IPropertyMapper<NavigationPage, NavigationRenderer> Mapper = new PropertyMapper<NavigationPage, NavigationRenderer>(ViewHandler.ViewMapper)
4646
{
4747
[PlatformConfiguration.iOSSpecific.NavigationPage.PrefersLargeTitlesProperty.PropertyName] = NavigationPage.MapPrefersLargeTitles,
48-
[PlatformConfiguration.iOSSpecific.NavigationPage.IsNavigationBarTranslucentProperty.PropertyName] = NavigationPage.MapIsNavigationBarTranslucent,
4948
};
5049

5150
public static CommandMapper<NavigationPage, NavigationRenderer> CommandMapper = new CommandMapper<NavigationPage, NavigationRenderer>(ViewHandler.ViewCommandMapper);
@@ -513,10 +512,12 @@ void HandlePropertyChanged(object sender, PropertyChangedEventArgs e)
513512
var current = Current = NavPage?.CurrentPage;
514513
ValidateNavbarExists(current);
515514
}
515+
#pragma warning disable CS0618 // Type or member is obsolete
516516
else if (e.PropertyName == IsNavigationBarTranslucentProperty.PropertyName)
517517
{
518518
UpdateTranslucent();
519519
}
520+
#pragma warning restore CS0618 // Type or member is obsolete
520521
else if (e.PropertyName == PreferredStatusBarUpdateAnimationProperty.PropertyName)
521522
{
522523
UpdateCurrentPagePreferredStatusBarUpdateAnimation();
@@ -628,7 +629,9 @@ void UpdateUseLargeTitles()
628629

629630
void UpdateTranslucent()
630631
{
631-
_viewHandlerWrapper.UpdateProperty(IsNavigationBarTranslucentProperty.PropertyName);
632+
#pragma warning disable CS0618 // Type or member is obsolete
633+
NavigationBar.Translucent = NavPage.OnThisPlatform().IsNavigationBarTranslucent();
634+
#pragma warning restore CS0618 // Type or member is obsolete
632635
}
633636

634637
void InsertPageBefore(Page page, Page before)
@@ -767,6 +770,15 @@ void RefreshBarBackground()
767770
_currentBarBackgroundBrush = null;
768771
}
769772

773+
#pragma warning disable CS0618 // Type or member is obsolete
774+
bool userTranslucentValue = false;
775+
bool isNavigationBarTranslucentExplicitlySet = NavPage.IsSet(IsNavigationBarTranslucentProperty);
776+
if (isNavigationBarTranslucentExplicitlySet)
777+
{
778+
userTranslucentValue = NavPage.OnThisPlatform().IsNavigationBarTranslucent();
779+
}
780+
#pragma warning restore CS0618 // Type or member is obsolete
781+
770782
if (OperatingSystem.IsIOSVersionAtLeast(13) || OperatingSystem.IsMacCatalystVersionAtLeast(13))
771783
{
772784
var navigationBarAppearance = NavigationBar.StandardAppearance;
@@ -780,10 +792,34 @@ void RefreshBarBackground()
780792
}
781793
else
782794
{
783-
if (_currentBarBackgroundColor?.Alpha < 1f)
784-
navigationBarAppearance.ConfigureWithTransparentBackground();
795+
// If user explicitly set translucent property, respect that value
796+
if (isNavigationBarTranslucentExplicitlySet)
797+
{
798+
if (userTranslucentValue)
799+
{
800+
navigationBarAppearance.ConfigureWithTransparentBackground();
801+
NavigationBar.Translucent = true;
802+
}
803+
else
804+
{
805+
navigationBarAppearance.ConfigureWithOpaqueBackground();
806+
NavigationBar.Translucent = false;
807+
}
808+
}
785809
else
786-
navigationBarAppearance.ConfigureWithOpaqueBackground();
810+
{
811+
// Default behavior: set translucency based on background color alpha
812+
if (_currentBarBackgroundColor?.Alpha < 1f)
813+
{
814+
navigationBarAppearance.ConfigureWithTransparentBackground();
815+
NavigationBar.Translucent = true;
816+
}
817+
else
818+
{
819+
navigationBarAppearance.ConfigureWithOpaqueBackground();
820+
NavigationBar.Translucent = false;
821+
}
822+
}
787823

788824
navigationBarAppearance.BackgroundColor = _currentBarBackgroundColor.ToPlatform();
789825
}
@@ -801,19 +837,43 @@ void RefreshBarBackground()
801837
}
802838
else
803839
{
804-
if (_currentBarBackgroundColor?.Alpha == 0f)
840+
// If user explicitly set translucent property, respect that value
841+
if (isNavigationBarTranslucentExplicitlySet)
805842
{
806-
NavigationBar.SetTransparentNavigationBar();
843+
if (userTranslucentValue)
844+
{
845+
NavigationBar.SetTransparentNavigationBar();
846+
NavigationBar.Translucent = true;
847+
}
848+
else
849+
{
850+
// Set navigation bar background color for opaque navigation bar
851+
NavigationBar.BarTintColor = _currentBarBackgroundColor == null
852+
? UINavigationBar.Appearance.BarTintColor
853+
: _currentBarBackgroundColor.ToPlatform();
854+
855+
var backgroundImage = NavigationBar.GetBackgroundImage(_currentBarBackgroundBrush);
856+
NavigationBar.SetBackgroundImage(backgroundImage, UIBarMetrics.Default);
857+
NavigationBar.Translucent = false;
858+
}
807859
}
808860
else
809861
{
810-
// Set navigation bar background color
811-
NavigationBar.BarTintColor = _currentBarBackgroundColor == null
812-
? UINavigationBar.Appearance.BarTintColor
813-
: _currentBarBackgroundColor.ToPlatform();
862+
// Default behavior: set translucency based on background color alpha
863+
if (_currentBarBackgroundColor?.Alpha == 0f)
864+
{
865+
NavigationBar.SetTransparentNavigationBar();
866+
}
867+
else
868+
{
869+
// Set navigation bar background color
870+
NavigationBar.BarTintColor = _currentBarBackgroundColor == null
871+
? UINavigationBar.Appearance.BarTintColor
872+
: _currentBarBackgroundColor.ToPlatform();
814873

815-
var backgroundImage = NavigationBar.GetBackgroundImage(_currentBarBackgroundBrush);
816-
NavigationBar.SetBackgroundImage(backgroundImage, UIBarMetrics.Default);
874+
var backgroundImage = NavigationBar.GetBackgroundImage(_currentBarBackgroundBrush);
875+
NavigationBar.SetBackgroundImage(backgroundImage, UIBarMetrics.Default);
876+
}
817877
}
818878
}
819879
}

src/Controls/src/Core/NavigationPage/NavigationPage.Mapper.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ public partial class NavigationPage
1111
// Adjust the mappings to preserve Controls.NavigationPage legacy behaviors
1212
#if IOS
1313
NavigationViewHandler.Mapper.ReplaceMapping<NavigationPage, NavigationViewHandler>(PlatformConfiguration.iOSSpecific.NavigationPage.PrefersLargeTitlesProperty.PropertyName, MapPrefersLargeTitles);
14-
NavigationViewHandler.Mapper.ReplaceMapping<NavigationPage, NavigationViewHandler>(PlatformConfiguration.iOSSpecific.NavigationPage.IsNavigationBarTranslucentProperty.PropertyName, MapIsNavigationBarTranslucent);
1514
#endif
1615
}
1716
}

src/Controls/src/Core/NavigationPage/NavigationPage.iOS.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,10 @@ public partial class NavigationPage
88
public static void MapPrefersLargeTitles(NavigationViewHandler handler, NavigationPage navigationPage) =>
99
MapPrefersLargeTitles((INavigationViewHandler)handler, navigationPage);
1010

11-
public static void MapIsNavigationBarTranslucent(NavigationViewHandler handler, NavigationPage navigationPage) =>
12-
MapPrefersLargeTitles((INavigationViewHandler)handler, navigationPage);
13-
1411
public static void MapPrefersLargeTitles(INavigationViewHandler handler, NavigationPage navigationPage)
1512
{
1613
if (handler is IPlatformViewHandler nvh && nvh.ViewController is UINavigationController navigationController)
1714
Platform.NavigationPageExtensions.UpdatePrefersLargeTitles(navigationController, navigationPage);
1815
}
19-
20-
public static void MapIsNavigationBarTranslucent(INavigationViewHandler handler, NavigationPage navigationPage)
21-
{
22-
if (handler is IPlatformViewHandler nvh && nvh.ViewController is UINavigationController navigationController)
23-
Platform.NavigationPageExtensions.UpdateIsNavigationBarTranslucent(navigationController, navigationPage);
24-
}
2516
}
2617
}

src/Controls/src/Core/Platform/iOS/Extensions/NavigationPageExtensions.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,14 @@ public static class NavigationPageExtensions
1010
public static void UpdatePrefersLargeTitles(this UINavigationController platformView, NavigationPage navigationPage)
1111
{
1212
if (platformView.NavigationBar is null)
13+
{
1314
return;
15+
}
1416

1517
if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsMacCatalystVersionAtLeast(11))
18+
{
1619
platformView.NavigationBar.PrefersLargeTitles = navigationPage.OnThisPlatform().PrefersLargeTitles();
17-
}
18-
19-
public static void UpdateIsNavigationBarTranslucent(this UINavigationController platformView, NavigationPage navigationPage)
20-
{
21-
if (platformView.NavigationBar is null)
22-
return;
23-
24-
platformView.NavigationBar.Translucent = navigationPage.OnThisPlatform().IsNavigationBarTranslucent();
20+
}
2521
}
2622

2723
internal static void SetTransparentNavigationBar(this UINavigationBar navigationBar)

src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,31 @@
22

33
namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific
44
{
5+
using System;
56
using FormsElement = Maui.Controls.NavigationPage;
67

78
/// <summary>The navigation page instance that Microsoft.Maui.Controls created on the iOS platform.</summary>
89
public static class NavigationPage
910
{
1011
#region Translucent
1112
/// <summary>Bindable property for <see cref="IsNavigationBarTranslucent"/>.</summary>
13+
14+
[Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")]
1215
public static readonly BindableProperty IsNavigationBarTranslucentProperty =
13-
BindableProperty.Create("IsNavigationBarTranslucent", typeof(bool),
14-
typeof(NavigationPage), false);
16+
BindableProperty.Create("IsNavigationBarTranslucent", typeof(bool),
17+
typeof(NavigationPage), false);
1518

1619
/// <summary>Returns a Boolean value that tells whether the navigation bar on the platform-specific navigation page is translucent.</summary>
1720
/// <param name="element">The platform specific element on which to perform the operation.</param>
1821
/// <returns>A Boolean value that tells whether the navigation bar on the platform-specific navigation page is translucent.</returns>
22+
[Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")]
1923
public static bool GetIsNavigationBarTranslucent(BindableObject element)
2024
{
2125
return (bool)element.GetValue(IsNavigationBarTranslucentProperty);
2226
}
2327

2428
/// <include file="../../../../docs/Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific/NavigationPage.xml" path="//Member[@MemberName='SetIsNavigationBarTranslucent'][1]/Docs/*" />
29+
[Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")]
2530
public static void SetIsNavigationBarTranslucent(BindableObject element, bool value)
2631
{
2732
element.SetValue(IsNavigationBarTranslucentProperty, value);
@@ -30,12 +35,14 @@ public static void SetIsNavigationBarTranslucent(BindableObject element, bool va
3035
/// <summary>Returns a Boolean value that tells whether the navigation bar on the platform-specific navigation page is translucent.</summary>
3136
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
3237
/// <returns>A Boolean value that tells whether the navigation bar on the platform-specific navigation page is translucent.</returns>
38+
[Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")]
3339
public static bool IsNavigationBarTranslucent(this IPlatformElementConfiguration<iOS, FormsElement> config)
3440
{
3541
return GetIsNavigationBarTranslucent(config.Element);
3642
}
3743

3844
/// <include file="../../../../docs/Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific/NavigationPage.xml" path="//Member[@MemberName='SetIsNavigationBarTranslucent'][2]/Docs/*" />
45+
[Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")]
3946
public static IPlatformElementConfiguration<iOS, FormsElement> SetIsNavigationBarTranslucent(this IPlatformElementConfiguration<iOS, FormsElement> config, bool value)
4047
{
4148
SetIsNavigationBarTranslucent(config.Element, value);
@@ -45,6 +52,7 @@ public static IPlatformElementConfiguration<iOS, FormsElement> SetIsNavigationBa
4552
/// <summary>Makes the navigation bar translucent on the platform-specific element.</summary>
4653
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
4754
/// <returns>The updated configuration object on which developers can make successive method calls.</returns>
55+
[Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")]
4856
public static IPlatformElementConfiguration<iOS, FormsElement> EnableTranslucentNavigationBar(this IPlatformElementConfiguration<iOS, FormsElement> config)
4957
{
5058
SetIsNavigationBarTranslucent(config.Element, true);
@@ -54,6 +62,7 @@ public static IPlatformElementConfiguration<iOS, FormsElement> EnableTranslucent
5462
/// <summary>Makes the navigation bar opaque on the platform-specific element.</summary>
5563
/// <param name="config">The platform specific configuration that contains the element on which to perform the operation.</param>
5664
/// <returns>The updated configuration object on which developers can make successive method calls.</returns>
65+
[Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")]
5766
public static IPlatformElementConfiguration<iOS, FormsElement> DisableTranslucentNavigationBar(this IPlatformElementConfiguration<iOS, FormsElement> config)
5867
{
5968
SetIsNavigationBarTranslucent(config.Element, false);

src/Controls/src/Core/PublicAPI/net-ios/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Microsoft.Maui.Controls.BrushTypeConverter.GradientBrushParser.Parse(string? css
2626
*REMOVED*Microsoft.Maui.Controls.ClickedEventArgs.Buttons.get -> Microsoft.Maui.Controls.ButtonsMask
2727
*REMOVED*~Microsoft.Maui.Controls.ClickedEventArgs.ClickedEventArgs(Microsoft.Maui.Controls.ButtonsMask buttons, object commandParameter) -> void
2828
*REMOVED*~Microsoft.Maui.Controls.ClickedEventArgs.Parameter.get -> object
29+
*REMOVED*~static Microsoft.Maui.Controls.NavigationPage.MapIsNavigationBarTranslucent(Microsoft.Maui.Handlers.INavigationViewHandler handler, Microsoft.Maui.Controls.NavigationPage navigationPage) -> void
30+
*REMOVED*~static Microsoft.Maui.Controls.NavigationPage.MapIsNavigationBarTranslucent(Microsoft.Maui.Handlers.NavigationViewHandler handler, Microsoft.Maui.Controls.NavigationPage navigationPage) -> void
31+
*REMOVED*~static Microsoft.Maui.Controls.Platform.NavigationPageExtensions.UpdateIsNavigationBarTranslucent(this UIKit.UINavigationController platformView, Microsoft.Maui.Controls.NavigationPage navigationPage) -> void
2932
Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges
3033
Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void
3134
Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool

src/Controls/src/Core/PublicAPI/net-maccatalyst/PublicAPI.Unshipped.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ Microsoft.Maui.Controls.BrushTypeConverter.GradientBrushParser.Parse(string? css
2626
*REMOVED*Microsoft.Maui.Controls.ClickedEventArgs.Buttons.get -> Microsoft.Maui.Controls.ButtonsMask
2727
*REMOVED*~Microsoft.Maui.Controls.ClickedEventArgs.ClickedEventArgs(Microsoft.Maui.Controls.ButtonsMask buttons, object commandParameter) -> void
2828
*REMOVED*~Microsoft.Maui.Controls.ClickedEventArgs.Parameter.get -> object
29+
*REMOVED*~static Microsoft.Maui.Controls.NavigationPage.MapIsNavigationBarTranslucent(Microsoft.Maui.Handlers.INavigationViewHandler handler, Microsoft.Maui.Controls.NavigationPage navigationPage) -> void
30+
*REMOVED*~static Microsoft.Maui.Controls.NavigationPage.MapIsNavigationBarTranslucent(Microsoft.Maui.Handlers.NavigationViewHandler handler, Microsoft.Maui.Controls.NavigationPage navigationPage) -> void
31+
*REMOVED*~static Microsoft.Maui.Controls.Platform.NavigationPageExtensions.UpdateIsNavigationBarTranslucent(this UIKit.UINavigationController platformView, Microsoft.Maui.Controls.NavigationPage navigationPage) -> void
2932
Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.get -> Microsoft.Maui.SafeAreaEdges
3033
Microsoft.Maui.Controls.ContentPage.SafeAreaEdges.set -> void
3134
Microsoft.Maui.Controls.ContentPresenter.CascadeInputTransparent.get -> bool

0 commit comments

Comments
 (0)