GithubHelp home page GithubHelp logo

zj565061763 / compose-swiperefresh Goto Github PK

View Code? Open in Web Editor NEW
7.0 3.0 0.0 507 KB

Android compose swipe refresh library, it is support refresh in vertical or horizontal orientation.

License: MIT License

Kotlin 100.00%
android compose horizontal swipe-refresh vertical

compose-swiperefresh's Introduction

Gradle

Sample

Vertical Horizontal Custom behavior
// Your ui state.
val uiState by viewModel.uiState.collectAsState()

FSwipeRefresh(
    // Sync ui state in the start direction
    isRefreshingStart = uiState.isRefreshing,

    // Sync ui state in the end direction.
    isRefreshingEnd = uiState.isLoadingMore,

    onRefreshStart = {
        // Refresh in the start direction.
    },

    onRefreshEnd = {
        // Refresh in the end direction.
    },
    // ...
) {
    LazyColumn {
        //...
    }
}

// Horizontal orientation.
FSwipeRefresh(
    orientationMode = OrientationMode.Horizontal,
    // ...
) {
    LazyRow {
        //...
    }
}

Indicator style

It is easy to customize the indicator style, here is a quick sample:

FSwipeRefresh(
    indicatorStart = {
        // Custom indicator style for the start direction.
        CustomizedIndicator()
    },
    //...
) {
    //...
}

@Composable
private fun CustomizedIndicator() {
    // Get the FSwipeRefreshState.
    val state = checkNotNull(LocalFSwipeRefreshState.current)

    // Get the container api which is provided to the indicator.
    val containerApi = checkNotNull(LocalContainerApiForIndicator.current)

    Box(
        modifier = Modifier.fillMaxWidth(),
        contentAlignment = Alignment.Center
    ) {

        val text = if (state.isRefreshing) {
            "Refreshing..."
        } else {
            if (containerApi.reachRefreshDistance && state.refreshState == RefreshState.Drag) {
                "Release to refresh"
            } else {
                "Pull to refresh"
            }
        }

        Text(text)
    }
}

Well that is it, if you want to learn more about how to customize the indicator style check the DefaultSwipeRefreshIndicator ContainerApiForIndicator

Indicator mode

Above Drag
Below Boundary
val state = rememberFSwipeRefreshState {
    // Set indicator mode for the start direction. 'Above' is the default indicator mode.
    it.startIndicatorMode = IndicatorMode.Above

    // Set indicator mode for the end direction.
    it.endIndicatorMode = IndicatorMode.Above
}

FSwipeRefresh(
    state = state,
    // ...
) {
    //...
}

The behavior of IndicatorMode is controlled by ContainerApiForSwipeRefresh.

Here is an example of how to customize the indicator mode behavior, click here for details.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.