diff --git a/src/Core/src/Platform/ElementExtensions.cs b/src/Core/src/Platform/ElementExtensions.cs index 01d664339c67..c39b7ca5a4cf 100644 --- a/src/Core/src/Platform/ElementExtensions.cs +++ b/src/Core/src/Platform/ElementExtensions.cs @@ -89,7 +89,7 @@ public static IElementHandler ToHandler(this IElement view, IMauiContext context } if (handler == null) - throw new Exception($"Handler not found for view {view}."); + throw new HandlerNotFoundException($"Handler not found for view {view}."); handler.SetMauiContext(context); @@ -104,6 +104,10 @@ public static IElementHandler ToHandler(this IElement view, IMauiContext context { throw; } + catch (HandlerNotFoundException) + { + throw; + } catch (Exception exc) { throw new ToPlatformException($"{handler} found for {view} is incompatible", exc); diff --git a/src/Core/src/Platform/HandlerNotFoundException.cs b/src/Core/src/Platform/HandlerNotFoundException.cs new file mode 100644 index 000000000000..ca130ce600fe --- /dev/null +++ b/src/Core/src/Platform/HandlerNotFoundException.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Runtime.Serialization; +using System.Text; + +namespace Microsoft.Maui.Platform +{ + class HandlerNotFoundException : System.Exception + { + public HandlerNotFoundException() + { + } + + public HandlerNotFoundException(string message) : base(message) + { + } + + public HandlerNotFoundException(string message, Exception innerException) : base(message, innerException) + { + } + + protected HandlerNotFoundException(SerializationInfo info, StreamingContext context) : base(info, context) + { + } + } +} diff --git a/src/Core/src/Platform/iOS/MauiCheckBox.cs b/src/Core/src/Platform/iOS/MauiCheckBox.cs index f975d42e2b93..13eff5c3995b 100644 --- a/src/Core/src/Platform/iOS/MauiCheckBox.cs +++ b/src/Core/src/Platform/iOS/MauiCheckBox.cs @@ -14,6 +14,9 @@ public class MauiCheckBox : UIButton static UIImage? Checked; static UIImage? Unchecked; + UIImage? CheckedDisabledAndTinted; + UIImage? UncheckedDisabledAndTinted; + UIAccessibilityTrait _accessibilityTraits; Color? _tintColor; @@ -91,6 +94,8 @@ public Color? CheckBoxTintColor if (_tintColor == value) return; + CheckedDisabledAndTinted = null; + UncheckedDisabledAndTinted = null; _tintColor = value; CheckBoxTintUIColor = CheckBoxTintColor?.ToPlatform(); } @@ -136,43 +141,44 @@ public override bool Enabled } } - protected virtual UIImage GetCheckBoximage() + protected virtual UIImage GetCheckBoxImage() { // Ideally I would use the static images here but when disabled it always tints them grey // and I don't know how to make it not tint them gray if (!Enabled && CheckBoxTintColor != null) { if (IsChecked) - return CreateCheckBox(CreateCheckMark()).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); + { + return CheckedDisabledAndTinted ??= + CreateCheckBox(CreateCheckMark()).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); + } - return CreateCheckBox(null).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); + return UncheckedDisabledAndTinted ??= + CreateCheckBox(null).ImageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal); } - if (Checked == null) - Checked = CreateCheckBox(CreateCheckMark()).ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); - - if (Unchecked == null) - Unchecked = CreateCheckBox(null).ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); + Checked ??= CreateCheckBox(CreateCheckMark()).ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); + Unchecked ??= CreateCheckBox(null).ImageWithRenderingMode(UIImageRenderingMode.AlwaysTemplate); return IsChecked ? Checked : Unchecked; } - internal virtual UIBezierPath CreateBoxPath(CGRect backgroundRect) => UIBezierPath.FromOval(backgroundRect); - internal virtual UIBezierPath CreateCheckPath() => new UIBezierPath + UIBezierPath CreateBoxPath(CGRect backgroundRect) => UIBezierPath.FromOval(backgroundRect); + UIBezierPath CreateCheckPath() => new UIBezierPath { LineWidth = (nfloat)0.077, LineCapStyle = CGLineCap.Round, LineJoinStyle = CGLineJoin.Round }; - internal virtual void DrawCheckMark(UIBezierPath path) + void DrawCheckMark(UIBezierPath path) { path.MoveTo(new CGPoint(0.72f, 0.22f)); path.AddLineTo(new CGPoint(0.33f, 0.6f)); path.AddLineTo(new CGPoint(0.15f, 0.42f)); } - internal virtual UIImage CreateCheckBox(UIImage? check) + UIImage CreateCheckBox(UIImage? check) { UIGraphics.BeginImageContextWithOptions(new CGSize(DefaultSize, DefaultSize), false, 0); var context = UIGraphics.GetCurrentContext(); @@ -208,7 +214,7 @@ internal virtual UIImage CreateCheckBox(UIImage? check) return img; } - internal UIImage CreateCheckMark() + UIImage CreateCheckMark() { UIGraphics.BeginImageContextWithOptions(new CGSize(DefaultSize, DefaultSize), false, 0); var context = UIGraphics.GetCurrentContext(); @@ -263,7 +269,7 @@ protected override void Dispose(bool disposing) void UpdateDisplay() { - SetImage(GetCheckBoximage(), UIControlState.Normal); + SetImage(GetCheckBoxImage(), UIControlState.Normal); SetNeedsDisplay(); }