Verify and fix handlers against decompiled production
- ImageHandler.Linux.cs: Verified matches production - ScrollViewHandler.Linux.cs: Verified matches production - StepperHandler.Linux.cs: Verified matches production - RadioButtonHandler.Linux.cs: Verified matches production - SearchBarHandler.Linux.cs: Fixed namespace, added CancelButtonColor, SolidPaint, null checks - ImageButtonHandler.cs: Verified matches production - DatePickerHandler.cs: Verified matches production - TimePickerHandler.cs: Verified matches production 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
308
Handlers/ImageHandler.Linux.cs
Normal file
308
Handlers/ImageHandler.Linux.cs
Normal file
@@ -0,0 +1,308 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using Microsoft.Maui.Handlers;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Linux handler for Image control.
|
||||
/// </summary>
|
||||
public class ImageHandler : ViewHandler<IImage, SkiaImage>
|
||||
{
|
||||
internal class ImageSourceServiceResultManager
|
||||
{
|
||||
private readonly ImageHandler _handler;
|
||||
private CancellationTokenSource? _cts;
|
||||
|
||||
public ImageSourceServiceResultManager(ImageHandler handler)
|
||||
{
|
||||
_handler = handler;
|
||||
}
|
||||
|
||||
public async void UpdateImageSourceAsync()
|
||||
{
|
||||
_cts?.Cancel();
|
||||
_cts = new CancellationTokenSource();
|
||||
var token = _cts.Token;
|
||||
|
||||
try
|
||||
{
|
||||
var source = _handler.VirtualView?.Source;
|
||||
if (source == null)
|
||||
{
|
||||
_handler.PlatformView?.LoadFromData(Array.Empty<byte>());
|
||||
return;
|
||||
}
|
||||
|
||||
if (_handler.VirtualView is IImageSourcePart imagePart)
|
||||
{
|
||||
imagePart.UpdateIsLoading(true);
|
||||
}
|
||||
|
||||
if (source is IFileImageSource fileSource)
|
||||
{
|
||||
var file = fileSource.File;
|
||||
if (!string.IsNullOrEmpty(file))
|
||||
{
|
||||
await _handler.PlatformView.LoadFromFileAsync(file);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (source is IUriImageSource uriSource)
|
||||
{
|
||||
var uri = uriSource.Uri;
|
||||
if (uri != null)
|
||||
{
|
||||
await _handler.PlatformView.LoadFromUriAsync(uri);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (source is IStreamImageSource streamSource)
|
||||
{
|
||||
var stream = await streamSource.GetStreamAsync(token);
|
||||
if (stream != null)
|
||||
{
|
||||
await _handler.PlatformView.LoadFromStreamAsync(stream);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (source is FontImageSource fontSource)
|
||||
{
|
||||
var bitmap = RenderFontImageSource(fontSource, _handler.PlatformView.WidthRequest, _handler.PlatformView.HeightRequest);
|
||||
if (bitmap != null)
|
||||
{
|
||||
_handler.PlatformView.LoadFromBitmap(bitmap);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (OperationCanceledException)
|
||||
{
|
||||
// Cancelled - ignore
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
if (_handler.VirtualView is IImageSourcePart imagePart)
|
||||
{
|
||||
imagePart.UpdateIsLoading(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static SKBitmap? RenderFontImageSource(FontImageSource fontSource, double requestedWidth, double requestedHeight)
|
||||
{
|
||||
var glyph = fontSource.Glyph;
|
||||
if (string.IsNullOrEmpty(glyph))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int size = (int)Math.Max(
|
||||
requestedWidth > 0 ? requestedWidth : 24.0,
|
||||
requestedHeight > 0 ? requestedHeight : 24.0);
|
||||
size = Math.Max(size, 16);
|
||||
|
||||
var color = fontSource.Color?.ToSKColor() ?? SKColors.Black;
|
||||
var bitmap = new SKBitmap(size, size, false);
|
||||
|
||||
using var canvas = new SKCanvas(bitmap);
|
||||
canvas.Clear(SKColors.Transparent);
|
||||
|
||||
SKTypeface? typeface = null;
|
||||
if (!string.IsNullOrEmpty(fontSource.FontFamily))
|
||||
{
|
||||
var fontPaths = new[]
|
||||
{
|
||||
"/usr/share/fonts/truetype/" + fontSource.FontFamily + ".ttf",
|
||||
"/usr/share/fonts/opentype/" + fontSource.FontFamily + ".otf",
|
||||
"/usr/local/share/fonts/" + fontSource.FontFamily + ".ttf",
|
||||
Path.Combine(AppContext.BaseDirectory, fontSource.FontFamily + ".ttf")
|
||||
};
|
||||
|
||||
foreach (var path in fontPaths)
|
||||
{
|
||||
if (File.Exists(path))
|
||||
{
|
||||
typeface = SKTypeface.FromFile(path);
|
||||
if (typeface != null)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (typeface == null)
|
||||
{
|
||||
typeface = SKTypeface.FromFamilyName(fontSource.FontFamily);
|
||||
}
|
||||
}
|
||||
|
||||
typeface ??= SKTypeface.Default;
|
||||
|
||||
float fontSize = size * 0.8f;
|
||||
using var font = new SKFont(typeface, fontSize);
|
||||
using var paint = new SKPaint(font)
|
||||
{
|
||||
Color = color,
|
||||
IsAntialias = true,
|
||||
TextAlign = SKTextAlign.Center
|
||||
};
|
||||
|
||||
var bounds = new SKRect();
|
||||
paint.MeasureText(glyph, ref bounds);
|
||||
|
||||
float x = size / 2f;
|
||||
float y = (size - bounds.Top - bounds.Bottom) / 2f;
|
||||
canvas.DrawText(glyph, x, y, paint);
|
||||
|
||||
return bitmap;
|
||||
}
|
||||
}
|
||||
|
||||
public static IPropertyMapper<IImage, ImageHandler> Mapper = new PropertyMapper<IImage, ImageHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
["Aspect"] = MapAspect,
|
||||
["IsOpaque"] = MapIsOpaque,
|
||||
["Source"] = MapSource,
|
||||
["Background"] = MapBackground,
|
||||
["Width"] = MapWidth,
|
||||
["Height"] = MapHeight
|
||||
};
|
||||
|
||||
public static CommandMapper<IImage, ImageHandler> CommandMapper = new(ViewHandler.ViewCommandMapper);
|
||||
|
||||
private ImageSourceServiceResultManager? _sourceLoader;
|
||||
private ImageSourceServiceResultManager SourceLoader => _sourceLoader ??= new ImageSourceServiceResultManager(this);
|
||||
|
||||
public ImageHandler() : base(Mapper, CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
public ImageHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
||||
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
protected override SkiaImage CreatePlatformView()
|
||||
{
|
||||
return new SkiaImage();
|
||||
}
|
||||
|
||||
protected override void ConnectHandler(SkiaImage platformView)
|
||||
{
|
||||
base.ConnectHandler(platformView);
|
||||
platformView.ImageLoaded += OnImageLoaded;
|
||||
platformView.ImageLoadingError += OnImageLoadingError;
|
||||
}
|
||||
|
||||
protected override void DisconnectHandler(SkiaImage platformView)
|
||||
{
|
||||
platformView.ImageLoaded -= OnImageLoaded;
|
||||
platformView.ImageLoadingError -= OnImageLoadingError;
|
||||
base.DisconnectHandler(platformView);
|
||||
}
|
||||
|
||||
private void OnImageLoaded(object? sender, EventArgs e)
|
||||
{
|
||||
if (VirtualView is IImageSourcePart imagePart)
|
||||
{
|
||||
imagePart.UpdateIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnImageLoadingError(object? sender, ImageLoadingErrorEventArgs e)
|
||||
{
|
||||
if (VirtualView is IImageSourcePart imagePart)
|
||||
{
|
||||
imagePart.UpdateIsLoading(false);
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapAspect(ImageHandler handler, IImage image)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.Aspect = image.Aspect;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapIsOpaque(ImageHandler handler, IImage image)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.IsOpaque = image.IsOpaque;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapSource(ImageHandler handler, IImage image)
|
||||
{
|
||||
if (handler.PlatformView == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (image is Image mauiImage)
|
||||
{
|
||||
if (mauiImage.WidthRequest > 0)
|
||||
{
|
||||
handler.PlatformView.WidthRequest = mauiImage.WidthRequest;
|
||||
}
|
||||
if (mauiImage.HeightRequest > 0)
|
||||
{
|
||||
handler.PlatformView.HeightRequest = mauiImage.HeightRequest;
|
||||
}
|
||||
}
|
||||
|
||||
handler.SourceLoader.UpdateImageSourceAsync();
|
||||
}
|
||||
|
||||
public static void MapBackground(ImageHandler handler, IImage image)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
if (image.Background is SolidPaint solidPaint && solidPaint.Color != null)
|
||||
{
|
||||
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapWidth(ImageHandler handler, IImage image)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
if (image is Image mauiImage && mauiImage.WidthRequest > 0)
|
||||
{
|
||||
handler.PlatformView.WidthRequest = mauiImage.WidthRequest;
|
||||
Console.WriteLine($"[ImageHandler] MapWidth: {mauiImage.WidthRequest}");
|
||||
}
|
||||
else if (image.Width > 0)
|
||||
{
|
||||
handler.PlatformView.WidthRequest = image.Width;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapHeight(ImageHandler handler, IImage image)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
if (image is Image mauiImage && mauiImage.HeightRequest > 0)
|
||||
{
|
||||
handler.PlatformView.HeightRequest = mauiImage.HeightRequest;
|
||||
Console.WriteLine($"[ImageHandler] MapHeight: {mauiImage.HeightRequest}");
|
||||
}
|
||||
else if (image.Height > 0)
|
||||
{
|
||||
handler.PlatformView.HeightRequest = image.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
105
Handlers/RadioButtonHandler.Linux.cs
Normal file
105
Handlers/RadioButtonHandler.Linux.cs
Normal file
@@ -0,0 +1,105 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using Microsoft.Maui.Handlers;
|
||||
|
||||
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Linux handler for RadioButton control.
|
||||
/// </summary>
|
||||
public class RadioButtonHandler : ViewHandler<IRadioButton, SkiaRadioButton>
|
||||
{
|
||||
public static IPropertyMapper<IRadioButton, RadioButtonHandler> Mapper = new PropertyMapper<IRadioButton, RadioButtonHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
["IsChecked"] = MapIsChecked,
|
||||
["TextColor"] = MapTextColor,
|
||||
["Font"] = MapFont,
|
||||
["Background"] = MapBackground
|
||||
};
|
||||
|
||||
public static CommandMapper<IRadioButton, RadioButtonHandler> CommandMapper = new(ViewHandler.ViewCommandMapper);
|
||||
|
||||
public RadioButtonHandler() : base(Mapper, CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
public RadioButtonHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
||||
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
protected override SkiaRadioButton CreatePlatformView()
|
||||
{
|
||||
return new SkiaRadioButton();
|
||||
}
|
||||
|
||||
protected override void ConnectHandler(SkiaRadioButton platformView)
|
||||
{
|
||||
base.ConnectHandler(platformView);
|
||||
platformView.CheckedChanged += OnCheckedChanged;
|
||||
|
||||
if (VirtualView is RadioButton radioButton)
|
||||
{
|
||||
platformView.Content = radioButton.Content?.ToString() ?? "";
|
||||
platformView.GroupName = radioButton.GroupName;
|
||||
platformView.Value = radioButton.Value;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DisconnectHandler(SkiaRadioButton platformView)
|
||||
{
|
||||
platformView.CheckedChanged -= OnCheckedChanged;
|
||||
base.DisconnectHandler(platformView);
|
||||
}
|
||||
|
||||
private void OnCheckedChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (VirtualView != null && PlatformView != null)
|
||||
{
|
||||
VirtualView.IsChecked = PlatformView.IsChecked;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapIsChecked(RadioButtonHandler handler, IRadioButton radioButton)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.IsChecked = radioButton.IsChecked;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapTextColor(RadioButtonHandler handler, IRadioButton radioButton)
|
||||
{
|
||||
if (handler.PlatformView != null && radioButton.TextColor != null)
|
||||
{
|
||||
handler.PlatformView.TextColor = radioButton.TextColor.ToSKColor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapFont(RadioButtonHandler handler, IRadioButton radioButton)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
var font = radioButton.Font;
|
||||
if (font.Size > 0)
|
||||
{
|
||||
handler.PlatformView.FontSize = (float)font.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapBackground(RadioButtonHandler handler, IRadioButton radioButton)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
if (radioButton.Background is SolidPaint solidPaint && solidPaint.Color != null)
|
||||
{
|
||||
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
109
Handlers/ScrollViewHandler.Linux.cs
Normal file
109
Handlers/ScrollViewHandler.Linux.cs
Normal file
@@ -0,0 +1,109 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using Microsoft.Maui.Handlers;
|
||||
using Microsoft.Maui.Platform.Linux.Hosting;
|
||||
|
||||
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Linux handler for ScrollView control.
|
||||
/// </summary>
|
||||
public class ScrollViewHandler : ViewHandler<IScrollView, SkiaScrollView>
|
||||
{
|
||||
public static IPropertyMapper<IScrollView, ScrollViewHandler> Mapper = new PropertyMapper<IScrollView, ScrollViewHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
["Content"] = MapContent,
|
||||
["HorizontalScrollBarVisibility"] = MapHorizontalScrollBarVisibility,
|
||||
["VerticalScrollBarVisibility"] = MapVerticalScrollBarVisibility,
|
||||
["Orientation"] = MapOrientation
|
||||
};
|
||||
|
||||
public static CommandMapper<IScrollView, ScrollViewHandler> CommandMapper = new(ViewHandler.ViewCommandMapper)
|
||||
{
|
||||
["RequestScrollTo"] = MapRequestScrollTo
|
||||
};
|
||||
|
||||
public ScrollViewHandler() : base(Mapper, CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
public ScrollViewHandler(IPropertyMapper? mapper)
|
||||
: base(mapper ?? Mapper, CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
protected override SkiaScrollView CreatePlatformView()
|
||||
{
|
||||
return new SkiaScrollView();
|
||||
}
|
||||
|
||||
public static void MapContent(ScrollViewHandler handler, IScrollView scrollView)
|
||||
{
|
||||
if (handler.PlatformView == null || handler.MauiContext == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var presentedContent = scrollView.PresentedContent;
|
||||
if (presentedContent != null)
|
||||
{
|
||||
Console.WriteLine("[ScrollViewHandler] MapContent: " + presentedContent.GetType().Name);
|
||||
|
||||
if (presentedContent.Handler == null)
|
||||
{
|
||||
presentedContent.Handler = presentedContent.ToViewHandler(handler.MauiContext);
|
||||
}
|
||||
|
||||
if (presentedContent.Handler?.PlatformView is SkiaView skiaView)
|
||||
{
|
||||
Console.WriteLine("[ScrollViewHandler] Setting content: " + skiaView.GetType().Name);
|
||||
handler.PlatformView.Content = skiaView;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
handler.PlatformView.Content = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapHorizontalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView)
|
||||
{
|
||||
handler.PlatformView.HorizontalScrollBarVisibility = (int)scrollView.HorizontalScrollBarVisibility switch
|
||||
{
|
||||
1 => ScrollBarVisibility.Always,
|
||||
2 => ScrollBarVisibility.Never,
|
||||
_ => ScrollBarVisibility.Default
|
||||
};
|
||||
}
|
||||
|
||||
public static void MapVerticalScrollBarVisibility(ScrollViewHandler handler, IScrollView scrollView)
|
||||
{
|
||||
handler.PlatformView.VerticalScrollBarVisibility = (int)scrollView.VerticalScrollBarVisibility switch
|
||||
{
|
||||
1 => ScrollBarVisibility.Always,
|
||||
2 => ScrollBarVisibility.Never,
|
||||
_ => ScrollBarVisibility.Default
|
||||
};
|
||||
}
|
||||
|
||||
public static void MapOrientation(ScrollViewHandler handler, IScrollView scrollView)
|
||||
{
|
||||
handler.PlatformView.Orientation = ((int)scrollView.Orientation - 1) switch
|
||||
{
|
||||
0 => ScrollOrientation.Horizontal,
|
||||
1 => ScrollOrientation.Both,
|
||||
2 => ScrollOrientation.Neither,
|
||||
_ => ScrollOrientation.Vertical
|
||||
};
|
||||
}
|
||||
|
||||
public static void MapRequestScrollTo(ScrollViewHandler handler, IScrollView scrollView, object? args)
|
||||
{
|
||||
if (args is ScrollToRequest request)
|
||||
{
|
||||
handler.PlatformView.ScrollTo((float)request.HorizontalOffset, (float)request.VerticalOffset, !request.Instant);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +1,43 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using Microsoft.Maui.Handlers;
|
||||
|
||||
namespace Microsoft.Maui.Platform;
|
||||
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Linux handler for SearchBar control.
|
||||
/// </summary>
|
||||
public partial class SearchBarHandler : ViewHandler<ISearchBar, SkiaSearchBar>
|
||||
public class SearchBarHandler : ViewHandler<ISearchBar, SkiaSearchBar>
|
||||
{
|
||||
public static IPropertyMapper<ISearchBar, SearchBarHandler> Mapper = new PropertyMapper<ISearchBar, SearchBarHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
[nameof(ISearchBar.Text)] = MapText,
|
||||
[nameof(ISearchBar.Placeholder)] = MapPlaceholder,
|
||||
[nameof(ISearchBar.PlaceholderColor)] = MapPlaceholderColor,
|
||||
[nameof(ISearchBar.TextColor)] = MapTextColor,
|
||||
[nameof(ISearchBar.Font)] = MapFont,
|
||||
[nameof(IView.IsEnabled)] = MapIsEnabled,
|
||||
[nameof(IView.Background)] = MapBackground,
|
||||
["Text"] = MapText,
|
||||
["TextColor"] = MapTextColor,
|
||||
["Font"] = MapFont,
|
||||
["Placeholder"] = MapPlaceholder,
|
||||
["PlaceholderColor"] = MapPlaceholderColor,
|
||||
["CancelButtonColor"] = MapCancelButtonColor,
|
||||
["Background"] = MapBackground
|
||||
};
|
||||
|
||||
public static CommandMapper<ISearchBar, SearchBarHandler> CommandMapper = new(ViewHandler.ViewCommandMapper);
|
||||
|
||||
public SearchBarHandler() : base(Mapper, CommandMapper) { }
|
||||
public SearchBarHandler() : base(Mapper, CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
protected override SkiaSearchBar CreatePlatformView() => new SkiaSearchBar();
|
||||
public SearchBarHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
||||
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
protected override SkiaSearchBar CreatePlatformView()
|
||||
{
|
||||
return new SkiaSearchBar();
|
||||
}
|
||||
|
||||
protected override void ConnectHandler(SkiaSearchBar platformView)
|
||||
{
|
||||
@@ -43,9 +55,9 @@ public partial class SearchBarHandler : ViewHandler<ISearchBar, SkiaSearchBar>
|
||||
|
||||
private void OnTextChanged(object? sender, TextChangedEventArgs e)
|
||||
{
|
||||
if (VirtualView != null && VirtualView.Text != e.NewText)
|
||||
if (VirtualView != null && PlatformView != null && VirtualView.Text != e.NewTextValue)
|
||||
{
|
||||
VirtualView.Text = e.NewText;
|
||||
VirtualView.Text = e.NewTextValue ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,51 +68,68 @@ public partial class SearchBarHandler : ViewHandler<ISearchBar, SkiaSearchBar>
|
||||
|
||||
public static void MapText(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
if (handler.PlatformView.Text != searchBar.Text)
|
||||
if (handler.PlatformView != null && handler.PlatformView.Text != searchBar.Text)
|
||||
{
|
||||
handler.PlatformView.Text = searchBar.Text ?? "";
|
||||
handler.PlatformView.Text = searchBar.Text ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapTextColor(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
if (handler.PlatformView != null && searchBar.TextColor != null)
|
||||
{
|
||||
handler.PlatformView.TextColor = searchBar.TextColor.ToSKColor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapFont(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
var font = searchBar.Font;
|
||||
if (font.Size > 0)
|
||||
{
|
||||
handler.PlatformView.FontSize = (float)font.Size;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(font.Family))
|
||||
{
|
||||
handler.PlatformView.FontFamily = font.Family;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapPlaceholder(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
handler.PlatformView.Placeholder = searchBar.Placeholder ?? "";
|
||||
handler.PlatformView.Invalidate();
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.Placeholder = searchBar.Placeholder ?? string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapPlaceholderColor(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
if (searchBar.PlaceholderColor != null)
|
||||
if (handler.PlatformView != null && searchBar.PlaceholderColor != null)
|
||||
{
|
||||
handler.PlatformView.PlaceholderColor = searchBar.PlaceholderColor.ToSKColor();
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapTextColor(SearchBarHandler handler, ISearchBar searchBar)
|
||||
public static void MapCancelButtonColor(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
if (searchBar.TextColor != null)
|
||||
handler.PlatformView.TextColor = searchBar.TextColor.ToSKColor();
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
|
||||
public static void MapFont(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
var font = searchBar.Font;
|
||||
if (font.Family != null)
|
||||
handler.PlatformView.FontFamily = font.Family;
|
||||
handler.PlatformView.FontSize = (float)font.Size;
|
||||
handler.PlatformView.Invalidate();
|
||||
}
|
||||
|
||||
public static void MapIsEnabled(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
handler.PlatformView.IsEnabled = searchBar.IsEnabled;
|
||||
handler.PlatformView.Invalidate();
|
||||
if (handler.PlatformView != null && searchBar.CancelButtonColor != null)
|
||||
{
|
||||
handler.PlatformView.ClearButtonColor = searchBar.CancelButtonColor.ToSKColor();
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapBackground(SearchBarHandler handler, ISearchBar searchBar)
|
||||
{
|
||||
if (searchBar.Background is SolidColorBrush solidBrush && solidBrush.Color != null)
|
||||
handler.PlatformView.BackgroundColor = solidBrush.Color.ToSKColor();
|
||||
handler.PlatformView.Invalidate();
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
if (searchBar.Background is SolidPaint solidPaint && solidPaint.Color != null)
|
||||
{
|
||||
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
127
Handlers/StepperHandler.Linux.cs
Normal file
127
Handlers/StepperHandler.Linux.cs
Normal file
@@ -0,0 +1,127 @@
|
||||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using Microsoft.Maui.Controls;
|
||||
using Microsoft.Maui.Graphics;
|
||||
using Microsoft.Maui.Handlers;
|
||||
using SkiaSharp;
|
||||
|
||||
namespace Microsoft.Maui.Platform.Linux.Handlers;
|
||||
|
||||
/// <summary>
|
||||
/// Linux handler for Stepper control.
|
||||
/// </summary>
|
||||
public class StepperHandler : ViewHandler<IStepper, SkiaStepper>
|
||||
{
|
||||
public static IPropertyMapper<IStepper, StepperHandler> Mapper = new PropertyMapper<IStepper, StepperHandler>(ViewHandler.ViewMapper)
|
||||
{
|
||||
["Value"] = MapValue,
|
||||
["Minimum"] = MapMinimum,
|
||||
["Maximum"] = MapMaximum,
|
||||
["Increment"] = MapIncrement,
|
||||
["Background"] = MapBackground,
|
||||
["IsEnabled"] = MapIsEnabled
|
||||
};
|
||||
|
||||
public static CommandMapper<IStepper, StepperHandler> CommandMapper = new(ViewHandler.ViewCommandMapper);
|
||||
|
||||
public StepperHandler() : base(Mapper, CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
public StepperHandler(IPropertyMapper? mapper, CommandMapper? commandMapper = null)
|
||||
: base(mapper ?? Mapper, commandMapper ?? CommandMapper)
|
||||
{
|
||||
}
|
||||
|
||||
protected override SkiaStepper CreatePlatformView()
|
||||
{
|
||||
return new SkiaStepper();
|
||||
}
|
||||
|
||||
protected override void ConnectHandler(SkiaStepper platformView)
|
||||
{
|
||||
base.ConnectHandler(platformView);
|
||||
platformView.ValueChanged += OnValueChanged;
|
||||
|
||||
// Apply dark theme colors if needed
|
||||
if (Application.Current?.UserAppTheme == AppTheme.Dark)
|
||||
{
|
||||
platformView.ButtonBackgroundColor = new SKColor(66, 66, 66);
|
||||
platformView.ButtonPressedColor = new SKColor(97, 97, 97);
|
||||
platformView.ButtonDisabledColor = new SKColor(48, 48, 48);
|
||||
platformView.SymbolColor = new SKColor(224, 224, 224);
|
||||
platformView.SymbolDisabledColor = new SKColor(97, 97, 97);
|
||||
platformView.BorderColor = new SKColor(97, 97, 97);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void DisconnectHandler(SkiaStepper platformView)
|
||||
{
|
||||
platformView.ValueChanged -= OnValueChanged;
|
||||
base.DisconnectHandler(platformView);
|
||||
}
|
||||
|
||||
private void OnValueChanged(object? sender, EventArgs e)
|
||||
{
|
||||
if (VirtualView != null && PlatformView != null)
|
||||
{
|
||||
VirtualView.Value = PlatformView.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapValue(StepperHandler handler, IStepper stepper)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.Value = stepper.Value;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapMinimum(StepperHandler handler, IStepper stepper)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.Minimum = stepper.Minimum;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapMaximum(StepperHandler handler, IStepper stepper)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.Maximum = stepper.Maximum;
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapBackground(StepperHandler handler, IStepper stepper)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
if (stepper.Background is SolidPaint solidPaint && solidPaint.Color != null)
|
||||
{
|
||||
handler.PlatformView.BackgroundColor = solidPaint.Color.ToSKColor();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapIncrement(StepperHandler handler, IStepper stepper)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
if (stepper is Stepper mauiStepper)
|
||||
{
|
||||
handler.PlatformView.Increment = mauiStepper.Increment;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void MapIsEnabled(StepperHandler handler, IStepper stepper)
|
||||
{
|
||||
if (handler.PlatformView != null)
|
||||
{
|
||||
handler.PlatformView.IsEnabled = stepper.IsEnabled;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user