2025-12-19 09:30:16 +00:00
|
|
|
// 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.Handlers;
|
|
|
|
|
using Microsoft.Maui.Graphics;
|
2026-01-16 05:03:49 +00:00
|
|
|
using Microsoft.Maui.Platform;
|
2025-12-19 09:30:16 +00:00
|
|
|
|
|
|
|
|
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Handler for ActivityIndicator on Linux using Skia rendering.
|
|
|
|
|
/// Maps IActivityIndicator interface to SkiaActivityIndicator platform view.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class ActivityIndicatorHandler : ViewHandler<IActivityIndicator, SkiaActivityIndicator>
|
|
|
|
|
{
|
|
|
|
|
public static IPropertyMapper<IActivityIndicator, ActivityIndicatorHandler> Mapper = new PropertyMapper<IActivityIndicator, ActivityIndicatorHandler>(ViewHandler.ViewMapper)
|
|
|
|
|
{
|
|
|
|
|
[nameof(IActivityIndicator.IsRunning)] = MapIsRunning,
|
|
|
|
|
[nameof(IActivityIndicator.Color)] = MapColor,
|
|
|
|
|
[nameof(IView.Background)] = MapBackground,
|
2026-01-16 05:03:49 +00:00
|
|
|
[nameof(IView.IsEnabled)] = MapIsEnabled,
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static CommandMapper<IActivityIndicator, ActivityIndicatorHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
|
|
|
|
|
{
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public ActivityIndicatorHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ActivityIndicatorHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
|
|
|
|
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaActivityIndicator CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaActivityIndicator();
|
|
|
|
|
}
|
|
|
|
|
|
2026-01-16 05:03:49 +00:00
|
|
|
protected override void ConnectHandler(SkiaActivityIndicator platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
|
|
|
|
|
|
|
|
|
// Sync properties
|
|
|
|
|
if (VirtualView != null)
|
|
|
|
|
{
|
|
|
|
|
MapIsRunning(this, VirtualView);
|
|
|
|
|
MapColor(this, VirtualView);
|
|
|
|
|
MapIsEnabled(this, VirtualView);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-19 09:30:16 +00:00
|
|
|
public static void MapIsRunning(ActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.IsRunning = activityIndicator.IsRunning;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapColor(ActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (activityIndicator.Color is not null)
|
2026-01-16 05:03:49 +00:00
|
|
|
handler.PlatformView.Color = activityIndicator.Color;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackground(ActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
|
|
|
|
|
if (activityIndicator.Background is SolidPaint solidPaint && solidPaint.Color is not null)
|
|
|
|
|
{
|
2026-01-17 03:10:29 +00:00
|
|
|
handler.PlatformView.BackgroundColor = solidPaint.Color;
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|
|
|
|
|
}
|
2026-01-16 05:03:49 +00:00
|
|
|
|
|
|
|
|
public static void MapIsEnabled(ActivityIndicatorHandler handler, IActivityIndicator activityIndicator)
|
|
|
|
|
{
|
|
|
|
|
if (handler.PlatformView is null) return;
|
|
|
|
|
handler.PlatformView.IsEnabled = activityIndicator.IsEnabled;
|
|
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|