Cherrio LLC
08/01/2023, 7:32 PMLaunchedEffect
using Unit as key in each page, but it gets called first time then anytime the page has been disposed by the Pager.
Is there any way around that behavior? I just want when a user switches a page the previous page should be disposed.Stylianos Gakis
08/01/2023, 7:33 PMCherrio LLC
08/01/2023, 7:38 PMCherrio LLC
08/01/2023, 7:38 PMCherrio LLC
08/01/2023, 7:39 PMxoangon
08/01/2023, 7:57 PMLaunchedEffect
is triggered in all the page changes, as you’re entering the composition phase with each changeCherrio LLC
08/01/2023, 8:02 PMDiposableEffect
, onDispose{}
will not be called when you navigate to page 2Stylianos Gakis
08/01/2023, 8:04 PMStylianos Gakis
08/01/2023, 8:05 PMCherrio LLC
08/01/2023, 8:07 PMStylianos Gakis
08/01/2023, 8:08 PMStylianos Gakis
08/01/2023, 8:12 PMcurrentPage
out in it's public API? Preferably one that's backed by mutable state?
If yes, you can do
val pagerState = rememberPagerState(...)
LaunchedEffect(Unit) {
snapshotFlow { pagerState.currentPage }
.filter { it == X }
.collect { \\ or collectLatest, depending on what you need.
doSomething()
}
}
xoangon
08/01/2023, 8:33 PMLaunchedEffect
would be triggered in any recomposition. What you're saying here makes sense to me, thanks for the explanation!