After restoring state of RecyclerView and FlexibleAdapter, FastScroll position is wrong or not visible.
On user scrolling FastScroll handle jumps to the correct position.
This issue is visible on example apk on configuration changes on any Fragment with FastScroll.
My particular case:
Save state using Evernote state lib:
@Parcelize
data class RecyclerSavedState(
val position: Int,
val state: Parcelable?,
val adapterState: Bundle?
) : Parcelable
@State
var savedState: RecyclerSavedState? = null
override fun onPause() {
super.onPause()
val state = Bundle()
adapter?.onSaveInstanceState(state)
savedState = RecyclerSavedState(
adapter?.stickyPosition ?: 0,
alertsRecycler?.layoutManager?.onSaveInstanceState(),
state
)
}
Observe items in Fragment:
override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
viewModel.items.observe(viewLifecycleOwner, Observer { newAlertList ->
newAlertList?.let { list ->
adapter?.submitList(list, savedState)
})
}
3. FlexibleAdapter extension:
class RecyclerAdapter(
items: List<AbstractFlexibleItem<>>,
listeners: Any
) : FlexibleAdapter<AbstractFlexibleItem<>>(items, listeners, true) {
private var recyclerSavedState: RecyclerSavedState? = null
FlexibleAdapeter 5.1.0, Android 9.0, Pixel 1
After restoring state of RecyclerView and FlexibleAdapter, FastScroll position is wrong or not visible. On user scrolling FastScroll handle jumps to the correct position.
This issue is visible on example apk on configuration changes on any Fragment with FastScroll.
My particular case:
class RecyclerAdapter( items: List<AbstractFlexibleItem<>>, listeners: Any ) : FlexibleAdapter<AbstractFlexibleItem<>>(items, listeners, true) { private var recyclerSavedState: RecyclerSavedState? = null
}