RecyclerView-FastScroller icon indicating copy to clipboard operation
RecyclerView-FastScroller copied to clipboard

Issues with "Changes sample app to use view pager 2"

Open kaaholst opened this issue 4 years ago • 3 comments

I've experienced various issues in the sample app, after the above commit, which is on the development branch as of 26 Nov 2020.

I put them all here in the same issue, because they might share the same root cause.

  1. When switching tabs he app will sometimes crash with the below stacktrace. Unfortunately I haven't found a way to reliably trigger this, but it does occur frequently.
  2. Display a tab, switch to another tab and then go back to the original tab, will stop the fast scroller handle from moving when the list is scrolled. The fast scroller handle still works. When using the Basic tab, this means that the fast scroller will not become visible when the list is scrolled.

2021-02-05 22:50:22.986 26158-26158/com.qtalk.sample D/RVFastScroller: Touch Action: 1 2021-02-05 22:50:24.590 26158-26158/com.qtalk.sample D/AndroidRuntime: Shutting down VM 2021-02-05 22:50:24.599 26158-26158/com.qtalk.sample E/AndroidRuntime: FATAL EXCEPTION: main Process: com.qtalk.sample, PID: 26158 java.lang.IllegalStateException: Observer com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller$adapterDataObserver$1$1@e29f01d was not registered. at android.database.Observable.unregisterObserver(Observable.java:69) at androidx.recyclerview.widget.RecyclerView$Adapter.unregisterAdapterDataObserver(RecyclerView.java:7537) at com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller.detachFastScrollerFromRecyclerView(RecyclerViewFastScroller.kt:964) at com.qtalk.recyclerviewfastscroller.RecyclerViewFastScroller.onDetachedFromWindow(RecyclerViewFastScroller.kt:381) at android.view.View.dispatchDetachedFromWindow(View.java:17456) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3681) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3673) at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:3673) at android.view.ViewGroup.removeViewInternal(ViewGroup.java:5227) at android.view.ViewGroup.removeViewAt(ViewGroup.java:5174) at androidx.recyclerview.widget.RecyclerView$5.removeViewAt(RecyclerView.java:915) at androidx.recyclerview.widget.ChildHelper.removeViewAt(ChildHelper.java:168) at androidx.recyclerview.widget.RecyclerView$LayoutManager.removeViewAt(RecyclerView.java:8946) at androidx.recyclerview.widget.RecyclerView$LayoutManager.removeAndRecycleViewAt(RecyclerView.java:9217) at androidx.recyclerview.widget.LinearLayoutManager.recycleChildren(LinearLayoutManager.java:1437) at androidx.recyclerview.widget.LinearLayoutManager.recycleViewsFromEnd(LinearLayoutManager.java:1531) at androidx.recyclerview.widget.LinearLayoutManager.recycleByLayoutState(LinearLayoutManager.java:1556) at androidx.recyclerview.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1582) at androidx.recyclerview.widget.LinearLayoutManager.scrollBy(LinearLayoutManager.java:1395) at androidx.recyclerview.widget.LinearLayoutManager.scrollHorizontallyBy(LinearLayoutManager.java:1124) at androidx.recyclerview.widget.RecyclerView.scrollStep(RecyclerView.java:1969) at androidx.recyclerview.widget.RecyclerView$ViewFlinger.run(RecyclerView.java:5476) at android.view.Choreographer$CallbackRecord.run(Choreographer.java:1029) at android.view.Choreographer.doCallbacks(Choreographer.java:841) at android.view.Choreographer.doFrame(Choreographer.java:769) at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:1015) at android.os.Handler.handleCallback(Handler.java:793) at android.os.Handler.dispatchMessage(Handler.java:98) at android.os.Looper.loop(Looper.java:173) at android.app.ActivityThread.main(ActivityThread.java:6698) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:782)

kaaholst avatar Feb 06 '21 14:02 kaaholst

I have the same problem, and found out that rewriting the function registerDataObserver() of the library as follows did seem to circumvent the crash. But I'm not sure this tackles the root of the issue.

The problem seems to be caused because the observer is registered more than once before being detached. It is first registered in initImpl() and then, every time you click and scroll down using the scrollbar, the observer is registered again at line 418.

@shahsurajk would you happen to have any insight on the issue?

By the way, this is the same issue as #43

My temporary fix:

private fun registerDataObserver() {
    if (recyclerView.adapter?.hasObservers() != true) {
        recyclerView.adapter?.registerAdapterDataObserver(adapterDataObserver.value)
    }
}

LunarX avatar Apr 05 '22 12:04 LunarX

I have exactly the same problem and I hope it'll be fixed because it's one of the most popular libraries that I think most developers use!

hamed8080 avatar Apr 07 '22 08:04 hamed8080

I solved it. Check my answer here - solution

SweetD3v avatar Jan 31 '23 07:01 SweetD3v