Skip to main content
Version: v3

PICKER

Start from API_LEVEL 3.0. Please refer to API_LEVEL

An universal selector, use to text and number list selection

Create UI widget

import { createWidget, widget, prop } from '@zos/ui'

const keyboard = createWidget(widget.WIDGET_PICKER, Param)

Param: object

PropertiesDescriptionRequiredType
nb_of_columnsMaximum Picker columns (Maximum number is 5)YESnumber
data_configArray of column configuration, refer to DataConfigYESArray<DataConfig>
titleTitle of PickerNOstring
subtitleSubtitle of PickerNOstring
done_iconResource path of icon about done statusNOnumber
picker_cbCallback function of PickerNOCallBack
init_col_indexInitialize the index of the focused columnNOnumber
normal_colorColor value of unselected itemNOnumber
select_colorColor value of selected itemNOnumber

DataConfig: object

PropertiesDescriptionRequiredType
data_arrayData array of columnYESArray<number|string>
support_loopsupport circular drag and dropYESboolean
unitUnitNOstring
connectorData separatorNOstring
font_namePath of font file, refer to TEXTNOstring
font_sizeFont sizeNOnumber
select_font_sizeFont size of selected itemNOnumber
connector_font_sizeFont size of separatorNOnumber
unit_font_sizeFont size of unitNOnumber
init_val_indexDefault selected indexNOnumber
col_widthColumn width, all columns need to be configuredNOnumber

CallBack: function

Callback function of Picker

picker_cb(picker: WIDGET, event_type: number, column_index: number, select_index: index): void
PropertiesDescription
pickerThe Picker instance
event_typeEvent type of Picker, see EVENT_TYPE
column_indexColumn index for triggering Picker events
select_indexThe index of selected item
EVENT_TYPE valueDescription
0Lose focus
1Get focus
2Selected item has a value
function picker_cb(picker, event_type, column_index, select_index) {
if (event_type == 2) {
picker.setProperty(prop.TITLE, 'End Date')
picker.setProperty(prop.SUBTITLE, '3 days in totals')

picker.setProperty(prop.UPDATE_DATA, {
col_index: 0,
val_index: 5,
data_array: new Array(10).fill(0).map((d, index) => index + 1)
})

picker.setProperty(prop.CUR_COLUMN, 1)
}
}

Property Operations

The SET and GET means widget.setProperty and widget.getProperty

Property NameSET/GETDescription
prop.TITLESETUpdate title
prop.SUBTITLESETUpdate subtitle
prop.UPDATE_DATASETUpdate data of a column
prop.CUR_COLUMNSET/GETUpdate the current column

Code example

import { Time } from '@zos/sensor'
import { widget, createWidget } from '@zos/ui'

const time = new Time()

const picker_widget = createWidget(widget.WIDGET_PICKER, {
title: 'Start Date',
subtitle: '',
nb_of_columns: 3,
single_wide: true,
init_col_index: 1,
data_config: [
{
data_array: new Array(12).fill(0).map((d, index) => index + 1),
init_val_index: time.getMonth() - 1,
unit: 'Month',
support_loop: true,
font_name: 'fonts/x.ttf',
font_size: 24,
select_font_size: 48,
connector_font_size: 18,
unit_font_size: 18,
col_width: 80
},
{
data_array: new Array(31).fill(0).map((d, index) => index + 1),
init_val_index: time.getDate() - 1,
unit: 'Day',
support_loop: true,
font_name: 'fonts/x.ttf',
font_size: 24,
select_font_size: 48,
connector_font_size: 36,
unit_font_size: 36,
col_width: 80
},
{
data_array: new Array(100).fill(0).map((d, index) => index + 1970),
init_val_index: time.getFullYear() - 1970,
unit: 'Year',
support_loop: true,
font_name: 'fonts/x.ttf',
font_size: 24,
select_font_size: 48,
connector_font_size: 36,
unit_font_size: 36,
col_width: 80
}
],
picker_cb
})

function picker_cb(picker, event_type, column_index, select_index) {
console.log(
'timePickerCb: ' + event_type,
'column_index: ' + column_index,
'select_index: ' + select_index
)
}