liangjingkanji / BRV

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

加载更多没有跟随 #369

Closed initchen closed 1 year ago

initchen commented 1 year ago

问题描述

SmartRefreshLayout支持设置setEnableFooterFollowWhenNoMoreData(true)来让加载更多跟随列表底部(列表没有满一屏的情况),但是改为BRV后失效

期望行为

加载更多跟随底部

如何复现

全局设置

SmartRefreshLayout.setDefaultRefreshFooterCreator { _, layout ->
            layout.setEnableFooterFollowWhenNoMoreData(true)
            ClassicsFooter(this)
        }

发起请求 使用BRV:

binding.pageRefreshLayout.onRefresh {
            scope {
                val data = Post<PageResult>(ApiUrl.Subject.PAGE_SIMPLE) {
                    json(mapOf("page" to index, "limit" to 10))
                }.await().data
                addData(data.records) {
                    index < data.pages
                }
            }
        }.showLoading()

使用 SmartRefreshLayout

binding.smartRefreshLayout.setOnRefreshListener {
            scopeNetLife {
                val data = Post<PageResult>(ApiUrl.Subject.PAGE_SIMPLE) {
                    json(mapOf("page" to index, "limit" to 10))
                }.await().data!!
                binding.rvPush.models = data.records
                if (index >= data.pages) {
                    binding.smartRefreshLayout.finishLoadMoreWithNoMoreData()
                }
                binding.smartRefreshLayout.finishRefresh()
            }
        }

布局:

<com.drake.brv.PageRefreshLayout
        android:id="@+id/pageRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_push"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </com.drake.brv.PageRefreshLayout>

<com.scwang.smart.refresh.layout.SmartRefreshLayout
        android:id="@+id/smartRefreshLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/rv_push"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

    </com.scwang.smart.refresh.layout.SmartRefreshLayout>

截图

image image

版本

liangjingkanji commented 1 year ago
  1. 默认情况下PageRefreshLayout会在不满一页时关闭上拉加载更多, 因为作者认为那是不合理和愚蠢的布局显示

  2. 你可以手动开启不满一页显示加载更多, 如果希望全局设置一次, 请使用SmartRefreshLayout的初始化设置监听SmartRefreshLayout.setDefaultRefreshInitializer

setDefaultRefreshFooterCreator并不属于全局初始化设置, 另外加载更多跟随布局不等于不满一页显示加载更多. 请阅读SmartRefreshLayout文档