diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellBottomNavViewAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellBottomNavViewAppearanceTracker.cs index d286c74da15f..5561fc9e9299 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellBottomNavViewAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellBottomNavViewAppearanceTracker.cs @@ -42,7 +42,7 @@ public virtual void ResetAppearance(BottomNavigationView bottomView) { bottomView.ItemIconTintList = GetDefaultTabColorList(_shellContext.AndroidContext); bottomView.ItemTextColor = GetDefaultTabColorList(_shellContext.AndroidContext); - SetBackgroundColor(bottomView, null); + SetBackground(bottomView, null); AndroidSystemChrome.UpdateBottomChrome( bottomView, new SolidColorBrush(ShellRenderer.DefaultBottomNavigationViewBackgroundColor)); @@ -52,6 +52,14 @@ public virtual void SetAppearance(BottomNavigationView bottomView, IShellAppeara { IShellAppearanceElement controller = appearance; var backgroundColor = controller.EffectiveTabBarBackgroundColor; + var shellAppearance = appearance as ShellAppearance; + var background = backgroundColor is not null + ? new SolidColorBrush(backgroundColor) + : !Brush.IsNullOrEmpty(shellAppearance?.Background) + ? shellAppearance.Background + : shellAppearance?.BackgroundColor is not null + ? new SolidColorBrush(shellAppearance.BackgroundColor) + : null; var foregroundColor = controller.EffectiveTabBarForegroundColor; var disabledColor = controller.EffectiveTabBarDisabledColor; var unselectedColor = controller.EffectiveTabBarUnselectedColor; @@ -70,14 +78,21 @@ public virtual void SetAppearance(BottomNavigationView bottomView, IShellAppeara bottomView.ItemTextColor = _itemTextColor; bottomView.ItemIconTintList = _itemIconTint; - SetBackgroundColor(bottomView, backgroundColor); + SetBackground(bottomView, background); AndroidSystemChrome.UpdateBottomChrome( bottomView, - new SolidColorBrush(backgroundColor ?? ShellRenderer.DefaultBottomNavigationViewBackgroundColor)); + background ?? new SolidColorBrush(ShellRenderer.DefaultBottomNavigationViewBackgroundColor)); } - protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color) + protected virtual void SetBackground(BottomNavigationView bottomView, Brush brush) { + if (brush is GradientBrush) + { + bottomView.UpdateBackground(brush); + return; + } + + var color = (brush as SolidColorBrush)?.Color; #pragma warning disable XAOBS001 // Obsolete var menuView = bottomView.GetChildAt(0) as BottomNavigationMenuView; #pragma warning restore XAOBS001 // Obsolete @@ -130,6 +145,12 @@ protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color } } + [Obsolete("Use SetBackground(BottomNavigationView, Brush) instead.")] + protected virtual void SetBackgroundColor(BottomNavigationView bottomView, Color color) + { + SetBackground(bottomView, color is not null ? new SolidColorBrush(color) : null); + } + static ColorStateList MakeDefaultColorStateList(Context context) { TypedValue mTypedValue = new TypedValue(); diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SafeShellTabBarAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SafeShellTabBarAppearanceTracker.cs index e0ecca140f76..8443fda2f973 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SafeShellTabBarAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SafeShellTabBarAppearanceTracker.cs @@ -71,7 +71,13 @@ void UpdateiOS15TabBarAppearance(UITabBarController controller, ShellAppearance { IShellAppearanceElement appearanceElement = appearance; - var backgroundColor = appearanceElement.EffectiveTabBarBackgroundColor; + var background = appearanceElement.EffectiveTabBarBackgroundColor is not null + ? new SolidColorBrush(appearanceElement.EffectiveTabBarBackgroundColor) + : !Brush.IsNullOrEmpty(appearance.Background) + ? appearance.Background + : appearance.BackgroundColor is not null + ? new SolidColorBrush(appearance.BackgroundColor) + : null; var foregroundColor = appearanceElement.EffectiveTabBarForegroundColor; var unselectedColor = appearanceElement.EffectiveTabBarUnselectedColor; var titleColor = appearanceElement.EffectiveTabBarTitleColor; @@ -84,7 +90,7 @@ void UpdateiOS15TabBarAppearance(UITabBarController controller, ShellAppearance null, foregroundColor ?? titleColor, unselectedColor, - backgroundColor, + background, titleColor ?? foregroundColor, unselectedColor); diff --git a/src/Controls/src/Core/Compatibility/Handlers/TabbedPage/iOS/TabbedRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/TabbedPage/iOS/TabbedRenderer.cs index 5ad7566f5144..2d0f1c71444e 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/TabbedPage/iOS/TabbedRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/TabbedPage/iOS/TabbedRenderer.cs @@ -642,7 +642,7 @@ void UpdateiOS15TabBarAppearance() _defaultBarTextColor, tabbed.IsSet(TabbedPage.SelectedTabColorProperty) ? tabbed.SelectedTabColor : null, tabbed.IsSet(TabbedPage.UnselectedTabColorProperty) ? tabbed.UnselectedTabColor : null, - tabbed.IsSet(TabbedPage.BarBackgroundColorProperty) ? tabbed.BarBackgroundColor : null, + tabbed.IsSet(TabbedPage.BarBackgroundColorProperty) ? tabbed.BarBackgroundColor.AsPaint() : null, tabbed.IsSet(TabbedPage.BarTextColorProperty) ? tabbed.BarTextColor : null, tabbed.IsSet(TabbedPage.BarTextColorProperty) ? tabbed.BarTextColor : null); } diff --git a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt index 70c245943443..20be6fec451e 100644 --- a/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt +++ b/src/Controls/src/Core/PublicAPI/net-android/PublicAPI.Unshipped.txt @@ -188,6 +188,7 @@ virtual Microsoft.Maui.Controls.Handlers.ShellItemHandler.CreateMoreBottomSheet( virtual Microsoft.Maui.Controls.Handlers.ShellItemHandler.OnSectionChanged(Microsoft.Maui.Controls.ShellSection! shellSection, bool animate) -> void virtual Microsoft.Maui.Controls.Handlers.ShellItemHandler.OnTabReselected(Microsoft.Maui.Controls.ShellSection! shellSection) -> void virtual Microsoft.Maui.Controls.Handlers.ShellSectionHandler.OnCreateNavigationAnimation(Android.Content.Context! context, bool isPopping, bool enter) -> Android.Views.Animations.Animation? +~virtual Microsoft.Maui.Controls.Platform.Compatibility.ShellBottomNavViewAppearanceTracker.SetBackground(Google.Android.Material.BottomNavigation.BottomNavigationView bottomView, Microsoft.Maui.Controls.Brush brush) -> void virtual Microsoft.Maui.Controls.Platform.Compatibility.ShellFlyoutTemplatedContentRenderer.UpdateVerticalScrollMode() -> void Microsoft.Maui.Controls.Handlers.ShellContentNavigationFragment Microsoft.Maui.Controls.Handlers.ShellContentNavigationFragment.ShellContentNavigationFragment() -> void diff --git a/src/Controls/src/Core/Shell/ShellAppearance.cs b/src/Controls/src/Core/Shell/ShellAppearance.cs index b439633454a2..1c37447e6514 100644 --- a/src/Controls/src/Core/Shell/ShellAppearance.cs +++ b/src/Controls/src/Core/Shell/ShellAppearance.cs @@ -79,7 +79,7 @@ public class ShellAppearance : IShellAppearanceElement public double FlyoutHeight => _doubleArray[1]; Color IShellAppearanceElement.EffectiveTabBarBackgroundColor => - TabBarBackgroundColor ?? BackgroundColor; + TabBarBackgroundColor; Color IShellAppearanceElement.EffectiveTabBarDisabledColor => TabBarDisabledColor ?? DisabledColor; diff --git a/src/Controls/src/Core/TabbedPage/TabbedPage.iOS.cs b/src/Controls/src/Core/TabbedPage/TabbedPage.iOS.cs index 805e0a69771b..d7ce62973105 100644 --- a/src/Controls/src/Core/TabbedPage/TabbedPage.iOS.cs +++ b/src/Controls/src/Core/TabbedPage/TabbedPage.iOS.cs @@ -846,7 +846,7 @@ void UpdateiOS15TabBarAppearance(UITabBar tabBar) _defaultBarTextColor, IsSet(SelectedTabColorProperty) ? SelectedTabColor : null, IsSet(UnselectedTabColorProperty) ? UnselectedTabColor : null, - IsSet(BarBackgroundColorProperty) ? BarBackgroundColor : null, + IsSet(BarBackgroundColorProperty) ? BarBackgroundColor.AsPaint() : null, IsSet(BarTextColorProperty) ? BarTextColor : null, IsSet(BarTextColorProperty) ? BarTextColor : null); } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Issue10445.cs b/src/Controls/tests/TestCases.HostApp/Issues/Issue10445.cs index 9c72e43c885f..b633ccff18a1 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Issue10445.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Issue10445.cs @@ -40,6 +40,16 @@ protected override void Init() } }; - AddContentPage(page, "Home"); + AddBottomTab(page, "Home"); + AddBottomTab(new ContentPage + { + Title = "Settings", + Content = new Label + { + Text = "Settings", + HorizontalOptions = LayoutOptions.Center, + VerticalOptions = LayoutOptions.Center + } + }, "Settings"); } } diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/ShellBackgroundSupportsGradientBrush.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/ShellBackgroundSupportsGradientBrush.png index ab89b28bfab5..6939e3768961 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/ShellBackgroundSupportsGradientBrush.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios-26/ShellBackgroundSupportsGradientBrush.png differ diff --git a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShellBackgroundSupportsGradientBrush.png b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShellBackgroundSupportsGradientBrush.png index c4bd289cfb04..7030598db8d2 100644 Binary files a/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShellBackgroundSupportsGradientBrush.png and b/src/Controls/tests/TestCases.iOS.Tests/snapshots/ios/ShellBackgroundSupportsGradientBrush.png differ diff --git a/src/Core/src/Platform/iOS/TabbedViewExtensions.cs b/src/Core/src/Platform/iOS/TabbedViewExtensions.cs index 055c4ad3998b..619bfa26cd8b 100644 --- a/src/Core/src/Platform/iOS/TabbedViewExtensions.cs +++ b/src/Core/src/Platform/iOS/TabbedViewExtensions.cs @@ -35,7 +35,7 @@ internal static void UpdateiOS15TabBarAppearance( UIColor? defaultBarTextColor, Color? selectedTabColor, Color? unselectedTabColor, - Color? barBackgroundColor, + Paint? barBackground, Color? selectedBarTextColor, Color? unSelectedBarTextColor) { @@ -45,7 +45,25 @@ internal static void UpdateiOS15TabBarAppearance( _tabBarAppearance.ConfigureWithDefaultBackground(); } - var effectiveBarColor = (barBackgroundColor == null) ? defaultBarColor : barBackgroundColor.ToPlatform(); + var effectiveBarColor = barBackground switch + { + null => defaultBarColor, + SolidPaint solidPaint => solidPaint.Color?.ToPlatform(), + _ => null, + }; + + if (barBackground is GradientPaint) + { + _tabBarAppearance.BackgroundEffect = null; + _tabBarAppearance.BackgroundColor = UIColor.Clear; + tabBar.BackgroundColor = UIColor.Clear; + tabBar.UpdateBackground(barBackground); + } + else + { + tabBar.RemoveBackgroundLayer(); + } + // Set BarBackgroundColor if (effectiveBarColor != null) {