Does `HorizontalPager` save/store the next and pre...
# compose
a
Does
HorizontalPager
save/store the next and previous pages/composables like
viewPager2
by default? if not, can I do it with
HorizontalPager
? I want the same smooth transition of
viewPager2
and see the two pages while swiping between them, is this possible with
HorizontalPager
?
c
I can't tell you how it works under the hood, though the source code isn't humongous so you could probably look into it yourself, but you'll be hard pressed to find any differences between
ViewPager*
and
HorizontalPager
at least in my trivial usage.
I have noticed that it can be a tiny bit janky, but I have only been using the debug builds of my application, so imagine a release build will result in less jank
a
For my usecase, each page has a bitmap to load, so it's so unsmooth transition in compare to
viewPager
which saves the next and previous bitmaps, therefore that transition would be more smoother.
c
I think you need to model the state to match what you want a bit more. If you held the bitmaps outside of the scope of the pager, and simply passed them in, you'd have ultimate control over the lifespan of the bitmaps. Though, you should be loading the images off the main thread so it shouldn't be janking up your paging.
m
I have certainly seen this behavior. I have a modifier that fires whenever a composable is first added to a composition and the lifecycle is in the resumed state. If i put this modifier on the pages of a HorizontalPager, it was firing several times. Initially for the 1st and 2nd page. Then if i swipe it along, it would fire for the 3rd page (because the second one was already in the composition, even though it hadn't actually been visible).
It makes sense, because under the hood, it's powered by LazyRow or LazyColumn (depending on your orientation), and that also keeps additional items in the composition to allow for smoother scrolling. And yes, debug builds are dirt slow, so try it with the release build before you assume any jank is related to your code or certain controls.
109 Views