Skip to main content
Version: v1.0

SCROLL_LIST

scroll_list_sample

Create a sliding list area, which can be filled with pictures and text.

Create UI widget

const scrollList = hmUI.createWidget(hmUI.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_configConfiguration information for item,see the description below.YESItemConfig
item_config_countThe length of the item_config array.YESnumber
data_arrayData sets, a structure array, see description below.YESDataArray
data_countThe length of data set.YESnumber
item_click_funcCallback.NOfunction
data_type_configWhich item type configuration information should be used for each row of data, see the description below.NOarray
data_type_config_countThe length of set.NOnumber
on_pageUsed when updating data, set to 1 means keep the current page after updating the data.NOnumber

ItemConfig: object

PropertiesDescriptionRequiredType
type_idThe current item type Id, js guarantees that it is NOt repeated. If item_config_count is 0, it can be left blank, otherwise it is 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

item_config Complete Configuration

const item_config = [
{
type_id: 1,
item_bg_color: 0xef5350,
item_bg_radius: 10,
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
}
],
text_view_count: 2,
item_height: 130
},
{
type_id: 2,
item_bg_color: 0xef5350,
item_bg_radius: 10,
text_view: [{ x: 100, y: 0, w: 100, h: 20, key: 'like', color: 0x3d5afe }],
text_view_count: 1,
item_height: 100
}
]

TextView: object

All relative coordinates involving location information.

PropertiesDescriptionRequiredType
xx-coordinateYESnumber
yy-coordinateYESnumber
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
// 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.YESnumber
yy-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
// 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

  • Each key is the key value when the View is added above.
  • Rendering will get the key value of each view from each View and look it up in the data_array.
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' }
]

data_type_config Configuration Information

If the id of the configured type is the 0 item of item_config then the configuration can be omitted.

PropertiesDescriptionRequiredType
startIndex of startYESnumber
endIndex of the endYESnumber
type_idIDYESnumber

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
}

Refresh data

const scrollList = hmUI.createWidget(hmUI.widget.SCROLL_LIST, Param)
scrollList.setProperty(hmUI.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

const dataList = [
{ name: 'a', age: 12, like: 2 },
{ name: 'b', age: 13, like: 3 },
{ name: 'c', age: 13, like: 4 }
]

function scrollListItemClick(list, index) {
console.log('scrollListItemClick index=' + index)
}

hmUI.createWidget(hmUI.widget.SCROLL_LIST, {
x: 10,
y: 10,
h: 454,
w: 200,
item_space: 10,
item_config: [
{
type_id: 1,
item_bg_color: 0xef5350,
item_bg_radius: 10,
text_view: [
{ x: 0, y: 0, w: 100, h: 100, key: 'name', color: 0xffffff, text_size: 20 },
{ x: 0, y: 100, w: 100, h: 30, key: 'age', color: 0xffffff }
],
text_view_count: 2,
item_height: 130
},
{
type_id: 2,
item_bg_color: 0xef5350,
item_bg_radius: 10,
text_view: [
{ x: 0, y: 0, w: 100, h: 100, key: 'name', color: 0xffffff, text_size: 20 },
{ x: 100, y: 0, w: 100, h: 100, key: 'like', color: 0x3d5afe }
],
text_view_count: 2,
item_height: 130
}
],
item_config_count: 2,
data_array: dataList,
data_count: dataList.length,
item_click_func: scrollListItemClick,
data_type_config: [
{
start: 0,
end: 1,
type_id: 1
},
{
start: 1,
end: 2,
type_id: 2
}
],
data_type_config_count: 2
})