Navigation completed

This commit is contained in:
2026-01-17 01:17:36 +00:00
parent 7a1241cbf2
commit d8bdf5472f
2 changed files with 199 additions and 4 deletions

View File

@@ -1,8 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers; using Microsoft.Maui.Handlers;
using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Hosting;
using SkiaSharp; using SkiaSharp;
namespace Microsoft.Maui.Platform.Linux.Handlers; namespace Microsoft.Maui.Platform.Linux.Handlers;
@@ -13,12 +15,17 @@ namespace Microsoft.Maui.Platform.Linux.Handlers;
/// </summary> /// </summary>
public partial class FlyoutPageHandler : ViewHandler<IFlyoutView, SkiaFlyoutPage> public partial class FlyoutPageHandler : ViewHandler<IFlyoutView, SkiaFlyoutPage>
{ {
private bool _isUpdatingPresented;
public static IPropertyMapper<IFlyoutView, FlyoutPageHandler> Mapper = new PropertyMapper<IFlyoutView, FlyoutPageHandler>(ViewHandler.ViewMapper) public static IPropertyMapper<IFlyoutView, FlyoutPageHandler> Mapper = new PropertyMapper<IFlyoutView, FlyoutPageHandler>(ViewHandler.ViewMapper)
{ {
[nameof(IFlyoutView.Flyout)] = MapFlyout,
[nameof(IFlyoutView.Detail)] = MapDetail,
[nameof(IFlyoutView.IsPresented)] = MapIsPresented, [nameof(IFlyoutView.IsPresented)] = MapIsPresented,
[nameof(IFlyoutView.FlyoutWidth)] = MapFlyoutWidth, [nameof(IFlyoutView.FlyoutWidth)] = MapFlyoutWidth,
[nameof(IFlyoutView.IsGestureEnabled)] = MapIsGestureEnabled, [nameof(IFlyoutView.IsGestureEnabled)] = MapIsGestureEnabled,
[nameof(IFlyoutView.FlyoutBehavior)] = MapFlyoutBehavior, [nameof(IFlyoutView.FlyoutBehavior)] = MapFlyoutBehavior,
[nameof(IView.Background)] = MapBackground,
}; };
public static CommandMapper<IFlyoutView, FlyoutPageHandler> CommandMapper = new(ViewHandler.ViewCommandMapper) public static CommandMapper<IFlyoutView, FlyoutPageHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
@@ -55,13 +62,82 @@ public partial class FlyoutPageHandler : ViewHandler<IFlyoutView, SkiaFlyoutPage
private void OnIsPresentedChanged(object? sender, EventArgs e) private void OnIsPresentedChanged(object? sender, EventArgs e)
{ {
// Sync back to the virtual view if (VirtualView is null || PlatformView is null || _isUpdatingPresented) return;
try
{
_isUpdatingPresented = true;
// Sync back to the virtual view
if (VirtualView is FlyoutPage flyoutPage)
{
flyoutPage.IsPresented = PlatformView.IsPresented;
}
}
finally
{
_isUpdatingPresented = false;
}
}
public static void MapFlyout(FlyoutPageHandler handler, IFlyoutView flyoutView)
{
if (handler.PlatformView is null || handler.MauiContext is null) return;
var flyout = flyoutView.Flyout;
if (flyout == null)
{
handler.PlatformView.Flyout = null;
return;
}
// Create handler for flyout content
if (flyout.Handler == null)
{
flyout.Handler = flyout.ToViewHandler(handler.MauiContext);
}
if (flyout.Handler?.PlatformView is SkiaView skiaFlyout)
{
handler.PlatformView.Flyout = skiaFlyout;
}
}
public static void MapDetail(FlyoutPageHandler handler, IFlyoutView flyoutView)
{
if (handler.PlatformView is null || handler.MauiContext is null) return;
var detail = flyoutView.Detail;
if (detail == null)
{
handler.PlatformView.Detail = null;
return;
}
// Create handler for detail content
if (detail.Handler == null)
{
detail.Handler = detail.ToViewHandler(handler.MauiContext);
}
if (detail.Handler?.PlatformView is SkiaView skiaDetail)
{
handler.PlatformView.Detail = skiaDetail;
}
} }
public static void MapIsPresented(FlyoutPageHandler handler, IFlyoutView flyoutView) public static void MapIsPresented(FlyoutPageHandler handler, IFlyoutView flyoutView)
{ {
if (handler.PlatformView is null) return; if (handler.PlatformView is null || handler._isUpdatingPresented) return;
handler.PlatformView.IsPresented = flyoutView.IsPresented;
try
{
handler._isUpdatingPresented = true;
handler.PlatformView.IsPresented = flyoutView.IsPresented;
}
finally
{
handler._isUpdatingPresented = false;
}
} }
public static void MapFlyoutWidth(FlyoutPageHandler handler, IFlyoutView flyoutView) public static void MapFlyoutWidth(FlyoutPageHandler handler, IFlyoutView flyoutView)
@@ -88,4 +164,14 @@ public partial class FlyoutPageHandler : ViewHandler<IFlyoutView, SkiaFlyoutPage
_ => FlyoutLayoutBehavior.Default _ => 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);
}
}
} }

View File

@@ -1,8 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements. // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license. // The .NET Foundation licenses this file to you under the MIT license.
using Microsoft.Maui.Controls;
using Microsoft.Maui.Handlers; using Microsoft.Maui.Handlers;
using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics;
using Microsoft.Maui.Platform.Linux.Hosting;
using SkiaSharp; using SkiaSharp;
namespace Microsoft.Maui.Platform.Linux.Handlers; namespace Microsoft.Maui.Platform.Linux.Handlers;
@@ -13,8 +15,14 @@ namespace Microsoft.Maui.Platform.Linux.Handlers;
/// </summary> /// </summary>
public partial class TabbedPageHandler : ViewHandler<ITabbedView, SkiaTabbedPage> public partial class TabbedPageHandler : ViewHandler<ITabbedView, SkiaTabbedPage>
{ {
private bool _isUpdatingSelection;
public static IPropertyMapper<ITabbedView, TabbedPageHandler> Mapper = new PropertyMapper<ITabbedView, TabbedPageHandler>(ViewHandler.ViewMapper) public static IPropertyMapper<ITabbedView, TabbedPageHandler> Mapper = new PropertyMapper<ITabbedView, TabbedPageHandler>(ViewHandler.ViewMapper)
{ {
[nameof(TabbedPage.BarBackgroundColor)] = MapBarBackgroundColor,
[nameof(TabbedPage.BarTextColor)] = MapBarTextColor,
[nameof(TabbedPage.SelectedTabColor)] = MapSelectedTabColor,
[nameof(TabbedPage.UnselectedTabColor)] = MapUnselectedTabColor,
}; };
public static CommandMapper<ITabbedView, TabbedPageHandler> CommandMapper = new(ViewHandler.ViewCommandMapper) public static CommandMapper<ITabbedView, TabbedPageHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
@@ -39,6 +47,9 @@ public partial class TabbedPageHandler : ViewHandler<ITabbedView, SkiaTabbedPage
{ {
base.ConnectHandler(platformView); base.ConnectHandler(platformView);
platformView.SelectedIndexChanged += OnSelectedIndexChanged; platformView.SelectedIndexChanged += OnSelectedIndexChanged;
// Sync initial tabs
SyncTabs();
} }
protected override void DisconnectHandler(SkiaTabbedPage platformView) protected override void DisconnectHandler(SkiaTabbedPage platformView)
@@ -50,6 +61,104 @@ public partial class TabbedPageHandler : ViewHandler<ITabbedView, SkiaTabbedPage
private void OnSelectedIndexChanged(object? sender, EventArgs e) private void OnSelectedIndexChanged(object? sender, EventArgs e)
{ {
// Notify the virtual view of selection change if (VirtualView is null || PlatformView is null || _isUpdatingSelection) return;
try
{
_isUpdatingSelection = true;
// Sync selected page back to virtual view
if (VirtualView is TabbedPage tabbedPage && PlatformView.SelectedIndex >= 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();
}
} }
} }