diff --git a/Handlers/FlyoutPageHandler.cs b/Handlers/FlyoutPageHandler.cs index 74f9194..a9c0674 100644 --- a/Handlers/FlyoutPageHandler.cs +++ b/Handlers/FlyoutPageHandler.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.Maui.Controls; using Microsoft.Maui.Handlers; using Microsoft.Maui.Graphics; +using Microsoft.Maui.Platform.Linux.Hosting; using SkiaSharp; namespace Microsoft.Maui.Platform.Linux.Handlers; @@ -13,12 +15,17 @@ namespace Microsoft.Maui.Platform.Linux.Handlers; /// public partial class FlyoutPageHandler : ViewHandler { + private bool _isUpdatingPresented; + public static IPropertyMapper Mapper = new PropertyMapper(ViewHandler.ViewMapper) { + [nameof(IFlyoutView.Flyout)] = MapFlyout, + [nameof(IFlyoutView.Detail)] = MapDetail, [nameof(IFlyoutView.IsPresented)] = MapIsPresented, [nameof(IFlyoutView.FlyoutWidth)] = MapFlyoutWidth, [nameof(IFlyoutView.IsGestureEnabled)] = MapIsGestureEnabled, [nameof(IFlyoutView.FlyoutBehavior)] = MapFlyoutBehavior, + [nameof(IView.Background)] = MapBackground, }; public static CommandMapper CommandMapper = new(ViewHandler.ViewCommandMapper) @@ -55,13 +62,82 @@ public partial class FlyoutPageHandler : ViewHandler FlyoutLayoutBehavior.Default }; } + + public static void MapBackground(FlyoutPageHandler handler, IFlyoutView flyoutView) + { + if (handler.PlatformView is null) return; + + if (flyoutView is FlyoutPage flyoutPage && flyoutPage.Background is SolidColorBrush solidBrush) + { + handler.PlatformView.ScrimColor = solidBrush.Color.ToSKColor().WithAlpha(100); + } + } } diff --git a/Handlers/TabbedPageHandler.cs b/Handlers/TabbedPageHandler.cs index b306004..355db82 100644 --- a/Handlers/TabbedPageHandler.cs +++ b/Handlers/TabbedPageHandler.cs @@ -1,8 +1,10 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using Microsoft.Maui.Controls; using Microsoft.Maui.Handlers; using Microsoft.Maui.Graphics; +using Microsoft.Maui.Platform.Linux.Hosting; using SkiaSharp; namespace Microsoft.Maui.Platform.Linux.Handlers; @@ -13,8 +15,14 @@ namespace Microsoft.Maui.Platform.Linux.Handlers; /// public partial class TabbedPageHandler : ViewHandler { + private bool _isUpdatingSelection; + public static IPropertyMapper Mapper = new PropertyMapper(ViewHandler.ViewMapper) { + [nameof(TabbedPage.BarBackgroundColor)] = MapBarBackgroundColor, + [nameof(TabbedPage.BarTextColor)] = MapBarTextColor, + [nameof(TabbedPage.SelectedTabColor)] = MapSelectedTabColor, + [nameof(TabbedPage.UnselectedTabColor)] = MapUnselectedTabColor, }; public static CommandMapper CommandMapper = new(ViewHandler.ViewCommandMapper) @@ -39,6 +47,9 @@ public partial class TabbedPageHandler : ViewHandler= 0) + { + var selectedIndex = PlatformView.SelectedIndex; + if (selectedIndex < tabbedPage.Children.Count) + { + tabbedPage.CurrentPage = tabbedPage.Children[selectedIndex] as Page; + } + } + } + finally + { + _isUpdatingSelection = false; + } + } + + private void SyncTabs() + { + if (PlatformView is null || VirtualView is null || MauiContext is null) return; + + PlatformView.ClearTabs(); + + if (VirtualView is TabbedPage tabbedPage) + { + foreach (var child in tabbedPage.Children) + { + if (child is Page page) + { + // Create handler for page content + if (page.Handler == null) + { + page.Handler = page.ToViewHandler(MauiContext); + } + + if (page.Handler?.PlatformView is SkiaView skiaContent) + { + PlatformView.AddTab(page.Title ?? "Tab", skiaContent, page.IconImageSource?.ToString()); + } + } + } + + // Sync selected tab + if (tabbedPage.CurrentPage != null) + { + var index = tabbedPage.Children.IndexOf(tabbedPage.CurrentPage); + if (index >= 0) + { + PlatformView.SelectedIndex = index; + } + } + } + } + + public static void MapBarBackgroundColor(TabbedPageHandler handler, ITabbedView tabbedView) + { + if (handler.PlatformView is null) return; + + if (tabbedView is TabbedPage tabbedPage && tabbedPage.BarBackgroundColor is Color color) + { + handler.PlatformView.TabBarBackgroundColor = color.ToSKColor(); + } + } + + public static void MapBarTextColor(TabbedPageHandler handler, ITabbedView tabbedView) + { + if (handler.PlatformView is null) return; + + if (tabbedView is TabbedPage tabbedPage && tabbedPage.BarTextColor is Color color) + { + // BarTextColor applies to unselected tabs + handler.PlatformView.UnselectedTabColor = color.ToSKColor(); + } + } + + public static void MapSelectedTabColor(TabbedPageHandler handler, ITabbedView tabbedView) + { + if (handler.PlatformView is null) return; + + if (tabbedView is TabbedPage tabbedPage && tabbedPage.SelectedTabColor is Color color) + { + handler.PlatformView.SelectedTabColor = color.ToSKColor(); + handler.PlatformView.IndicatorColor = color.ToSKColor(); + } + } + + public static void MapUnselectedTabColor(TabbedPageHandler handler, ITabbedView tabbedView) + { + if (handler.PlatformView is null) return; + + if (tabbedView is TabbedPage tabbedPage && tabbedPage.UnselectedTabColor is Color color) + { + handler.PlatformView.UnselectedTabColor = color.ToSKColor(); + } } }