The Picker
component is used to select a single value from a set of mutually exclusive options. It supports various display styles and allows users to choose a single value. The selected value and the change event can be managed using the value
and onChanged
properties.
PickerValue
: The type of the selected value, which can be either number
or string
.PickerProps<T extends PickerValue>
: The property type for the Picker
component, which includes:
value
: The current selected value, which can be a number
or string
(optional).onChanged
: A callback function triggered when the selected value changes, with the new value (T
) as the parameter.children
: The option views, where each child must have a tag
property to indicate its value. This can be a JSX.Element
or an array of JSX.Element
s.title
: A string describing the option's purpose, used in certain cases.systemImage
: The name of the system image resource, used in certain cases.label
: A JSX.Element
that describes the purpose of the selection, used in certain cases.The Picker
component manages the user's selection through the value
and onChanged
properties. The value
is the current selected value, and the onChanged
is a callback function that is invoked when the user changes the selection. The children
property defines the options' views, allowing multiple layouts to be used for displaying the options. Each children
element must have a tag
property to mark its value, for example, <Text tag={1}>Option 1</Text>
.
The Picker
component supports the following styles to adjust how the component is displayed:
automatic
: The default style, automatically determined based on the picker’s context.inline
: Displays each option inline with other views in the current container.menu
: Displays the options in a menu that opens when the user presses a button or as a submenu within a larger menu.navigationLink
: Displays a navigation link that presents the options in a List-style picker view when clicked.palette
: Displays the options as a row of compact elements.segmented
: Displays the options in a segmented control style.wheel
: Displays the options in a scrollable wheel, showing the selected option and a few neighboring options.Below are examples of how to use the Picker
component:
Picker
Picker
can be used in forms to select a single value from a predefined set of options.Picker
can be used to choose colors, themes, languages, etc.Picker
can serve as a tool for selecting options within multi-level menus.children
element in the Picker
must use the tag
property to mark its value, for example: <Text tag={1}>Option 1</Text>
.value
and onChanged
properties must be used together to ensure correct functionality when the user changes the selected value.pickerStyle
property provides various styles to enhance the user experience. Select the one that fits your use case best.JSX.Element
: The type used for defining the view structure. The Picker
component’s children
property relies on this type.useState
: A React hook for managing the selected value’s state.