Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

com.github.gryzor:swipenolib

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

com.github.gryzor:swipenolib

A very simple implementation of a RecyclerView ItemTouchHelper

  • 1.0.0
  • Source
  • Maven
  • Socket score

Version published
Maintainers
1
Source

SwipeNoLib

A very simple implementation of a RecyclerView ItemTouchHelper.

Adding swipe to RecyclerView cells doesn't need a lot of code, you don't need a library, hence why this library exists… ¯\_(ツ)_/¯

SwipeNoLib

There are only two classes involved: RecyclerViewItemSwipeHelper and RecyclerViewSwipeHelperDecorator.

The former is the one that deals with the touch, drag and drawing of the background; the later is in charge of drawing a background after an item has been removed. Only the Swipe helper is needed, the decorator is optional.

How To Use?

  1. Add the Gradle dependency:
compile 'com.github.Gryzor:SwipeNoLib:v1.0.6'

Remember this is a Jitpack.io artifact so you also need to add:

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

to your root build.gradle at the end of repositories.

It's the one that usually says:

// Top-level build file where you can add configuration options common to all sub-projects/modules.

  1. Use the supplied Builder to construct an instance of the swipe helper like so:
        new RecyclerViewItemSwipeHelper.Builder()
                .setBackgroundColor(new ColorDrawable(Color.RED))
                .setSwipeListener(new RecyclerViewItemSwipeHelper.OnSwipeListener() {
                    @Override
                    public void onItemSwiped(final int position) {
                        // Do whatever you want, like recyclerViewAdapter.remove(position)
                    }
                })
                .swipeToStart()
                .setDeleteDecorationColor(Color.WHITE)
                .setDeleteImage(getDrawable(R.drawable.vg_clear_black_24dp))
                .disableSwipeOnPositions(0, 3)
                .disableSwipeOnLastItem()
                .buildAndAttach(this, recyclerView);

If you want to display text instead of an icon, you can use:

                .swipeToStart()
                .setDeleteDecorationColor(Color.WHITE)
                .setDeleteText("DELETE")
                .setDeleteTextSize(42)
                .disableSwipeOnPositions(0, 3)
                .disableSwipeOnLastItem()
                .buildAndAttach(this, recyclerView);

Notice how you have to remove setDeleteImage. The Decoration Color also affects the text.

Additionally you can build and attach later by using:

ItemTouchHelper helper = new RecyclerViewItemSwipeHelper.Builder()
						...
						.build(this);

helper.attachToRecyclerView(recyclerView);

If you also want the benefit from the decorator to animate the background color while RecyclerView is animating its childs, then you need to:

        new RecyclerViewSwipeHelperDecorator.Builder()
                .setBackgroundColor(new ColorDrawable(Color.RED))
                .buildAndAdd(recyclerView);

or if you want to pre-build this and then add it, you can:

        RecyclerView.ItemDecoration decorator = new RecyclerViewSwipeHelperDecorator.Builder()
                .setBackgroundColor(new ColorDrawable(Color.RED))
                .build();

         // later…
        recyclerView.addItemDecoration(decorator);

If you don't want to use this library, feel free to grab the code from:

RecyclerViewItemSwipeHelper

and

RecyclerViewSwipeHelperDecorator

Based upon the implementation seen here by Neman Jakovacevic.

   Copyright 2017 Martin Marconcini

   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.

FAQs

Package last updated on 10 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc