Ejemplo n.º 1
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);
        }