Ejemplo n.º 1
0
        void UpdateSquareShape()
        {
            if (!NativeVersion.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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (NativeVersion.Supports(NativeApis.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
            }
        }
Ejemplo n.º 3
0
 public MauiPageControl()
 {
     ValueChanged += MauiPageControlValueChanged;
     if (NativeVersion.IsAtLeast(14))
     {
         AllowsContinuousInteraction = false;
         BackgroundStyle             = UIPageControlBackgroundStyle.Minimal;
     }
 }
Ejemplo n.º 4
0
        public static void UpdateTextHtml(this TextView textView, ILabel label)
        {
            var newText = label.Text ?? string.Empty;

            if (NativeVersion.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
        }
Ejemplo n.º 5
0
        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 && !NativeVersion.IsAtLeast(14))
            {
                LayoutSubviews();
            }
        }
Ejemplo n.º 6
0
        internal static UIView GetTrackSubview(this UISwitch uISwitch)
        {
            UIView uIView;

            if (NativeVersion.IsAtLeast(13))
            {
                uIView = uISwitch.Subviews[0].Subviews[0];
            }
            else
            {
                uIView = uISwitch.Subviews[0].Subviews[0].Subviews[0];
            }

            return(uIView);
        }
Ejemplo n.º 7
0
        public MauiTimePicker(Action dateSelected)
        {
            BorderStyle = UITextBorderStyle.RoundedRect;

            _picker = new UIDatePicker {
                Mode = UIDatePickerMode.Time, TimeZone = new NSTimeZone("UTC")
            };
            _dateSelected = dateSelected;

            if (NativeVersion.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();
            });

            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;
        }
Ejemplo n.º 8
0
        public static void RequestNewWindow(this Application nativeApplication, IApplication application, OpenWindowRequest?args)
        {
            if (application.Handler?.MauiContext is not IMauiContext applicationContext)
            {
                return;
            }

            var state  = args?.State;
            var bundle = state.ToBundle();

            var pm     = nativeApplication.PackageManager !;
            var intent = pm.GetLaunchIntentForPackage(nativeApplication.PackageName !) !;

            intent.AddFlags(ActivityFlags.NewTask);
            intent.AddFlags(ActivityFlags.MultipleTask);
            if (NativeVersion.Supports(NativeApis.LaunchAdjacent))
            {
                intent.AddFlags(ActivityFlags.LaunchAdjacent);
            }
            intent.PutExtras(bundle);

            nativeApplication.StartActivity(intent);
        }
Ejemplo n.º 9
0
        public static UIImage?ConvertToImage(this UIView view)
        {
            if (!NativeVersion.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);
            }));
        }
Ejemplo n.º 10
0
        public static void UpdateTrackColor(this UISwitch uiSwitch, ISwitch view, UIColor?defaultOnTrackColor, UIColor?defaultOffTrackColor)
        {
            if (view == null)
            {
                return;
            }

            if (view.TrackColor == null)
            {
                uiSwitch.OnTintColor = defaultOnTrackColor;
            }
            else
            {
                uiSwitch.OnTintColor = view.TrackColor.ToNative();
            }

            UIView uIView;

            if (NativeVersion.IsAtLeast(13))
            {
                uIView = uiSwitch.Subviews[0].Subviews[0];
            }
            else
            {
                uIView = uiSwitch.Subviews[0].Subviews[0].Subviews[0];
            }

            if (view.TrackColor == null)
            {
                uIView.BackgroundColor = defaultOffTrackColor;
            }
            else
            {
                uIView.BackgroundColor = uiSwitch.OnTintColor;
            }
        }
Ejemplo n.º 11
0
        public static void UpdateSemanticNodeInfo(this View nativeView, IView virtualView, AccessibilityNodeInfoCompat?info)
        {
            if (info == null)
            {
                return;
            }

            var semantics = virtualView?.Semantics;

            if (semantics == null)
            {
                return;
            }

            string?newText = null;
            string?newContentDescription = null;

            var desc = semantics.Description;

            if (!string.IsNullOrEmpty(desc))
            {
                // Edit Text fields won't read anything for the content description
                if (nativeView is EditText et)
                {
                    if (!string.IsNullOrEmpty(et.Text))
                    {
                        newText = $"{desc}, {et.Text}";
                    }
                    else
                    {
                        newText = $"{desc}";
                    }
                }
                else
                {
                    newContentDescription = desc;
                }
            }

            var hint = semantics.Hint;

            if (!string.IsNullOrEmpty(hint))
            {
                // info HintText won't read anything back when using TalkBack pre API 26
                if (NativeVersion.IsAtLeast(26))
                {
                    info.HintText = hint;

                    if (nativeView is EditText)
                    {
                        info.ShowingHintText = false;
                    }
                }
                else
                {
                    if (nativeView is EditText et)
                    {
                        newText = newText ?? et.Text;
                        newText = $"{newText}, {hint}";
                    }
                    else if (nativeView 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;
            }

            if (!string.IsNullOrWhiteSpace(newText))
            {
                info.Text = newText;
            }
        }