//list index 가져오기
LazyColumn {
item {
Text(header)
}
itemsIndexed(data) { index, item ->
Item(item, index)
}
}
//list 사이에 padding 적용하기
LazyRow(
horizontalArrangment = Arrangement.spacedBy(8.dp)
) {
items(data) { item ->
Item(item)
}
}
//리스트 상태를 저장
val state = rememberLazyListState()
//스크롤시 처음으로 보이는 아이템
state.firstVisibleItemIndex
stata.firstVisibleItemScrollOffset
//스크롤 맨 위로 올릴 수 있는 버튼 보일지 체크하기
val showScrollToTopButton by remember {
derivedStateOf {
state.firstVisibleItemIndex > 0
}
}
//버튼 클릭시 리스트 맨 위로
val coroutineScope = rememberCoroutineScope()
ScrollToTopButton(
onClick = {
coroutineScope.launch {
//suspend funciton
state.scrollToItem(index = 0)
//또는 animateScrollToItem
}
}
)
//현재 보이는 item 정보
state.layoutInfo.visibleItemsInfo.map { it.index }
//list 총 갯수
state.layoutInfo.totalItemCount
LazyColumn(
state = state
) {
...
}