liangjingkanji / BRV

[使用文档] Android 快速构建 RecyclerView, 比 BRVAH 更简单强大
http://liangjingkanji.github.io/BRV/
MIT License
2.49k stars 317 forks source link

使用autoRefresh时,使用TabLayout+ViewPager2快速切换会导致中间的onRefresh不被调用到。 #408

Closed parcool closed 7 months ago

parcool commented 7 months ago

经过简单排查发现:

@Override
protected void onDetachedFromWindow() {
    super.onDetachedFromWindow();
    mAttachedToWindow = false;
    mManualLoadMore = true;
    animationRunnable = null;
    if (reboundAnimator != null) {
        Animator animator = reboundAnimator;
        animator.removeAllListeners();
        reboundAnimator.removeAllUpdateListeners();
        reboundAnimator.setDuration(0);//cancel会触发End调用,可以判断0来确定是否被cancel
        reboundAnimator.cancel();//会触发 cancel 和 end 调用
        reboundAnimator = null;
    }
......
}

SmartRefershLayout里的onDetachedFromWindow执行了(中间那个tab的),这会导致刷新不被调用到。看上去是SmartRefreshLayout本身的锅,但这个问题怎么解决呢?

liangjingkanji commented 7 months ago

能fork仓库复现下问题吗? 我猜测不到原因和你具体怎么写的(工作繁忙尽可能直接展示问题) brv已经开源五年来看不应该存在这么明显的bug

parcool commented 7 months ago

已fork仓库并复现。 仓库地址:https://github.com/parcool/BRV

Screen_recording_20231201_125559.webm 从视频中可以看到,第二页(评论页),界面是空的。

liangjingkanji commented 7 months ago

跨标签切换会存在该问题, 具体怎么修复SmartRefreshLayout这个问题我也不清楚, 或许你应该给作者反馈下

给几个建议吧

  1. 初次使用缺省页体验更好, autoRefresh()改为showLoading()
  2. 懒加载, 在Fragment.onResume去请求网络
liangjingkanji commented 7 months ago

我才发现因为你使用了ViewPager2, 非必要并不推荐该控件, 存在的问题太多了

以后使用ViewPager2自己排查问题吧, 太多这种问题浪费时间了