Improve shared MAUI controls and tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
#if ANDROID
|
||||
#if ANDROID
|
||||
using Microsoft.Maui.Controls.Compatibility.Platform.Android;
|
||||
#endif
|
||||
using Sarand.Net.Mobile.Maui.Controls;
|
||||
@@ -10,26 +10,25 @@ using System.Threading.Tasks;
|
||||
|
||||
namespace Sarand.Net.Mobile.Maui.Handlers
|
||||
{
|
||||
//========================================================================
|
||||
// Ref. https://dev.to/vhugogarcia/remove-entry-and-picker-borders-in-net-maui-2pk2
|
||||
// Ref. https://github.com/dotnet/maui/issues/7906
|
||||
|
||||
public static class SamFormHandler
|
||||
{
|
||||
//--------------------------------------------------------------------
|
||||
// Definitions.
|
||||
// --- Control handler registration ---
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/// <summary>
|
||||
/// Remove borders around entry and picker controls.
|
||||
/// Apply configured native styling to Sam entry, editor, and picker controls.
|
||||
/// <para>Also make background transparent.</para>
|
||||
/// </summary>
|
||||
public static void AssignControlHandlers()
|
||||
{
|
||||
//---------------------------------------------------------------
|
||||
// Entry handler.
|
||||
// --- Entry handler ---
|
||||
|
||||
Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping("SamEntryHandler", (handler, view) =>
|
||||
{
|
||||
if ((view as SamEntry)?.NativeNoBorder ?? false)
|
||||
if (view is not ISamNativeControlStyle style) return;
|
||||
if (style.NativeNoBorder)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
|
||||
@@ -40,15 +39,17 @@ namespace Sarand.Net.Mobile.Maui.Handlers
|
||||
handler.PlatformView.BorderThickness = new Microsoft.UI.Xaml.Thickness() { Bottom = 0, Top = 0, Left = 0, Right = 0, };
|
||||
#endif
|
||||
}
|
||||
if ((view as SamEntry)?.NativeNoUnderline ?? false)
|
||||
if (style.NativeNoUnderline)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
|
||||
#elif IOS || MACCATALYST
|
||||
// UITextField/UITextView do not expose a separate Android-style underline.
|
||||
#elif WINDOWS
|
||||
// WinUI text controls use a border, not a separate underline; use NativeNoBorder to remove it.
|
||||
#endif
|
||||
}
|
||||
if ((view as SamEntry)?.NativeBackgroundClear ?? false)
|
||||
if (style.NativeBackgroundClear)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.Background = null;
|
||||
@@ -56,34 +57,37 @@ namespace Sarand.Net.Mobile.Maui.Handlers
|
||||
#elif IOS || MACCATALYST
|
||||
handler.PlatformView.BackgroundColor = UIKit.UIColor.Clear;
|
||||
#elif WINDOWS
|
||||
handler.PlatformView.Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Editor handler.
|
||||
// --- Editor handler ---
|
||||
|
||||
Microsoft.Maui.Handlers.EditorHandler.Mapper.AppendToMapping("SamEditorHandler", (handler, view) =>
|
||||
{
|
||||
if ((view as SamEditor)?.NativeNoBorder ?? false)
|
||||
if (view is not ISamNativeControlStyle style) return;
|
||||
if (style.NativeNoBorder)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
|
||||
#elif IOS || MACCATALYST
|
||||
handler.PlatformView.Layer.BorderWidth = 0;
|
||||
//handler.PlatformView.BorderStyle = UIKit.UITextViewBorderStyle.None;
|
||||
#elif WINDOWS
|
||||
handler.PlatformView.BorderThickness = new Microsoft.UI.Xaml.Thickness() { Bottom = 0, Top = 0, Left = 0, Right = 0, };
|
||||
#endif
|
||||
}
|
||||
if ((view as SamEntry)?.NativeNoUnderline ?? false)
|
||||
if (style.NativeNoUnderline)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
|
||||
#elif IOS || MACCATALYST
|
||||
// UITextView has no separate underline to remove.
|
||||
#elif WINDOWS
|
||||
// WinUI text controls use a border, not a separate underline; use NativeNoBorder to remove it.
|
||||
#endif
|
||||
}
|
||||
if ((view as SamEntry)?.NativeBackgroundClear ?? false)
|
||||
if (style.NativeBackgroundClear)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.Background = null;
|
||||
@@ -91,15 +95,17 @@ namespace Sarand.Net.Mobile.Maui.Handlers
|
||||
#elif IOS || MACCATALYST
|
||||
handler.PlatformView.BackgroundColor = UIKit.UIColor.Clear;
|
||||
#elif WINDOWS
|
||||
handler.PlatformView.Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Picker handler.
|
||||
Microsoft.Maui.Handlers.PickerHandler.Mapper.AppendToMapping("Borderless", (handler, view) =>
|
||||
// --- Picker handler ---
|
||||
|
||||
Microsoft.Maui.Handlers.PickerHandler.Mapper.AppendToMapping("SamPickerHandler", (handler, view) =>
|
||||
{
|
||||
if ((view as SamEditor)?.NativeNoBorder ?? false)
|
||||
if (view is not ISamNativeControlStyle style) return;
|
||||
if (style.NativeNoBorder)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
|
||||
@@ -110,15 +116,17 @@ namespace Sarand.Net.Mobile.Maui.Handlers
|
||||
handler.PlatformView.BorderThickness = new Microsoft.UI.Xaml.Thickness() { Bottom = 0, Top = 0, Left = 0, Right = 0, };
|
||||
#endif
|
||||
}
|
||||
if ((view as SamEntry)?.NativeNoUnderline ?? false)
|
||||
if (style.NativeNoUnderline)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.BackgroundTintList = Android.Content.Res.ColorStateList.ValueOf(Colors.Transparent.ToAndroid());
|
||||
#elif IOS || MACCATALYST
|
||||
// The native picker has a full border, not a separate underline; use NativeNoBorder to remove it.
|
||||
#elif WINDOWS
|
||||
// The WinUI picker has a full border, not a separate underline; use NativeNoBorder to remove it.
|
||||
#endif
|
||||
}
|
||||
if ((view as SamEntry)?.NativeBackgroundClear ?? false)
|
||||
if (style.NativeBackgroundClear)
|
||||
{
|
||||
#if ANDROID
|
||||
handler.PlatformView.Background = null;
|
||||
@@ -126,14 +134,13 @@ namespace Sarand.Net.Mobile.Maui.Handlers
|
||||
#elif IOS || MACCATALYST
|
||||
handler.PlatformView.BackgroundColor = UIKit.UIColor.Clear;
|
||||
#elif WINDOWS
|
||||
handler.PlatformView.Background = new Microsoft.UI.Xaml.Media.SolidColorBrush(Microsoft.UI.Colors.Transparent);
|
||||
#endif
|
||||
}
|
||||
});
|
||||
|
||||
//---------------------------------------------------------------
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
// --- The End ---
|
||||
}
|
||||
//========================================================================
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user