The list flow is a layout form that arranges content in units of rows. Each row of list items efficiently displays structured information through combinations of text, images, and other forms. When the content of list items exceeds the screen size, scrolling functionality can be provided. List streams feature neat typesetting, highlighted key points, convenient comparison, and fast browsing. They are also widely used in various scenarios, such as app home pages, contacts, music playlists, and shopping lists.
The list flow mainly uses the List component to linearly arrange child components ListItemGroup or ListItem in the vertical direction and render any number of text and image views in a mixed manner to construct list content. In practical scenarios, it is generally combined with other basic components as required to form relatively complex interactive functions.
This section describes the implementation of the following list stream scenarios:
Scenario
As the container of the long list on the home page, the List component uses ListItem to customize the view pages of different modules. It is usually used in the list information flow scenario where multiple types of views are displayed, such as the portal home page and mall home page.
In this scenario, the app home page is used as an example. Content except the search box on the top of the page is placed in the List component to build the entire page. Upon entering the page, users can swipe down to simulate a network request for page refresh, scroll the list content with the scenic spot title to stick to the top, and swipe up to simulate a request for adding data when the page is scrolled to its bottom.
Principles
Different ListItem child components are rendered based on the data types of the views in the list.
The Refresh component enables page pull-down operations and displays a refresh animation. In tandem with core components like Swiper and Grid, the List component is utilized to construct the overall page layout. Furthermore, by leveraging the sticky attribute and onReachEnd() event of the List component, alongside the onRefreshing() event of the Refresh component, you can implement features such as simulating data refresh via pull-down, simulating data addition via pull-up, and implementing list header pinning (sticky headers).
Development Procedure
Develop the search box on the top.
Row() {
Text($r('app.string.beijing'))
// ...
TextInput({ placeholder: $r('app.string.want_search')})
// ...
Text($r('app.string.more'))
// ...
} In the first ListItem group of List, use the Swiper component to construct the carousel image content.
List({ space: 12 }) {
ListItem() {
Swiper() {
ForEach(this.swiperContent, (item: SwiperType) => {
Stack({ alignContent: Alignment.BottomStart }) {
Image($r(item.pic))
}
}, (item: SwiperType) => JSON.stringify(item))
}
// ...
.autoPlay(true)
.duration(1000)
.curve(Curve.Linear)
.indicator(
new DotIndicator()
.selectedColor(Color.White)
)
.itemSpace(10)
// ...
}
// ...
} Effect:

In the second ListItem group of List, use the Grid component to construct the page grid area.
List({ space: 12 }) {
ListItem() {
// ...
}
ListItem() {
Grid() {
ForEach(this.gridTitle, (item: Resource) => {
GridItem() {
Column() {
Image($r('app.media.pic1'))
// ...
Text(item)
// ...
}
}
}, (item: Resource) => JSON.stringify(item))
}
.rowsGap(16)
.columnsGap(19)
.columnsTemplate('1fr 1fr 1fr 1fr 1fr')
// ...
}
// ...
} Effect:
Construct the recommended content and list content.
@Builder
scenicSpotDetailBuilder(title: Resource) {
Column() {
Image($r('app.media.pic1'))
// ...
Column() {
Text(title)
// ...
Text() {
Span($r('app.string.group_discount'))
// ...
Span('$999')
// ...
}
.margin({ top: 4, bottom: 4 })
Text() {
Span($r('app.string.group_discount'))
Span('$1999')
}
// ...
}
// ...
}
} List({ space: 12 }) {
ListItem() {
// ...
}
ListItem() {
// ...
}
ListItem() {
Row() {
Image($r('app.media.pic1'))
// ...
Image($r('app.media.pic1'))
// ...
}
// ...
}
ForEach(this.scenicSpotTitle, (item: Resource) => {
ListItemGroup({ header: this.scenicSpotHeader(item) }) {
ForEach(this.scenicSpotArray, (scenicSpotItem: Resource) => {
ListItem() {
this.scenicSpotDetailBuilder(scenicSpotItem);
}
}, (scenicSpotItem: Resource) => JSON.stringify(scenicSpotItem))
}
.borderRadius(this.borderRadiusVal)
}, (item: Resource) => JSON.stringify(item))
// ...
} Place the constructed page content inside the Refresh component, and add the corresponding onReachEnd() and onRefreshing() callbacks to the List and Refresh components respectively, to achieve the effects of simulating data refresh via pull-down and adding list data via pull-up.
Row() {
// ...
}
// ...
Refresh({ refreshing: $$this.isRefreshing }) {
List({ space: 12 }) {
ListItem() {
// ...
}
ListItem() {
// ...
}
ListItem() {
// ...
}
ForEach(this.scenicSpotTitle, (item: Resource) => {
// ...
}, (item: Resource) => JSON.stringify(item))
ListItem() {
Row() {
if (!this.noMoreData) {
LoadingProgress()
// ...
}
Text(this.noMoreData ? $r('app.string.no_more_data') : $r('app.string.loading_more'))
}
// ...
}
// ...
}
// ...
.onReachEnd(() => {
if (this.scenicSpotArray.length >= 20) {
this.noMoreData = true;
return;
}
setTimeout(() => {
this.scenicSpotArray.push('scenic area' + (this.scenicSpotArray.length + 1));
}, 500)
})
}
.onRefreshing(() => {
this.isRefreshing = true;
setTimeout(() => {
this.scenicSpotArray =
this.scenicSpotArray = ['scenic area 1', 'scenic area 2', 'scenic area 3', 'scenic area 4', 'scenic area 5'];
this.noMoreData = false;
this.isRefreshing = false;
}, 2000)
}) Scenario
The sticky effect achieved by nesting Tabs with List is commonly used on the home screens of news and information apps.
In this scenario, Tabs on the home screen is used as an example. In the TabContent area, the List component is used together with other components to construct the list data content. As users swipe up the content on the screen, the tabs in the middle area are pinned to the top.
Principles
The Tabs component can quickly switch between view contents on a page so that users can focus on the currently displayed content, and classify the page contents to improve the page space usage.
Use the Tabs component together with basic components such as Stack, Scroll, Search, and List to build a complete screen. Then, use the nestedScroll attribute of the List component and the calc function to calculate the height, so that the tabs in the middle are always displayed on the top.
Development Procedure
Construct the custom tabBar content of Tabs.
@Builder
tabBuilder(img: Resource, title: Resource, index: number) {
Column() {
Image(img)
// ...
.fillColor(this.currentIndex === index ? '#0a59f7' : '#66000000')
Text(title)
// ...
.fontColor(this.currentIndex === index ? '#0a59f7' : '#66000000')
}
// ...
.onClick(() => {
this.currentIndex = index;
this.tabsController.changeIndex(this.currentIndex);
})
} Tabs({ barPosition: BarPosition.End, controller: this.tabsController }) {
TabContent() {
// ...
}
.tabBar(this.tabBuilder($r('app.media.mine'), $r('app.string.tabBar1'), 0))
// ...
}
// ...
.onChange((index: number) => {
this.currentIndex = index;
}) Effect:

Build the top search area.
Row() {
Image($r('app.media.app_icon'))
// ...
Search({
placeholder: $r('app.string.want_search'),
})
.searchButton('search', { fontSize: 14 })
// ...
Text($r('app.string.search'))
// ...
} Construct the image placeholder area, custom navigation content, and list content.
Scroll(this.scrollController) {
Column() {
Image($r('app.media.pic5'))
// ...
Column() {
Row({ space: 16 }) {
ForEach(this.tabArray, (item: string, index: number) => {
Text(item)
.fontColor(this.currentTabIndex === index ? '#0a59f7' : Color.Black)
.onClick(() => {
this.contentTabController.changeIndex(index);
this.currentTabIndex = index;
})
}, (item: string) => item)
}
// ...
Tabs({ barPosition: BarPosition.Start, controller: this.contentTabController }) {
TabContent() {
List({ space: 10, scroller: this.listScroller }) {
CustomListItem({
imgUrl: $r('app.media.pic1'),
title: $r('app.string.manager_content')
})
// ...
}
// ...
}
.tabBar('follow')
// ...
}
// ...
}
// ...
}
}
// ...
.scrollBar(BarState.Off) Add the nestedScroll attribute to the List component and use the calc function to implement the effect of displaying the customized tab area in the middle on the top.
Tabs({ barPosition: BarPosition.Start, controller: this.contentTabController }) {
TabContent() {
List({ space: 10, scroller: this.listScroller }) {
// ...
}
// ...
.nestedScroll({
scrollForward: NestedScrollMode.PARENT_FIRST,
scrollBackward: NestedScrollMode.SELF_FIRST
})
}
.tabBar('follow')
// ...
}
.barHeight(0)
.height('calc(100% - 100vp)')
.onChange((index: number) => {
this.currentTabIndex = index;
}) Scenario
The two lists are linked in the same direction. The alphabetical list on the right is used for quick indexing and the content list is grouped based on the initial letter. This is usually used on the contacts, city selection, and group selection pages.
This scenario is illustrated using the city list page as an example. The city list data on the left and the alphabetic navigation data on the right are displayed using the List component, while the Stack component enables layered display of the two lists. When users enter the page and scroll the city list on the left, the alphabetical title of the list is pinned to the top and the corresponding alphabetical navigation content on the right is highlighted. When users tap the alphabetical navigation content on the right, the corresponding content is displayed in the city list on the left.
Principles
With the left List serving as the city directory and the right List as the city alphabetical shortcut navigation, individual ListItem components are used to render and display the corresponding data. By utilizing a Stack container component, the alphabetical navigation list overlays the city list. Furthermore, by applying the sticky attribute and the onScrollIndex() method to the respective List components, a synchronized linkage effect between the data of both lists is achieved.
Development Procedure
Use ListItemGroup for the city list to group the current city, hot cities, and city data, and use ListItem to display the specific data in each group.
@Builder
textContent(content: string) {
Text(content)
// ...
} List({ scroller: this.cityScroller }) {
ListItemGroup({ header: this.itemHead($r('app.string.current_city')) }) {
ListItem() {
Text(this.currentCity)
.width('100%')
.height(45)
.fontSize(16)
.padding({ left: 16, top: 12, bottom: 12 })
.textAlign(TextAlign.Start)
.backgroundColor(Color.White)
}
}
ListItemGroup({ header: this.itemHead($r('app.string.popular_cities')) }) {
ForEach(this.hotCities, (item: string) => {
ListItem() {
this.textContent(item);
}
}, (item: string) => item)
}
.divider({
strokeWidth: 1,
color: '#EDEDED',
startMargin: 10,
endMargin: 45
})
ForEach(this.groupWorldList, (item: string) => {
ListItemGroup({ header: this.itemHead(item) }) {
ForEach(this.getCitiesWithGroupName(item), (cityItem: City) => {
ListItem() {
this.textContent(cityItem.city);
}
}, (cityItem: City) => cityItem.city)
}
})
} Use List to display the alphabetical navigation list data on the right.
Column() {
List({ scroller: this.navListScroller }) {
ForEach(this.groupWorldList, (item: string, index: number) => {
ListItem() {
Text(item)
// ...
}
}, (item: string) => item)
}
} Use the Stack container component to overlay the alphabetical navigation content on top of the city list.
Stack({ alignContent: Alignment.End }) {
List({ scroller: this.cityScroller }) {
// ...
}
// ...
Column() {
List({ scroller: this.navListScroller }) {
// ...
}
}
// ...
} Finally, add the sticky attribute to the city list to implement the title sticky effect, and add the onScrollIndex() method. Use the selectNavIndex variable to associate the letter navigation list content and control the selected state of the corresponding letter navigation content.
Add a tap event to the alphabetical navigation list. Within this event, use the scrollToIndex() method of the city list controller (cityScroller) to control and update the display of the city list content, thereby achieving a synchronized linkage effect between the data of both lists.
Stack({ alignContent: Alignment.End }) {
List({ scroller: this.cityScroller }) {
// ...
}
// ...
.onScrollIndex((index: number) => {
this.selectNavIndex = index - 2;
})
Column() {
List({ scroller: this.navListScroller }) {
ForEach(this.groupWorldList, (item: string, index: number) => {
ListItem() {
Text(item)
// ...
.onClick(() => {
this.selectNavIndex = index;
this.isClickScroll = true;
this.cityScroller.scrollToIndex(index + 2, false, ScrollAlign.START);
})
}
}, (item: string) => item)
}
}
// ...
} Scenario
By selecting an item from the first-level list on the left, the data in the second-level list on the right is updated accordingly. This is commonly used in second-level category selection pages such as product category selection and style editing pages.
In this scenario, taking the product category list page as an example, the left category navigation and right navigation content are displayed using the List component. When users enter the page and tap a category on the left navigation, the corresponding details data in the right list is displayed. When users scroll the right list, the list title is pinned to the top, while the corresponding content on the left navigation is highlighted.
Principles
Two separate List components are used on the left and right for implementation, both lists are configured with their respective onScrollIndex() events. In its callback, when a switch in data items is detected, the left List invokes a method to scroll the right List to the corresponding position of the matching category; the right List operates in the exact same manner.
Development Procedure
Use two List components to construct the category navigation data on the left and category content data on the right.
List({ scroller: this.navTitleScroller }) {
ForEach(this.categoryList, (item: NavTitleModel, index: number) => {
ListItem() {
Text(item.titleName)
// ...
}
}, (item: NavTitleModel) => JSON.stringify(item.titleName))
}
// ...
List({ scroller: this.goodsListScroller }) {
ForEach(this.categoryList, (item: NavTitleModel) => {
ListItemGroup({ space: 12, header: this.goodsHeaderBuilder(item.titleName) }) {
ForEach(item.goodsList, (goodsItem: GoodsDataModel) => {
ListItem() {
Row() {
Image(goodsItem.imgUrl)
// ...
Column() {
Text(goodsItem.goodsName)
// ...
Text('$' + goodsItem.price)
// ...
}
// ...
}
// ...
}
}, (goodsItem: GoodsDataModel) => JSON.stringify(goodsItem.goodsId))
}
}, (item: NavTitleModel) => JSON.stringify(item.goodsList))
} Add a tap event to the navigation list on the left, add a onScrollIndex() event to the category details list on the right, and call the listChange method of the custom event. In the listChange method, invoke the scrollToIndex() event of the corresponding list controller based on the value of the isGoods variable to implement the association between the navigation list and category details data.
listChange(index: number, isGoods: boolean) {
if (this.currentTitleId !== index) {
this.currentTitleId = index;
if (isGoods) {
this.goodsListScroller.scrollToIndex(index);
} else {
this.navTitleScroller.scrollToIndex(index);
}
}
} List({ scroller: this.navTitleScroller }) {
ForEach(this.categoryList, (item: NavTitleModel, index: number) => {
ListItem() {
Text(item.titleName)
// ...
.onClick(() => {
this.listChange(index, true);
})
}
}, (item: NavTitleModel) => JSON.stringify(item.titleName))
}
// ...
List({ scroller: this.goodsListScroller }) {
// ...
}
// ...
.onScrollIndex((index: number) => {
this.listChange(index, false)
})