*** WARNING: This library is no longer maintained *** An easy way to add a simple 'swipe-and-do-something' behavior to your `RecyclerView` items. Just like in Gmail or Inbox apps.

Overview

SwipeToAction

Download

An easy way to add a simple 'swipe-and-do-something' behavior to your RecyclerView items. Just like in Gmail or Inbox apps.

SwipeToAction Sample

Integration

The lib is available on Maven Central, you can find it with Gradle, please

dependencies {
    compile 'co.dift.ui.swipetoaction:library:1.1'
}

Usage

Check a demo project in the sample/ folder.

  1. The view you'll use for the items should have at least 3 children:
  • the one at the front (the last one or anyone with the tag=front)

  • the one to reveal when you swipe to left (before the front view or anyone with tag=reveal-left)

  • the one to reveal when you swipe to right (before the reveal-left view or anyone with tag=reveal-right)

     <!-- this view reveals when swipe right -->
     <RelativeLayout
        android:tag="reveal-right"
        android:background="@color/accent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_marginLeft="20dp"
            android:tint="@color/icons"
            android:src="@mipmap/ic_favorite_black_24dp"/>
     </RelativeLayout>
    
     <!-- this view reveals when swipe left -->
     <RelativeLayout
        android:tag="reveal-left"
        android:background="@color/primary"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="20dp"
            android:tint="@color/icons"
            android:src="@mipmap/ic_delete_black_24dp"/>
     </RelativeLayout>
    
     <!-- this is the item front view -->
     <RelativeLayout
        android:tag="front"
        android:background="@color/item_background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:padding="@dimen/item_padding">
    
        <TextView
            android:id="@+id/title"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_toRightOf="@+id/image"
            android:singleLine="true"
            android:textSize="16dp"
            android:textStyle="bold" />
    
     </RelativeLayout>
  1. In the adapter for your RecyclerView create a ViewHolder that extends SwipeToAction.ViewHolder. For instance, in the sample project I have a list of books and my items are instances of a Book class, therefore, the ViewHolder inside the adapter looks like this:

       public class BookViewHolder extends SwipeToAction.ViewHolder<Book> {
         ...
         public BookViewHolder(View v) {
           super(v);
           ...
         }
       }

    Also, in the onBindViewHolder method remember to set the item data to the view holder instance

      @Override
      public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        Book item = items.get(position);
        BookViewHolder vh = (BookViewHolder) holder;
        vh.data = item;
    
        ...
    
      }
  2. Set the RecyclerView as usual to create a vertical list, set the previous adapter and instantiate SwipeToAction providing the recyclerView instance and a swipe listener SwipeToAction.SwipeListener<T>

      recyclerView = (RecyclerView) findViewById(R.id.recycler);
      LinearLayoutManager layoutManager = new LinearLayoutManager(this);
      recyclerView.setLayoutManager(layoutManager);
      recyclerView.setHasFixedSize(true);
    
      adapter = new BooksAdapter(this.books);
      recyclerView.setAdapter(adapter);
    
      swipeToAction = new SwipeToAction(recyclerView, new SwipeToAction.SwipeListener<Book>() {
        @Override
        public boolean swipeLeft(final Book itemData) {
            //do something
            return true; //true will move the front view to its starting position
        }
    
        @Override
        public boolean swipeRight(Book itemData) {
            //do something
            return true;
        }
    
        @Override
        public void onClick(Book itemData) {
            //do something
        }
    
        @Override
        public void onLongClick(Book itemData) {
            //do something
        }
      });

License

Copyright (C) 2015 Dift.co

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
You might also like...
Android library defining adapter classes of RecyclerView to manage multiple view types
Android library defining adapter classes of RecyclerView to manage multiple view types

RecyclerView-MultipleViewTypeAdapter RecyclerView adapter classes for managing multiple view types Release Note [Release Note] (https://github.com/yqr

Pumped up RecyclerView

##Description This is an attempt to make RecyclerView easier to use. Features built in: ProgressBar while adapter hasn't been set EmptyView if adapter

 An adapter which could be used to achieve a parallax effect on RecyclerView.
An adapter which could be used to achieve a parallax effect on RecyclerView.

android-parallax-recycleview Integration Step 1. Add the JitPack repository to your build file repositories { maven { url "https://jitpack

A Fast Scroller for the RecyclerView world!
A Fast Scroller for the RecyclerView world!

RecyclerViewFastScroller The RecyclerViewFastScroller is a widget that can be added to a layout and connected to a RecyclerView for fast scrolling. Th

ItemDecoration for RecyclerView using LinearLayoutManager for Android
ItemDecoration for RecyclerView using LinearLayoutManager for Android

RecyclerItemDecoration RecyclerItemDecoration allows you to draw divider between items in recyclerview with multiple ViewType without considering item

[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView
[UNMAINTAINED] Sticky Headers decorator for Android's RecyclerView

This project is no longer being maintained sticky-headers-recyclerview This decorator allows you to easily create section headers for RecyclerViews us

👇 Easy Google Photos style multi-selection for RecyclerViews, powered by Kotlin and AndroidX.
👇 Easy Google Photos style multi-selection for RecyclerViews, powered by Kotlin and AndroidX.

Drag Select Recycler View This library allows you to implement Google Photos style multi-selection in your apps! You start by long pressing an item in

Android library to display a ListView whose cells are not rigid but flabby and react to ListView scroll.
Android library to display a ListView whose cells are not rigid but flabby and react to ListView scroll.

FlabbyListView This library is not maintained anymore and there will be no further releases Android library to display a ListView which cells are not

An android library for section headers that stick to the top
An android library for section headers that stick to the top

StickyListHeaders StickyListHeaders is an Android library that makes it easy to integrate section headers in your ListView. These section headers stic

Comments
  • how to set durations....

    how to set durations....

    your lib is so goooood!!

    thx..!!

    but i want customized durations

    private static final int SWIPE_ANIMATION_DURATION = 300;
    private static final int RESET_ANIMATION_DURATION = 500;
    private static final int REVEAL_THRESHOLD = 50;
    private static final int SWIPE_THRESHOLD_WIDTH_RATIO = 5;
    private static final int LONG_PRESS_TIME = 500;
    

    but i can't find solution...

    opened by wackijaki 0
  • pointerIndex out of Range error

    pointerIndex out of Range error

    Sometimes I get this error when I am scrolliing. Here is stacktrace:

    java.lang.IllegalArgumentException: pointerIndex out of range at android.view.MotionEvent.nativeGetAxisValue(Native Method) at android.view.MotionEvent.getX(MotionEvent.java:2069) at co.dift.ui.SwipeToAction$1.onTouch(SwipeToAction.java:91) at android.view.View.dispatchTouchEvent(View.java:7784) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2210) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1945) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917) at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:2216) at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1917)

    opened by Davit-Al 4
  • Fix for when reveal views have clickable control

    Fix for when reveal views have clickable control

    Previously if we added a button with its setOnClickListener it will crash if we attempt to swipe (left or right) by starting with our finger directly over the button. Although the button is "hidden" behind the "front" view.

    So this fix is mainly to keep both the reveal panels invisible (GONE) when then "front" view is covering them completely. I think this is probably what most developers would expect the default behavior to be.

    opened by francoishill 0
Owner
Victor Calvello
Co-founder & CEO @ Underscope | React Native
Victor Calvello
Android library providing simple way to control divider items (ItemDecoration) of RecyclerView

RecyclerView-FlexibleDivider Android library providing simple way to control divider items of RecyclerView Release Note [Release Note] (https://github

Yoshihito Ikeda 2.4k Dec 18, 2022
An Android Animation library which easily add itemanimator to RecyclerView items.

RecyclerView Animators RecyclerView Animators is an Android library that allows developers to easily create RecyclerView with animations. Please feel

Daichi Furiya 11.2k Jan 5, 2023
A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView.

RecyclerViewSwipeDismiss A very easy-to-use and non-intrusive implement of Swipe to dismiss for RecyclerView. Preview How to use Add these lines to yo

xcodebuild 431 Nov 23, 2022
Android ListView that mimics a GridView with asymmetric items. Supports items with row span and column span

AsymmetricGridView An Android custom ListView that implements multiple columns and variable sized elements. Please note that this is currently in a pr

Felipe Lima 1.8k Jan 7, 2023
A Paging GridView with the same behavior as PagingListView.

PagingGridView PagingGridView has the ability to add more items on it like PagingListView does. Basically is a GridView with the ability to add more i

Nicolas Jafelle 279 Dec 29, 2022
Kotlin way of building RecyclerView Adapter 🧩. You do not have to write RecyclerView Adapters again and again and suffer from handling of different view types. Kiel will help you.

Kiel Kiel is a RecyclerView.Adapter with a minimalistic and convenient Kotlin DSL which provides utility on top of Android's normal RecyclerView.Adapt

ibrahim yilmaz 370 Jan 2, 2023
Android library to achieve in an easy way, the behaviour of the home page in the Expedia app, with a pair of auto-scroll circular parallax ListViews.

ListBuddies This library is not maintained anymore and there will be no further releases Android library of a pair of auto-scroll circular parallax Li

JPARDOGO 970 Dec 29, 2022
[] A swipe menu for ListView.

SwipeMenuListView A swipe menu for ListView. Demo Usage Add dependency dependencies { compile 'com.baoyz.swipemenulistview:library:1.3.0' } Step 1

星一 3.5k Dec 16, 2022
Dividers is a simple Android library to create easy separators for your RecyclerViews

Dividers Dividers is an Android library to easily create separators for your RecyclerViews. It supports a wide range of dividers from simple ones, tha

Karumi 490 Dec 28, 2022
. Android library that integrate sticky section headers in your RecyclerView

recyclerview-stickyheaders Recyclerview-stickyheaders is an Android library that makes it easy to integrate section headers in your RecyclerView. Thes

null 968 Nov 10, 2022