Skip to content

Picker on iOS/Catalyst should use UIButton with menu rather than UIPickerView #23999

Open

Description

Description

Currently, on iOS, the picker uses a slightly hacky button, which opens a popover and the native UIPickerView control. This isn't very elegant. However the main problem is that this core control is completely broken on Mac Catalyst when using the native mac idiom. It can't even run, because of limitations inherent to mac catalyst and the UIPicker control.

A solution, which would also align the iOS Picker with its android and windows counterparts, would be to replace this with a UIButton that has ShowsMenuAsPrimaryAction = true and ChangesSelectionAsPrimaryAction = true.

Here's an example, which currently works:

protected override UIKit.UIView CreatePlatformView()
{   
    UIMenuElement[] menuElements = new UIMenuElement[]{
        UIAction.Create("Option 1",null,null,(args)=>{}),
        UIAction.Create("Option 2",null,null,(args)=>{}),
        UIAction.Create("Option 3",null,null,(args)=>{})
    };

    var button = new UIButton(UIButtonType.System);
    button.Menu = UIMenu.Create(menuElements);
    button.ShowsMenuAsPrimaryAction = true;
    button.ChangesSelectionAsPrimaryAction = true;
    return button;
}

On macOS, you get exactly what you would expect from a picker control:

image

And iOS also feels and looks great to use, a lot better than the current control:
image

Public API Changes

No API Changes, this would be a replacement of the underlying native control on iOS.

Intended Use-Case

Any time that a picker is needed on iOS or macOS.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions