public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode) { if (drawable == null) { return; } if (PlatformVersion.Supports(PlatformApis.BlendModeColorFilter)) { BlendMode?filterMode29 = GetFilterMode(mode); if (filterMode29 != null) { drawable.SetColorFilter(new BlendModeColorFilter(color, filterMode29)); } } else { #pragma warning disable CS0612 // Type or member is obsolete PorterDuff.Mode?filterModePre29 = GetFilterModePre29(mode); #pragma warning restore CS0612 // Type or member is obsolete if (filterModePre29 != null) #pragma warning disable CS0618 // Type or member is obsolete { drawable.SetColorFilter(color, filterModePre29); } #pragma warning restore CS0618 // Type or member is obsolete } }
public static void UpdateTrackColor(this UISwitch uiSwitch, ISwitch view) { if (view == null) { return; } if (view.TrackColor != null) { uiSwitch.OnTintColor = view.TrackColor.ToPlatform(); } UIView uIView; if (PlatformVersion.IsAtLeast(13)) { uIView = uiSwitch.Subviews[0].Subviews[0]; } else { uIView = uiSwitch.Subviews[0].Subviews[0].Subviews[0]; } if (view.TrackColor != null) { uIView.BackgroundColor = uiSwitch.OnTintColor; } }
void UpdateSquareShape() { if (!PlatformVersion.IsAtLeast(14)) { UpdateCornerRadius(); return; } var uiPageControlContentView = Subviews[0]; if (uiPageControlContentView.Subviews.Length > 0) { var uiPageControlIndicatorContentView = uiPageControlContentView.Subviews[0]; foreach (var view in uiPageControlIndicatorContentView.Subviews) { if (view is UIImageView imageview) { imageview.Image = UIImage.GetSystemImage("squareshape.fill"); var frame = imageview.Frame; //the square shape is not the same size as the circle so we might need to correct the frame imageview.Frame = new CGRect(frame.X - 6, frame.Y, frame.Width, frame.Height); } } } }
public MauiPageControl() { ValueChanged += MauiPageControlValueChanged; if (PlatformVersion.IsAtLeast(14)) { AllowsContinuousInteraction = false; BackgroundStyle = UIPageControlBackgroundStyle.Minimal; } }
public static void UpdateTextHtml(this TextView textView, ILabel label) { var newText = label.Text ?? string.Empty; if (PlatformVersion.IsAtLeast(24)) { textView.SetText(Html.FromHtml(newText, FromHtmlOptions.ModeCompact), BufferType.Spannable); } else #pragma warning disable CS0618 // Type or member is obsolete { textView.SetText(Html.FromHtml(newText), BufferType.Spannable); } #pragma warning restore CS0618 // Type or member is obsolete }
internal static UIView GetTrackSubview(this UISwitch uISwitch) { UIView uIView; if (PlatformVersion.IsAtLeast(13)) { uIView = uISwitch.Subviews[0].Subviews[0]; } else { uIView = uISwitch.Subviews[0].Subviews[0].Subviews[0]; } return(uIView); }
void MauiPageControlValueChanged(object?sender, System.EventArgs e) { if (_updatingPosition || _indicatorView == null) { return; } _indicatorView.Position = (int)CurrentPage; //if we are iOS13 or lower and we are using a Square shape //we need to update the CornerRadius of the new shape. if (IsSquare && !PlatformVersion.IsAtLeast(14)) { LayoutSubviews(); } }
public MauiTimePicker(Action dateSelected) { BorderStyle = UITextBorderStyle.RoundedRect; _picker = new UIDatePicker { Mode = UIDatePickerMode.Time, TimeZone = new NSTimeZone("UTC") }; _dateSelected = dateSelected; if (PlatformVersion.IsAtLeast(14)) { _picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels; } var width = UIScreen.MainScreen.Bounds.Width; var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44)) { BarStyle = UIBarStyle.Default, Translucent = true }; var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace); var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) => { DateSelected?.Invoke(this, EventArgs.Empty); _dateSelected?.Invoke(); }); toolbar.SetItems(new[] { spacer, doneButton }, false); InputView = _picker; InputAccessoryView = toolbar; InputView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight; InputAccessoryView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight; InputAssistantItem.LeadingBarButtonGroups = null; InputAssistantItem.TrailingBarButtonGroups = null; AccessibilityTraits = UIAccessibilityTrait.Button; }
public static void RequestNewWindow(this Application platformApplication, IApplication application, OpenWindowRequest?args) { if (application.Handler?.MauiContext is not IMauiContext applicationContext) { return; } var state = args?.State; var bundle = state.ToBundle(); var pm = platformApplication.PackageManager !; var intent = pm.GetLaunchIntentForPackage(platformApplication.PackageName !) !; intent.AddFlags(ActivityFlags.NewTask); intent.AddFlags(ActivityFlags.MultipleTask); if (PlatformVersion.Supports(PlatformApis.LaunchAdjacent)) { intent.AddFlags(ActivityFlags.LaunchAdjacent); } intent.PutExtras(bundle); platformApplication.StartActivity(intent); }
public static UIImage?ConvertToImage(this UIView view) { if (!PlatformVersion.IsAtLeast(10)) { UIGraphics.BeginImageContext(view.Frame.Size); view.Layer.RenderInContext(UIGraphics.GetCurrentContext()); var image = UIGraphics.GetImageFromCurrentImageContext(); UIGraphics.EndImageContext(); if (image.CGImage == null) { return(null); } return(new UIImage(image.CGImage)); } var imageRenderer = new UIGraphicsImageRenderer(view.Bounds.Size); return(imageRenderer.CreateImage((a) => { view.Layer.RenderInContext(a.CGContext); })); }
public static void UpdateSemanticNodeInfo(this View platformView, IView virtualView, AccessibilityNodeInfoCompat?info) { if (info == null || virtualView == null) { return; } var semantics = virtualView.Semantics; var desc = semantics?.Description; var hint = semantics?.Hint; string?newText = null; string?newContentDescription = null; if (!string.IsNullOrEmpty(desc)) { // Edit Text fields won't read anything for the content description if (platformView is EditText et) { if (!string.IsNullOrEmpty(et.Text)) { newText = $"{desc}, {et.Text}"; } else { newText = $"{desc}"; } } else { newContentDescription = desc; } } if (!string.IsNullOrEmpty(hint)) { // info HintText won't read anything back when using TalkBack pre API 26 if (PlatformVersion.IsAtLeast(26)) { info.HintText = hint; if (platformView is EditText) { info.ShowingHintText = false; } } else { if (platformView is EditText et) { newText = newText ?? et.Text; newText = $"{newText}, {hint}"; } else if (platformView is TextView tv) { if (newContentDescription != null) { newText = $"{newContentDescription}, {hint}"; } else if (!string.IsNullOrEmpty(tv.Text)) { newText = $"{tv.Text}, {hint}"; } else { newText = $"{hint}"; } } else { if (newContentDescription != null) { newText = $"{newContentDescription}, {hint}"; } else { newText = $"{hint}"; } } newContentDescription = null; } } if (!string.IsNullOrWhiteSpace(newContentDescription)) { info.ContentDescription = newContentDescription; } else if (info.ContentDescription == virtualView.AutomationId) { info.ContentDescription = null; } if (!string.IsNullOrWhiteSpace(newText)) { info.Text = newText; } }