Ejemplo n.º 1
0
        void OnFocusChange(object?sender, global::Android.Views.View.FocusChangeEventArgs e)
        {
            if (TypedNativeView == null)
            {
                return;
            }

            if (e.HasFocus)
            {
                if (TypedNativeView.Clickable)
                {
                    TypedNativeView.CallOnClick();
                }
                else
                {
                    OnClick(TypedNativeView, EventArgs.Empty);
                }
            }
            else if (_dialog != null)
            {
                _dialog.Hide();
                TypedNativeView.ClearFocus();
                _dialog = null;
            }
        }
Ejemplo n.º 2
0
        public override void SetView(View view)
        {
            base.SetView(view);

            _content = VirtualView?.View?.ToView();
            if (_content != null)
            {
                if (VirtualView?.View != null)
                {
                    VirtualView.View.NeedsLayout += HandleViewNeedsLayout;
                }

                _content.SizeToFit();
                TypedNativeView.Add(_content);

                var measuredSize = VirtualView.View.Measure(new SizeF(float.PositiveInfinity, float.PositiveInfinity));
                TypedNativeView.ContentSize = measuredSize.ToCGSize();
            }

            if (VirtualView.Orientation == Orientation.Horizontal)
            {
                TypedNativeView.ShowsVerticalScrollIndicator   = false;
                TypedNativeView.ShowsHorizontalScrollIndicator = true;
            }
            else
            {
                TypedNativeView.ShowsVerticalScrollIndicator   = true;
                TypedNativeView.ShowsHorizontalScrollIndicator = false;
            }
        }
Ejemplo n.º 3
0
        public override void Remove(View view)
        {
            TypedNativeView.RemoveView(_view);
            _view = null;

            base.Remove(view);
        }
Ejemplo n.º 4
0
 protected override MauiTimePicker CreateNativeView()
 {
     return(new MauiTimePicker(() => {
         SetVirtualViewTime();
         TypedNativeView?.ResignFirstResponder();
     }));
 }
Ejemplo n.º 5
0
        public void Add(IView child)
        {
            _ = TypedNativeView ?? throw new InvalidOperationException($"{nameof(TypedNativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiContext ?? throw new InvalidOperationException($"{nameof(MauiContext)} should have been set by base class.");

            TypedNativeView.AddView(child.ToNative(MauiContext), 0);
        }
Ejemplo n.º 6
0
        public void Add(IView child)
        {
            _ = TypedNativeView ?? throw new InvalidOperationException($"{nameof(TypedNativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");

            TypedNativeView.AddSubview(child.ToNative());
            TypedNativeView.SetNeedsLayout();
        }
Ejemplo n.º 7
0
        public virtual SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            var s       = TypedNativeView.SizeThatFits(new CoreGraphics.CGSize((float)widthConstraint, (float)heightConstraint));
            var request = new Size(s.Width == float.PositiveInfinity ? double.PositiveInfinity : s.Width,
                                   s.Height == float.PositiveInfinity ? double.PositiveInfinity : s.Height);

            return(new SizeRequest(request));
        }
Ejemplo n.º 8
0
        void OnCollectionChanged(object?sender, EventArgs e)
        {
            if (VirtualView == null || TypedNativeView == null)
            {
                return;
            }

            TypedNativeView.UpdatePicker(VirtualView);
        }
Ejemplo n.º 9
0
        void OnTextChanged()
        {
            if (TypedNativeView == null)
            {
                return;
            }

            TypedNativeView.HidePlaceholder(!string.IsNullOrEmpty(TypedNativeView.Text));
        }
Ejemplo n.º 10
0
        public void Add(IView child)
        {
            _ = TypedNativeView ?? throw new InvalidOperationException($"{nameof(TypedNativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiApp.Current?.Context ?? throw new InvalidOperationException($"The MauiApp.Current.Context can't be null.");

            TypedNativeView.AddSubview(child.ToNative(MauiApp.Current.Context));
            TypedNativeView.SetNeedsLayout();
        }
Ejemplo n.º 11
0
        public override void Remove(View view)
        {
            if (_content != null)
            {
                TypedNativeView.RemoveView(_content);
                _content = null;
            }

            base.Remove(view);
        }
Ejemplo n.º 12
0
        public void Remove(IView child)
        {
            _ = TypedNativeView ?? throw new InvalidOperationException($"{nameof(TypedNativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");

            if (child?.Handler?.NativeView is View view)
            {
                TypedNativeView.RemoveView(view);
            }
        }
Ejemplo n.º 13
0
        protected override MauiPicker CreateNativeView()
        {
            _pickerView = new UIPickerView();

            var nativePicker = new MauiPicker(_pickerView)
            {
                BorderStyle = UITextBorderStyle.RoundedRect
            };

            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) =>
            {
                var pickerSource = (PickerSource)_pickerView.Model;

                if (pickerSource.SelectedIndex == -1 && VirtualView?.Items != null && VirtualView.Items.Count > 0)
                {
                    UpdatePickerSelectedIndex(0);
                }

                if (VirtualView?.SelectedIndex == -1 && VirtualView.Items != null && VirtualView.Items.Count > 0)
                {
                    TypedNativeView?.SetSelectedIndex(VirtualView, 0);
                }

                UpdatePickerFromPickerSource(pickerSource);
                nativePicker.ResignFirstResponder();
            });

            toolbar.SetItems(new[] { spacer, doneButton }, false);

            nativePicker.InputView          = _pickerView;
            nativePicker.InputAccessoryView = toolbar;

            nativePicker.InputView.AutoresizingMask          = UIViewAutoresizing.FlexibleHeight;
            nativePicker.InputAccessoryView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight;

            if (UIDevice.CurrentDevice.CheckSystemVersion(9, 0))
            {
                nativePicker.InputAssistantItem.LeadingBarButtonGroups  = null;
                nativePicker.InputAssistantItem.TrailingBarButtonGroups = null;
            }

            nativePicker.AccessibilityTraits = UIAccessibilityTrait.Button;

            _pickerView.Model = new PickerSource(VirtualView);

            return(nativePicker);
        }
Ejemplo n.º 14
0
        public void Remove(IView child)
        {
            _ = TypedNativeView ?? throw new InvalidOperationException($"{nameof(TypedNativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");

            if (child?.Handler?.NativeView is NativeView nativeView)
            {
                nativeView.RemoveFromSuperview();
                TypedNativeView.SetNeedsLayout();
            }
        }
Ejemplo n.º 15
0
        void OnFocusedChange(bool hasFocus)
        {
            if (TypedNativeView == null || VirtualView == null)
            {
                return;
            }

            // This will eliminate additional native property setting if not required.
            if (VirtualView.ClearButtonVisibility == ClearButtonVisibility.WhileEditing)
            {
                TypedNativeView?.UpdateClearButtonVisibility(VirtualView, ClearButtonDrawable);
            }
        }
Ejemplo n.º 16
0
        public virtual Size GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            var sizeThatFits = TypedNativeView?.SizeThatFits(new CoreGraphics.CGSize((float)widthConstraint, (float)heightConstraint));

            if (sizeThatFits.HasValue)
            {
                return(new Size(
                           sizeThatFits.Value.Width == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Value.Width,
                           sizeThatFits.Value.Height == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Value.Height));
            }

            return(new Size(widthConstraint, heightConstraint));
        }
Ejemplo n.º 17
0
        void SetControlPropertiesFromProxy()
        {
            if (TypedNativeView == null)
            {
                return;
            }

            foreach (UIControlState uiControlState in ControlStates)
            {
                TypedNativeView.SetTitleColor(UIButton.Appearance.TitleColor(uiControlState), uiControlState);                 // If new values are null, old values are preserved.
                TypedNativeView.SetTitleShadowColor(UIButton.Appearance.TitleShadowColor(uiControlState), uiControlState);
                TypedNativeView.SetBackgroundImage(UIButton.Appearance.BackgroundImageForState(uiControlState), uiControlState);
            }
        }
Ejemplo n.º 18
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            _ = TypedNativeView ?? throw new InvalidOperationException($"{nameof(TypedNativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");

            TypedNativeView.CrossPlatformMeasure = VirtualView.Measure;
            TypedNativeView.CrossPlatformArrange = VirtualView.Arrange;

            foreach (var child in VirtualView.Children)
            {
                TypedNativeView.AddSubview(child.ToNative());
            }
        }
Ejemplo n.º 19
0
        public override void SetView(View view)
        {
            base.SetView(view);

            var newContent = VirtualView?.View?.ToView();
            if (_content == null || newContent != _content)
            {
                if (_content != null)
                    TypedNativeView.RemoveView(_content);

                _content = newContent;

                if (_content != null)
                    TypedNativeView.AddView(_content);
            }
        }
Ejemplo n.º 20
0
        public override void SetVirtualView(IView view)
        {
            base.SetVirtualView(view);

            _ = TypedNativeView ?? throw new InvalidOperationException($"{nameof(TypedNativeView)} should have been set by base class.");
            _ = VirtualView ?? throw new InvalidOperationException($"{nameof(VirtualView)} should have been set by base class.");
            _ = MauiApp.Current?.Context ?? throw new InvalidOperationException($"The MauiApp.Current.Context can't be null.");

            TypedNativeView.CrossPlatformMeasure = VirtualView.Measure;
            TypedNativeView.CrossPlatformArrange = VirtualView.Arrange;

            foreach (var child in VirtualView.Children)
            {
                TypedNativeView.AddView(child.ToNative(MauiApp.Current.Context));
            }
        }
Ejemplo n.º 21
0
        public virtual SizeRequest GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (TypedNativeView == null)
            {
                return(new SizeRequest(Size.Zero));
            }

            var deviceWidthConstraint  = Context.ToPixels(widthConstraint);
            var deviceHeightConstraint = Context.ToPixels(heightConstraint);

            var widthSpec  = MeasureSpecMode.AtMost.MakeMeasureSpec((int)deviceWidthConstraint);
            var heightSpec = MeasureSpecMode.AtMost.MakeMeasureSpec((int)deviceHeightConstraint);

            TypedNativeView.Measure(widthSpec, heightSpec);

            var deviceIndependentSize = Context.FromPixels(TypedNativeView.MeasuredWidth, TypedNativeView.MeasuredHeight);

            return(new SizeRequest(deviceIndependentSize));
        }
Ejemplo n.º 22
0
        void OnTextChanged(string?text)
        {
            if (VirtualView == null || TypedNativeView == null)
            {
                return;
            }

            // Even though <null> is technically different to "", it has no
            // functional difference to apps. Thus, hide it.
            var mauiText   = VirtualView.Text ?? string.Empty;
            var nativeText = text ?? string.Empty;

            if (mauiText != nativeText)
            {
                VirtualView.Text = nativeText;
            }

            // Text changed should trigger clear button visibility.
            TypedNativeView.UpdateClearButtonVisibility(VirtualView, ClearButtonDrawable);
        }
Ejemplo n.º 23
0
        public virtual Size GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (TypedNativeView == null)
            {
                return(new Size(widthConstraint, heightConstraint));
            }

            var sizeThatFits = TypedNativeView.SizeThatFits(new CoreGraphics.CGSize((float)widthConstraint, (float)heightConstraint));

            var size = new Size(
                sizeThatFits.Width == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Width,
                sizeThatFits.Height == float.PositiveInfinity ? double.PositiveInfinity : sizeThatFits.Height);

            if (double.IsInfinity(size.Width) || double.IsInfinity(size.Height))
            {
                TypedNativeView.SizeToFit();

                size = new Size(TypedNativeView.Frame.Width, TypedNativeView.Frame.Height);
            }

            return(size);
        }
Ejemplo n.º 24
0
        public virtual Size GetDesiredSize(double widthConstraint, double heightConstraint)
        {
            if (TypedNativeView == null)
            {
                return(Size.Zero);
            }

            if (Context == null)
            {
                return(new Size(widthConstraint, heightConstraint));
            }

            var deviceWidthConstraint  = Context.ToPixels(widthConstraint);
            var deviceHeightConstraint = Context.ToPixels(heightConstraint);

            var widthSpec  = MeasureSpecMode.Exactly.MakeMeasureSpec((int)deviceWidthConstraint);
            var heightSpec = MeasureSpecMode.Exactly.MakeMeasureSpec((int)deviceHeightConstraint);

            TypedNativeView.Measure(widthSpec, heightSpec);

            return(Context.FromPixels(TypedNativeView.MeasuredWidth, TypedNativeView.MeasuredHeight));
        }
Ejemplo n.º 25
0
        void OnClick(object?sender, EventArgs e)
        {
            if (_dialog == null && VirtualView != null)
            {
                using (var builder = new AlertDialog.Builder(Context))
                {
                    builder.SetTitle(VirtualView.Title ?? string.Empty);

                    string[] items = VirtualView.Items.ToArray();

                    builder.SetItems(items, (s, e) =>
                    {
                        var selectedIndex         = e.Which;
                        VirtualView.SelectedIndex = selectedIndex;
                        TypedNativeView?.UpdatePicker(VirtualView);
                    });

                    builder.SetNegativeButton(AResource.String.Cancel, (o, args) => { });

                    _dialog = builder.Create();
                }

                if (_dialog == null)
                {
                    return;
                }

                _dialog.SetCanceledOnTouchOutside(true);

                _dialog.DismissEvent += (sender, args) =>
                {
                    _dialog.Dispose();
                    _dialog = null;
                };

                _dialog.Show();
            }
        }
Ejemplo n.º 26
0
 private void HandleChildrenChanged(object sender, LayoutEventArgs e)
 {
     TypedNativeView?.CreateTabs(VirtualView?.ToList());
 }
Ejemplo n.º 27
0
 private void VirtualView_ChildrenChanged(object sender, LayoutEventArgs e)
 {
     TypedNativeView?.Setup(VirtualView?.ToList());
 }
Ejemplo n.º 28
0
 public override void SetView(View view)
 {
     base.SetView(view);
     TypedNativeView?.Setup(VirtualView?.ToList());
     SubscribeEvent();
 }