airbnb / epoxy

Epoxy is an Android library for building complex screens in a RecyclerView
https://goo.gl/eIK82p
Apache License 2.0
8.5k stars 733 forks source link

current RecyclerView position #378

Closed Yumcoder-dev closed 6 years ago

Yumcoder-dev commented 6 years ago

suppose we have two layouts for land and portrait, how to save and restore current RecyclerView(with TypedEpoxyController) position?

elihart commented 6 years ago

RecyclerView automatically saves its position as part of saved instance state. make sure your view state is getting saved. the only gotcha is that epoxy models must be set on the RecyclerView before view state is restored

Yumcoder-dev commented 6 years ago

Let me explain it in another real scenario: in a chat message list, we want to save last message id (set in epoxy model id) that seen by the user. If the user left the list and later back to it, new data will be fetched from the server and the list is constructed but we want to scroll to the last seen message (epoxy_model_id = message_id)

elihart commented 6 years ago

That should be easy enough. You will have to:

sauyee333 commented 6 years ago

I have a similar issue with Carousel. I am using fragment and only onPaused is called before starting another fragment. When back to the recyclerview fragment, only onCreateView/onViewCreated/onResume are called. So calling onSaveInstanceState does not help. How to we deal with saving state for Carousel (multiple horizontal recyclerview) in fragment? Thanks.

elihart commented 6 years ago

Closing since @sauyee333 opened https://github.com/airbnb/epoxy/issues/385 and yumcoder seems to have this solved