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; } }
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; } }
public override void Remove(View view) { TypedNativeView.RemoveView(_view); _view = null; base.Remove(view); }
protected override MauiTimePicker CreateNativeView() { return(new MauiTimePicker(() => { SetVirtualViewTime(); TypedNativeView?.ResignFirstResponder(); })); }
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); }
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(); }
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)); }
void OnCollectionChanged(object?sender, EventArgs e) { if (VirtualView == null || TypedNativeView == null) { return; } TypedNativeView.UpdatePicker(VirtualView); }
void OnTextChanged() { if (TypedNativeView == null) { return; } TypedNativeView.HidePlaceholder(!string.IsNullOrEmpty(TypedNativeView.Text)); }
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(); }
public override void Remove(View view) { if (_content != null) { TypedNativeView.RemoveView(_content); _content = null; } base.Remove(view); }
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); } }
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); }
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(); } }
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); } }
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)); }
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); } }
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()); } }
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); } }
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)); } }
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)); }
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); }
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); }
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)); }
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(); } }
private void HandleChildrenChanged(object sender, LayoutEventArgs e) { TypedNativeView?.CreateTabs(VirtualView?.ToList()); }
private void VirtualView_ChildrenChanged(object sender, LayoutEventArgs e) { TypedNativeView?.Setup(VirtualView?.ToList()); }
public override void SetView(View view) { base.SetView(view); TypedNativeView?.Setup(VirtualView?.ToList()); SubscribeEvent(); }