verticalswipe

Implementation vertical swipe behavior for Coordinator Layout

License

License

GroupId

GroupId

ru.turlir.android
ArtifactId

ArtifactId

verticalswipebehavior
Last Version

Last Version

1.2.0
Release Date

Release Date

Type

Type

aar
Description

Description

verticalswipe
Implementation vertical swipe behavior for Coordinator Layout
Project URL

Project URL

https://github.com/pik-software/android-verticalSwipeBehavior
Source Code Management

Source Code Management

https://github.com/pik-software/android-verticalSwipeBehavior

Download verticalswipebehavior

How to add to project

<!-- https://jarcasting.com/artifacts/ru.turlir.android/verticalswipebehavior/ -->
<dependency>
    <groupId>ru.turlir.android</groupId>
    <artifactId>verticalswipebehavior</artifactId>
    <version>1.2.0</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/ru.turlir.android/verticalswipebehavior/
implementation 'ru.turlir.android:verticalswipebehavior:1.2.0'
// https://jarcasting.com/artifacts/ru.turlir.android/verticalswipebehavior/
implementation ("ru.turlir.android:verticalswipebehavior:1.2.0")
'ru.turlir.android:verticalswipebehavior:aar:1.2.0'
<dependency org="ru.turlir.android" name="verticalswipebehavior" rev="1.2.0">
  <artifact name="verticalswipebehavior" type="aar" />
</dependency>
@Grapes(
@Grab(group='ru.turlir.android', module='verticalswipebehavior', version='1.2.0')
)
libraryDependencies += "ru.turlir.android" % "verticalswipebehavior" % "1.2.0"
[ru.turlir.android/verticalswipebehavior "1.2.0"]

Dependencies

runtime (2)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk7 jar 1.4.31
androidx.coordinatorlayout » coordinatorlayout jar 1.1.0

Project Modules

There are no modules declared in this project.

VerticalSwipeBehavior

VerticalSwipeBehavior is a small and flexible vertical swipe behavior for android CoordinatorLayout. Moves the released view at the given vertical position.

Example

Download

Download

Check repository

allprojects {
    repositories {
        jcenter()
    }
}

Add dependency in to build.gradle

dependencies {
    implementation 'io.apiqa.android:verticalswipebehavior:1.0.0'
}

Usage

You should have CoordinatorLayout in parent view. Add tag app:layout_behavior="io.apiqa.android.verticalswipe.VerticalSwipeBehavior" to your banner. Padding or margin is optional for positioning. View top is a start point for animation.

<androidx.coordinatorlayout.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <TextView
        android:id="@+id/drag"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/drag_me"
        app:layout_behavior="io.apiqa.android.verticalswipe.VerticalSwipeBehavior" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Set sideEffect, clamp and settle into VerticalSwipeBehavior for customize banner movement.

val drag = findViewById<View>(R.id.drag)
VerticalSwipeBehavior.from(drag).apply {
   sideEffect = NegativeFactorFilterSideEffect(AlphaElevationSideEffect())
   clamp = BelowFractionalClamp(minFraction = 3f)
   settle = SettleOnTopAction()
}

Details

  • SideEffect – Changes view properties depending on the progress of movement. Default implementation AlphaElevationSideEffect change alpha and elevation of view. You may use NegativeFactorFilterSideEffect for simple composition of behavior. WithoutSideEffect does not change any properties of view. PropertySideEffect - common way for changing several properties of view.
class AlphaElevationSideEffect: SideEffect {

    override fun apply(child: View, factor: Float) {
        child.elevation = elevation * (1f - abs(factor)) // special for elevation-aware view
        child.alpha = 1f - abs(factor)
    }
}
  • VerticalClamp – Have limits on moving view vertically. It is often necessary to limit movement to a part of the height of view. This is done by FractionClamp. Also you can use SensitivityClamp for tuning sensitivity.
class FractionClamp(private val maxFraction: Float = 1f, private val minFraction: Float = 1f): VerticalClamp {

    override fun constraint(height: Int, top: Int, dy: Int): Int {
        val min = min(top, originTop + (height * minFraction).toInt())
        return max(min, originTop - (height * maxFraction).toInt())
    }

    override fun downCast(distance: Int, top: Int, height: Int, dy: Int): Float {
        return distance / (height * maxFraction)
    }

    override fun upCast(distance: Int, top: Int, height: Int, dy: Int): Float {
        return distance / (height * minFraction)
    }
}
  • PostAction – Responsible for changing view position after swipe is completed. ViewDragHelper is used for animation moving of view in consideration of pointer speed. OriginSettleAction moves the view to the starting position.
class OriginSettleAction: PostAction {

    override fun releasedBelow(helper: ViewDragHelper, diff: Int, child: View): Boolean {
        return helper.settleCapturedViewAt(child.left, originTop)
    }

    override fun releasedAbove(helper: ViewDragHelper, diff: Int, child: View): Boolean {
        return helper.settleCapturedViewAt(child.left, originTop)
    }
}

Blogs

Пишем гибкий VerticalSwipeBehavior | Хабр

ru.turlir.android

PIK Digital

Versions

Version
1.2.0