Roar Gronmo
11/23/2019, 3:45 PMBruno_
11/23/2019, 4:21 PM@Composable
fun Scroller(
onNextPage: (page: Int) -> Unit,
child: @Composable() () -> Unit
) {
val scrollerPosition: ScrollerPosition = +memo { scroller }
VerticalScroller(scrollerPosition, { pos: Px, maxPos: Px ->
scrollerPosition.value = pos
if (pos.value > maxPos.value - 500) {
onNextPage(currentPage)
currentPage++
}
}) {
child()
}
}
Leland Richardson [G]
11/23/2019, 4:43 PMManuel Wrage
11/23/2019, 6:32 PMLeland Richardson [G]
11/24/2019, 5:31 PMRoar Gronmo
11/24/2019, 8:10 PMBruno_
11/25/2019, 7:58 AM@Composable
fun PagedVerticalScroller(
onNextPage: (page: Int) -> Unit,
child: @Composable() () -> Unit
) {
var currentPage = 0
val scrollerPosition: ScrollerPosition = +memo { ScrollerPosition() }
VerticalScroller(scrollerPosition, { pos: Px, maxPos: Px ->
scrollerPosition.value = pos
if (pos.value > maxPos.value - 500) {
onNextPage(currentPage)
currentPage++
}
}) {
child()
}
}
Roar Gronmo
11/25/2019, 9:10 AMRoar Gronmo
11/25/2019, 11:40 AMBruno_
11/25/2019, 12:16 PMBruno_
11/25/2019, 12:17 PMManuel Wrage
11/25/2019, 12:58 PMval items = (1..100_000).toList()
ScrollableList(
items = items,
itemSizeProvider = { 48.dp }
) { _, item ->
ListItem(text = +memo { "Item $item" })
}
The only downside is that it needs to know the size of each item in advance.Roar Gronmo
11/25/2019, 2:57 PMManuel Wrage
11/25/2019, 3:14 PMRoar Gronmo
11/27/2019, 10:29 AM