google / accompanist

A collection of extension libraries for Jetpack Compose
https://google.github.io/accompanist
Apache License 2.0
7.48k stars 602 forks source link

[Pager]HorizontalPager cannot save the AndroidView state. #1238

Closed wilinz closed 2 years ago

wilinz commented 2 years ago

HorizontalPager cannot save the AndroidView state. When switching pages, the AndroidView factory will be triggered, resulting in view recreate. If WebView is used in HorizontalPager, the webpage will be reloaded when switching pages.

Nek-12 commented 2 years ago

I'm facing the same issue with ExoPlayer. The video does not start preparing for display until it's on screen, which results in a delay before playing it and a performance impact.

agent10 commented 2 years ago

I have the same issue with WebView. It keeps reloading every time I switch my tabs. Very annoying.

David-Development commented 2 years ago

Starting with Version 0.19 there was a switch from the previous HorizontalPager to a LazyRow implementation. By definition a LazyRow only shows views inside the viewport thus the WebView keeps reloading every time.

both HorizontalPager and VerticalPager were re-written to be based on LazyRow and LazyColumn respectively https://google.github.io/accompanist/pager/#changes-in-v0190

This is also related to https://github.com/google/accompanist/issues/899 where the support for offscreenPageLimit is discussed.

I noticed myself that in a setup with a Horizontal Pager with only 3 Tabs the tabs on the right hand side are kept and are recycled while tabs on the left are disposed immediately when they leave the viewport.

tengyeekong commented 2 years ago

Seems like Pager don't save the state of the pages and recreate everything in the page when switching pages. Is there any solution for this?

github-actions[bot] commented 2 years ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

lectricas commented 1 year ago

I think its rather obvious that there should be an option to keep the pages in memory. Why google keep making my life complicated? Do they like it?

Nek-12 commented 1 year ago

Using foundation pager you can specify offscreen page limit. No need to vent here.

rs5173 commented 6 months ago

Jetpack Compose is a piece of shit 💩💩💩!!!

BIGGGGGGGGGG 💩💩💩 !!!

jasonjiicloud commented 4 months ago

In my version, HorizontalPager has a parameter: beyondBoundsPageCount, which can specify the number of pages you want to preload before or after the visible ones. When switching pages, the specified one will not reload, it keeps alive.

savvasenok commented 1 month ago

In my version, HorizontalPager has a parameter: beyondBoundsPageCount, which can specify the number of pages you want to preload before or after the visible ones. When switching pages, the specified one will not reload, it keeps alive.

This worked for me! Thanks