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.
|
|
|
|
|
|
2026-01-01 13:51:12 -05:00
|
|
|
using System.ComponentModel;
|
|
|
|
|
using Microsoft.Maui.Controls;
|
|
|
|
|
using Microsoft.Maui.Graphics;
|
2025-12-19 09:30:16 +00:00
|
|
|
using Microsoft.Maui.Handlers;
|
|
|
|
|
|
2026-01-01 13:51:12 -05:00
|
|
|
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
2025-12-19 09:30:16 +00:00
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Linux handler for ProgressBar control.
|
|
|
|
|
/// </summary>
|
2026-01-01 13:51:12 -05:00
|
|
|
public class ProgressBarHandler : ViewHandler<IProgress, SkiaProgressBar>
|
2025-12-19 09:30:16 +00:00
|
|
|
{
|
|
|
|
|
public static IPropertyMapper<IProgress, ProgressBarHandler> Mapper = new PropertyMapper<IProgress, ProgressBarHandler>(ViewHandler.ViewMapper)
|
|
|
|
|
{
|
2026-01-01 13:51:12 -05:00
|
|
|
["Progress"] = MapProgress,
|
|
|
|
|
["ProgressColor"] = MapProgressColor,
|
|
|
|
|
["IsEnabled"] = MapIsEnabled,
|
|
|
|
|
["Background"] = MapBackground,
|
|
|
|
|
["BackgroundColor"] = MapBackgroundColor
|
2025-12-19 09:30:16 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static CommandMapper<IProgress, ProgressBarHandler> CommandMapper = new(ViewHandler.ViewCommandMapper);
|
|
|
|
|
|
2026-01-01 13:51:12 -05:00
|
|
|
public ProgressBarHandler() : base(Mapper, CommandMapper)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override SkiaProgressBar CreatePlatformView()
|
|
|
|
|
{
|
|
|
|
|
return new SkiaProgressBar();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void ConnectHandler(SkiaProgressBar platformView)
|
|
|
|
|
{
|
|
|
|
|
base.ConnectHandler(platformView);
|
|
|
|
|
|
|
|
|
|
if (VirtualView is BindableObject bindable)
|
|
|
|
|
{
|
|
|
|
|
bindable.PropertyChanged += OnVirtualViewPropertyChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (VirtualView is VisualElement ve)
|
|
|
|
|
{
|
|
|
|
|
platformView.IsVisible = ve.IsVisible;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
|
2026-01-01 13:51:12 -05:00
|
|
|
protected override void DisconnectHandler(SkiaProgressBar platformView)
|
|
|
|
|
{
|
|
|
|
|
if (VirtualView is BindableObject bindable)
|
|
|
|
|
{
|
|
|
|
|
bindable.PropertyChanged -= OnVirtualViewPropertyChanged;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
base.DisconnectHandler(platformView);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnVirtualViewPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (VirtualView is VisualElement ve && e.PropertyName == "IsVisible")
|
|
|
|
|
{
|
|
|
|
|
PlatformView.IsVisible = ve.IsVisible;
|
|
|
|
|
PlatformView.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
|
|
|
|
|
public static void MapProgress(ProgressBarHandler handler, IProgress progress)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.Progress = progress.Progress;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapProgressColor(ProgressBarHandler handler, IProgress progress)
|
|
|
|
|
{
|
|
|
|
|
if (progress.ProgressColor != null)
|
2026-01-01 13:51:12 -05:00
|
|
|
{
|
2025-12-19 09:30:16 +00:00
|
|
|
handler.PlatformView.ProgressColor = progress.ProgressColor.ToSKColor();
|
2026-01-01 13:51:12 -05:00
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapIsEnabled(ProgressBarHandler handler, IProgress progress)
|
|
|
|
|
{
|
|
|
|
|
handler.PlatformView.IsEnabled = progress.IsEnabled;
|
|
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
2025-12-21 13:26:56 -05:00
|
|
|
|
|
|
|
|
public static void MapBackground(ProgressBarHandler handler, IProgress progress)
|
|
|
|
|
{
|
2026-01-01 13:51:12 -05:00
|
|
|
if (progress.Background is SolidPaint solidPaint && solidPaint.Color != null)
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
2026-01-01 13:51:12 -05:00
|
|
|
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
2025-12-21 13:26:56 -05:00
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static void MapBackgroundColor(ProgressBarHandler handler, IProgress progress)
|
|
|
|
|
{
|
2026-01-01 13:51:12 -05:00
|
|
|
if (progress is VisualElement ve && ve.BackgroundColor != null)
|
2025-12-21 13:26:56 -05:00
|
|
|
{
|
|
|
|
|
handler.PlatformView.BackgroundColor = ve.BackgroundColor.ToSKColor();
|
|
|
|
|
handler.PlatformView.Invalidate();
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-12-19 09:30:16 +00:00
|
|
|
}
|