I've found strange behavior in HorizontalPager.
Pages beyond the bounds never call onDispose
inside DisposableEffect
. In other words, what kind of key DisposableEffect
must consume in order to trigger onDispose
once the page becomes "inactive"(stops composing)?
In my case, there are 5 pages of content for the pager. Using beyondBoundsPageCount == 1
there are always 2-3 pages composed at the time, while others aren't.
The screen with pager:
...
HorizontalPager(
pageCount = pages.size,
state = pagerState,
beyondBoundsPageCount = 1
) { index ->
val page = pages[index]
PageScreen(page, index)
}
...
The page itself:
@Composable
fun PageScreen(
pageData: PageData,
index: Int
) {
DisposableEffect(key1 = Unit) { // What kind of key there must be
Timber.d("DisposableEffect body at $index")
onDispose {
// The block which is never gets called
Timber.d("DisposableEffect onDispose at $index")
}
}
}
P.S.:
Compose version is stable 1.4.1
HorizontalPager is from androidx.compose.foundation.pager.HorizontalPager