scwang90 / SmartRefreshLayout

🔥下拉刷新、上拉加载、二级刷新、淘宝二楼、RefreshLayout、OverScroll,Android智能下拉刷新框架,支持越界回弹、越界拖动,具有极强的扩展性,集成了几十种炫酷的Header和 Footer。
https://segmentfault.com/a/1190000010066071
Apache License 2.0
24.94k stars 4.96k forks source link

TwoLevelHeader调用finishTwoLevel后,随机出现二楼没关闭问题 #1387

Open goodluckier opened 3 years ago

goodluckier commented 3 years ago

` <com.scwang.smart.refresh.layout.SmartRefreshLayout android:id="@+id/swl_news_list" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@android:color/transparent" android:visibility="visible" app:srlDragRate="1">

    <com.scwang.smart.refresh.header.TwoLevelHeader
        android:id="@+id/two_level_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:srlEnablePullToCloseTwoLevel="true">

        <com.ruanmei.ithome.views.LogoRefreshHeader
            android:id="@+id/srl_refresh_header"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </com.scwang.smart.refresh.header.TwoLevelHeader>

    <com.iruanmi.multitypeadapter.MyRecyclerView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/transparent"
        android:clipToPadding="false"
        android:paddingBottom="60dp"
        android:scrollbarThumbVertical="@drawable/shape_scroll_bar"
        android:scrollbars="vertical" />
</com.scwang.smart.refresh.layout.SmartRefreshLayout> `

关闭时调用two_level_header.finishTwoLevel();

我的二楼布局写在另一个页面中,通过库的下拉监听动画模仿二楼出现。

不知道为什么调用关闭了,却没走onStateChanged

scwang90 commented 2 years ago

我尝试了一下,没能重现这个问题

建议自己断点调试一下 TwoLevelHeader 中的代码,看看 mRefreshKernel 是不是 等于 null

    /**
     * 结束二级刷新
     * @return TwoLevelHeader
     */
    public TwoLevelHeader finishTwoLevel() {
        final RefreshKernel refreshKernel = mRefreshKernel;
        if (refreshKernel != null) {
            refreshKernel.finishTwoLevel();
        }
        return this;
    }

如果 mRefreshKernel != null 在单步进去看看状态是不是 RefreshState.TwoLevel

@Override
        public RefreshKernel finishTwoLevel() {
            if (mState == RefreshState.TwoLevel) {
                mKernel.setState(RefreshState.TwoLevelFinish);
                if (mSpinner == 0) {
                    moveSpinner(0, false);
                    notifyStateChanged(RefreshState.None);
                } else {
                    animSpinner(0).setDuration(mFloorDuration);
                }
            }
            return this;
        }
KIDD-4869 commented 2 years ago

我也出现了这样的问题,而且打了断点看了state是TwoLevelReleased,这个根源我没去深究,现在的做法是关闭二楼时手动用kernel将状态调为RefreshState.TwoLevel。

TokenYc commented 1 year ago

应该是因为RefreshState.TwoLevel这个状态是在动画结束后设置的,所以在动画未结束前调用finish,状态是Released,会出现无法关闭的情况。