Skip to content

MessengerBotTeam/compose-free-scroll

 
 

Repository files navigation

Compose Free Scroll

Jetpack Compose library for free scroll (diagonal scroll) modifier

This library provides a freeScroll modifier that allows scrolling in any direction, as opposed to the official horizontalScroll and verticalScroll modifiers that only allow scrolling in one direction at a time. With the freeScroll modifier, you can scroll in any direction simultaneously.

demo.mp4

Installation

In your project's root build.gradle file, add the following:

allprojects {
    repositories {
        maven { url 'https://jitpack.io' }
    }
}

In your app's build.gradle file, add the following:

dependencies {
    implementation 'com.github.chihsuanwu:compose-free-scroll:0.2.3'
}

Usage

To use the freeScroll modifier, simply add it to the modifier chain of a composable that you want to be scrollable.

val freeScrollState = rememberFreeScrollState()
Column(
    modifier = Modifier
        .fillMaxSize()
        .freeScroll(state = freeScrollState)
) {
    // Content ...
}

Note that this modifier uses pointerInput as the underlying implementation, so some pointer events will be consumed.

If you want to use TransformGestures simultaneously, you can use the freeScrollWithTransformGesture modifier.

val freeScrollState = rememberFreeScrollState()
Column(
    modifier = Modifier
        .fillMaxSize()
        .freeScrollWithTransformGesture(
            state = freeScrollState,
            onGesture = { centroid: Offset,
                          pan: Offset,
                          zoom: Float,
                          rotation: Float ->
                // Transform gestures ...
            }
        )
) {
    // Content ...
}

Limitations

Currently, this library still lacks a bounce effect feature. This is limited by the current implementation.

Any contributions are highly appreciated!

About

Jetpack Compose library for free scroll (diagonal scroll) modifier

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages

  • Kotlin 100.0%