Skip to main content
Version: v3

SCROLL_LIST

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

scroll_list_sample

Create a list area with sliding support, where each item item can have an image and text, and support horizontal sliding.

Create UI widget

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

const scrollList = createWidget(widget.SCROLL_LIST, Param)

Type

Param: object

PropertiesDescriptionRequiredType
xThe x-coordinate of the widget.YESnumber
yThe y-coordinate of the widget.YESnumber
wWidth of the widget.YESnumber
hThe height of the widget.YESnumber
item_spaceSpace between each item.NOnumber
item_configitem type configuration, see ItemConfigYESArray<ItemConfig>
item_config_countThe length of the item_config array.YESnumber
data_arrayData Array.YESDataArray
data_countData array length.YESnumber
item_click_funcitem Click callback function, see ItemClickFuncNOItemClickFunc
data_type_configThe index type configuration array for item, see DataTypeConfigNOArray<DataTypeConfig>
data_type_config_countThe length of data_type_config.NOnumber
on_pageUsed when updating data, set to 1 means that the list data remains at the current position after updating, otherwise it returns to the top of the list.NOnumber
snap_to_centerIs the list attached to the SCROLL_LIST height center positionNOboolean
item_focus_change_funcThe list sliding focus change callback function, see ItemFocusChangeFuncNOItemFocusChangeFunc
item_enable_horizon_dragWhether the item can be slid in the horizontal directionNOboolean
item_drag_max_distanceHorizontal sliding distance, positive value means sliding to the left, negative value means sliding to the rightNOnumber

ItemConfig: object

PropertiesDescriptionRequiredType
type_idThe type ID of the item, not required if item_config_count is 0, otherwise required.NOnumber
item_heightItem's height.YESnumber
item_bg_colorItem's background color.YESnumber
item_bg_radiusThe rounded corners of the item's background.YESnumber
text_viewThe structure array of textView, each item is a textView. See the description below.NOArray<TextView>
text_view_countArray's length of text_view.NOnumber
image_viewArray of imageView, each item is an imageView.See description below.NOArray<ImageView>
image_view_countThe length of the image_view array.NOnumber

TextView: object

All relative coordinates involving location information.

PropertiesDescriptionRequiredType
xx coordinate, relative coordinate.YESnumber
yy-coordinate, relative coordinate.YESnumber
wThe width of widget.YESnumber
hThe length of the widget.YESnumber
colorThe color of text.NOnumber
text_sizeThe size of text.NOnumber
keyData binding.See usage examples and data_array descriptions for details.YESstring
actionWhether or not to respond to the click event, after responding, the corresponding data key can be captured in item_click_func, default falseNOboolean
// Each structure in the array is a textView.
const text_view = [
{ x: 100, y: 0, w: 100, h: 20, key: 'name', color: 0xffffff },
{ x: 0, y: 30, w: 100, h: 100, key: 'age', color: 0xffffff, text_size: 20 }
]

ImageView: object

All relative coordinates involving location information.

PropertiesDescriptionRequiredType
xx-coordinate, relative coordinate.YESnumber
yy-coordinate, relative coordinate.YESnumber
wThe width of widget.YESnumber
hThe length of the widget.YESnumber
colorThe color of text.NOnumber
keyData binding.See usage examples and data_array descriptions for details.YESstring
actionWhether or not to respond to the click event, after responding, the corresponding data key can be captured in item_click_func, default falseNOboolean
// Each structure in the array is an imageView.
const image_view = [{ x: 0, y: 0, w: 20, h: 20, key: 'img_src' }]

data_array Configuration

The data arrays, TextView and ImageView, take values from each of the data_array objects based on the property name (configured via key) and render them to the view based on the corresponding configuration.

const dataList = [
{ img_src: rootPath + 'step/step_num_1.png', name: 'name1', age: '12' },
{ img_src: rootPath + 'step/step_num_1.png', name: 'name1', age: '13' },
{ img_src: rootPath + 'step/step_num_1.png', name: 'name1', age: '13' }
]

DataTypeConfig: object

Set the item type of the list index.

PropertiesDescriptionRequiredType
startIndex of startYESnumber
endIndex of the endYESnumber
type_idThe type configuration in item_config corresponds to type_idYESnumber

The relationship between start and end is the closed interval [start, end].

{
data_type_config:[
//The data representing the index from 0 to 2 uses the style with type_id of 2.
{
start: 0,
end: 2,
type_id: 2,
},
{
start: 3,
end: 10,
type_id: 1,
},
],
data_type_config_count:2
}

ItemClickFunc

(list: ScrollList, index: number, data_key: string) => void
ParametersdescriptionType
listSCROLL_LIST Widgetany
indexClicked item indexnumber
data_keyClicked data key name, by key can be located to the clicked areastring

ItemFocusChangeFunc

(list: ScrollList, index: number, focus: boolean) => void
ParametersdescriptionType
listSCROLL_LIST Widgetany
indexitem indexnumber
focusitem is in focus or notboolean

Refresh data

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

const scrollList = createWidget(widget.SCROLL_LIST, Param)
scrollList.setProperty(prop.UPDATE_DATA, {
//Reset configuration information
data_type_config: [
{
start: 0,
end: 2,
type_id: 2
}
],
//Configuration the length of information
data_type_config_count: 1,
//New data
data_array: [
{ img_src: rootPath + 'test/NOrmalbtn_h.png', name: 'Name', age: '12', like: 'type2' },
{ img_src: rootPath + 'test/NOrmalbtn_h.png', name: 'namex1', age: '13', like: 'type2' },
{ img_src: rootPath + 'test/NOrmalbtn_h.png', name: 'namex2', age: '13', like: 'type2' },
{ img_src: rootPath + 'test/NOrmalbtn_h.png', name: 'namex3', age: '12', like: 'type2' },
{ img_src: rootPath + 'test/NOrmalbtn_h.png', name: 'name666', age: '13', like: 'type2' }
],
//The length of the data
data_count: 5,
//Refresh the data and stay on the current page. If it is not set or set to 0, it will return to the top of the list.
on_page: 1
})

Code example

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

Page({
build() {
const dataList = [
{ name: 'Amazfit T-Rex 2', size: 454, del_img: 'btn/delete.png' },
{ name: 'Amazfit GTR 3 Pro', size: 480, del_img: 'btn/delete.png' },
{ name: 'Amazfit GTR 3', size: 454, del_img: 'btn/delete.png' }
]

const scrollList = createWidget(widget.SCROLL_LIST, {
x: 0,
y: 120,
h: 300,
w: 480,
item_space: 20,
snap_to_center: true,
item_enable_horizon_drag: true,
item_drag_max_distance: -120,
item_config: [
{
type_id: 1,
item_bg_color: 0xef5350,
item_bg_radius: 10,
text_view: [
{ x: 0, y: 0, w: 480, h: 80, key: 'name', color: 0xffffff, text_size: 20 },
{ x: 0, y: 80, w: 480, h: 40, key: 'size', color: 0xffffff }
],
text_view_count: 2,
image_view: [{ x: 492, y: 28, w: 64, h: 64, key: 'del_img', action: true }],
image_view_count: 1,
item_height: 120
},
{
type_id: 2,
item_bg_color: 0xef5350,
item_bg_radius: 10,
text_view: [
{ x: 0, y: 0, w: 480, h: 80, key: 'name', color: 0x000000, text_size: 20 },
{ x: 0, y: 80, w: 480, h: 40, key: 'size', color: 0x000000 }
],
text_view_count: 2,
image_view: [{ x: 492, y: 28, w: 64, h: 64, key: 'del_img', action: true }],
image_view_count: 1,
item_height: 120
}
],
item_config_count: 2,
data_array: dataList,
data_count: dataList.length,
item_focus_change_func: (list, index, focus) => {
console.log('scrollListFocusChange index=' + index)
console.log('scrollListFocusChange focus=' + focus)
},
item_click_func: (item, index, data_key) => {
console.log(`scrollListItemClick index=${index}`)
if (data_key === 'del_img') {
scrollList.setProperty(prop.DELETE_ITEM, { index })
dataList.splice(index, 1)
} else {
updateConfig()
}
},
data_type_config: [
{
start: 0,
end: 1,
type_id: 1
},
{
start: 1,
end: 2,
type_id: 2
}
],
data_type_config_count: 2,
snap_to_center: true,
item_enable_horizon_drag: true,
item_drag_max_distance: -112
})

function updateConfig() {
scrollList.setProperty(prop.UPDATE_DATA, {
data_type_config: [
{
start: 0,
end: dataList.length - 1,
type_id: 1
}
],
data_type_config_count: 1,
data_array: dataList,
data_count: dataList.length,
on_page: 1
})
}
}
})