美文网首页Android开发Android开发Android技术知识
Compose 下拉刷新库——ComposeRefreshLay

Compose 下拉刷新库——ComposeRefreshLay

作者: 辰渊 | 来源:发表于2023-01-11 12:10 被阅读0次

在进行Compose应用开发时,发现没有下拉刷新上拉加载,没有Android原生提供的SwipeRefreshLayout。查看官方simple样例(https://github.com/android/compose-samples),在官方样例的基础进行简单封装,编写了ComposeRefreshLayout(github:https://github.com/xiaoyu00/ComposeRefreshLayout)

效果展示

xg.gif

说明

因刷新头与上拉加载View全部为自定义,比较灵活,所以本库里不包含默认刷新头与加载View,效果中的刷新头与加载View代码在app目录下的simple里

使用

引入

        repositories {
            ...
            maven { url 'https://jitpack.io' }
        }
dependencies {
       implementation 'com.github.xiaoyu00:ComposeRefreshLayout:1.0.0'
    }

下拉刷新

RefreshLayout(refreshingState = refreshing, onRefresh = {
            refreshing = true
            scope.launch {
                delay(2000)
                refreshing = false
            }
        }, refreshHeader = { offset, state ->
           // RefreshDefaultHeader(state, offset)
           // RefreshLottieHeader(state)
           // 你的刷新Header(上面刷新头代码在app下simple里)
          ...
        }) {
            // 刷新内容
            ...
    }

上拉加载

LoadMoreLayout(loadMoreState = isLoadMore, onLoadMore = {
        isLoadMore = true
        scope.launch {
            delay(2000)
            isLoadMore = false
        }
    }, loadMore = { offset, state ->
        // LoadMoreDefaultView(state, isNoMore)(此代码在app下simple里)
    // 你的加载View
        ...
    }) {
        // 加载内容
         ...
    }

组合使用

LoadMoreLayout(loadMoreState = isLoadMore, onLoadMore = {
        isLoadMore = true
        scope.launch {
            delay(2000)
            isLoadMore = false
        }
    }, loadMore = { offset, state ->
        // LoadMoreDefaultView(state, isNoMore)(此代码在app下simple里)
        // 你的加载View
    ...
    }) {
        RefreshLayout(refreshingState = refreshing, onRefresh = {
            refreshing = true
            scope.launch {
                delay(2000)
                refreshing = false
            }
        }, refreshHeader = { offset, state ->
            //RefreshDefaultHeader(state, offset) (此刷新头代码在app下simple里)
            // 你的刷新Header
      ...
        }) {
            //内容
      ...
        }
    }

相关文章

网友评论

    本文标题:Compose 下拉刷新库——ComposeRefreshLay

    本文链接:https://www.haomeiwen.com/subject/vhkvcdtx.html