Skip to main content
Version: v3+

CYCLE_LIST

Start from API_LEVEL 2.0 . Please refer to API_LEVEL.

cycle_list_sample

Create a list that scrolls in a loop, which can be populated with images.

Create UI widget

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

const cycleList = createWidget(widget.CYCLE_LIST, Param)

Type

Param: object

PropertiesDescriptionRequiredType
item_bg_colorBackground color.YESnumber
item_heightThe height of item.YESnumber
xThe x-coordinate of widgets.YESnumber
yThe y-coordinate of widgets.YESnumber
wThe width of widgets.YESnumber
hThe height of widgets.YESnumber
data_arrayData arrays.YESArray<Data>
data_sizeThe length of the array.YESnumber
item_click_funcCallback for item click.NOItemClickFunc
item_focus_change_funcItem focus state callback.NOItemFocusChangeFunc

ItemClickFunc: function

(cycleList: CycleList, index: number) => void
PropertiesTypeNotes
cycleListobjectThe instance of cycleList.
indexnumberClicked item index.Starting from 0.

ItemFocusChangeFunc: function

(cycleList: CycleList, index: number, isFocus: boolean) => void
参数说明类型
cycleListThe instance of cycleList.object
indexLosing/getting the index of the focus item.number
isFocusWhether to get the focus.boolean

Code example

tip

Please refer to Design Resources for the image resources in the code example

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

Page({
state: {
pageName: 'CYCLE_LIST'
},

build() {
const imgArray = ['number-img/0.png', 'number-img/1.png', 'number-img/2.png', 'number-img/3.png', 'number-img/4.png']
const cycleList = createWidget(widget.CYCLE_LIST, {
x: 230,
y: 120,
h: 300,
w: 30,
data_array: imgArray,
data_size: 5,
item_height: 100,
item_click_func: (list, index) => {
console.log(index)
},
item_bg_color: 0xffffff
})
}
})

Additional Examples

Example 1

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

const imgListStyleObj = {
data_array: imgArray,
data_size: 11,
item_bg_color: 0x0007f,
layout: {
width: '20vw',
height: '65vh',
item_height: '13vh',
},
}

const rootContainer = createWidget(widget.VIRTUAL_CONTAINER, {
layout: { x: '0vw', y: '0vh', width: '100vw', height: '70vh' },
})

const groupRoot = createWidget(widget.GROUP, {
parent: rootContainer,
layout: {
display: 'flex',
'flex-flow': 'row wrap',
'column-gap': '20',
'row-gap': '10',
'justify-content': 'space-evenly',
'align-items': 'center',
width: '100%',
height: '100%',
},
})

for (let i = 0; i < 3; i += 1) {
groupRoot.createWidget(widget.CYCLE_LIST, imgListStyleObj)
}