Convert Figma logo to code with AI

luckybilly logoSmartSwipe

An android library to make swipe more easier and more powerful. Android各种侧滑,有这一个就够了

2,065
261
2,065
33

Top Related Projects

10,798

Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate situation when grid, list and other layouts in the same recyclerview.

7,700

A declarative framework for building efficient UIs on Android.

8,512

Epoxy is an Android library for building complex screens in a RecyclerView

Flexible multiple types for Android RecyclerView.

Flexbox for Android

A SnapHelper that snaps a RecyclerView to an edge.

Quick Overview

SmartSwipe is an Android library that provides a comprehensive solution for implementing swipe gestures in Android applications. It offers a wide range of swipe actions and configurations, allowing developers to easily add swipe functionality to various UI elements such as activities, fragments, and views.

Pros

  • Extensive customization options for swipe gestures
  • Supports multiple swipe directions and actions
  • Easy integration with existing Android projects
  • Smooth and responsive swipe animations

Cons

  • Limited documentation in English
  • May have a learning curve for complex configurations
  • Potential performance impact on older devices with many swipe listeners
  • Not actively maintained (last update was in 2019)

Code Examples

  1. Basic swipe-to-finish activity:
SmartSwipe.wrap(this)
    .addConsumer(new ActivitySlidingBackConsumer(this))
    .enableLeft();
  1. Adding swipe-to-refresh functionality:
SmartSwipeRefresh.createClassicRefresh(recyclerView)
    .setOnRefreshListener(new SmartSwipeRefresh.OnRefreshListener() {
        @Override
        public void onRefresh() {
            // Perform refresh action
        }
    });
  1. Creating a swipeable drawer:
SmartSwipe.wrap(this)
    .addConsumer(new DrawerConsumer())
    .enableLeft()
    .setScrimColor(0x7F000000)
    .setDrawerOpenRatio(0.8f);

Getting Started

To use SmartSwipe in your Android project, follow these steps:

  1. Add the JitPack repository to your project's build.gradle file:
allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}
  1. Add the SmartSwipe dependency to your app's build.gradle file:
dependencies {
    implementation 'com.github.luckybilly:SmartSwipe:1.1.2'
}
  1. Sync your project with Gradle files.

  2. Start using SmartSwipe in your activities or fragments:

import com.billy.android.swipe.SmartSwipe;

public class MainActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        SmartSwipe.wrap(this)
            .addConsumer(new ActivitySlidingBackConsumer(this))
            .enableLeft();
    }
}

Competitor Comparisons

10,798

Project vlayout is a powerfull LayoutManager extension for RecyclerView, it provides a group of layouts for RecyclerView. Make it able to handle a complicate situation when grid, list and other layouts in the same recyclerview.

Pros of vlayout

  • Focuses on efficient and flexible layouts for complex UIs
  • Supports a wide range of layout types (LinearLayout, GridLayout, etc.)
  • Optimized for performance with large lists and complex views

Cons of vlayout

  • Steeper learning curve due to its complexity
  • May be overkill for simpler UI layouts
  • Less active development and updates compared to SmartSwipe

Code Comparison

SmartSwipe (Gesture handling):

SmartSwipe.wrap(view)
    .addConsumer(new SpaceConsumer())
    .enableHorizontal()
    .setScaleMode(ScaleMode.SCALE_FADE);

vlayout (Layout creation):

RecyclerView.RecycledViewPool viewPool = new RecyclerView.RecycledViewPool();
VirtualLayoutManager layoutManager = new VirtualLayoutManager(this);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setRecycledViewPool(viewPool);

Key Differences

  • SmartSwipe focuses on gesture handling and swipe interactions
  • vlayout specializes in complex layout management for RecyclerViews
  • SmartSwipe is more suitable for adding swipe gestures to existing views
  • vlayout is better for creating highly customized and efficient list layouts

Use Cases

SmartSwipe:

  • Adding swipe-to-delete functionality
  • Creating custom gesture-based interactions

vlayout:

  • Building complex e-commerce product lists
  • Implementing heterogeneous layouts in a single RecyclerView
7,700

A declarative framework for building efficient UIs on Android.

Pros of Litho

  • Declarative UI framework for building efficient UIs at scale
  • Optimized for performance with automatic layout calculations and incremental mount
  • Extensive documentation and support from Facebook's engineering team

Cons of Litho

  • Steeper learning curve due to its unique component-based architecture
  • Limited flexibility compared to traditional Android UI development
  • Requires additional build setup and dependencies

Code Comparison

SmartSwipe (Java):

SmartSwipe.wrap(view)
    .addConsumer(new SpaceConsumer())
        .setHorizontalPercent(0.2f)
        .setVerticalPercent(0.2f)
    .addConsumer(new TranslateConsumer())
        .setXMoveRatio(0.5f)
        .setYMoveRatio(0.5f);

Litho (Java):

@OnCreateLayout
static Component onCreateLayout(ComponentContext c) {
  return Row.create(c)
      .child(Text.create(c).text("Hello").textSizeDip(40))
      .child(Text.create(c).text("World").textSizeDip(40))
      .build();
}

SmartSwipe focuses on gesture-based interactions and swipe behaviors, while Litho is a comprehensive UI framework for building complex, high-performance layouts. SmartSwipe offers a more straightforward API for adding swipe functionality to existing views, whereas Litho requires a different approach to UI development with its component-based system.

8,512

Epoxy is an Android library for building complex screens in a RecyclerView

Pros of Epoxy

  • More comprehensive UI building framework for Android
  • Better suited for complex, dynamic layouts
  • Stronger community support and regular updates

Cons of Epoxy

  • Steeper learning curve
  • Potentially overkill for simpler UI requirements
  • More complex setup and integration process

Code Comparison

SmartSwipe (Gesture handling):

SmartSwipe.wrap(view)
    .addConsumer(new SpaceConsumer())
        .setHorizontalPercent(0.2f)
        .setVerticalPercent(0.2f)
    .addConsumer(new TranslateConsumer())
        .setXMoveRatio(0.5f)
        .setYMoveRatio(0.5f);

Epoxy (Building dynamic UI):

class CarouselEpoxyModel : EpoxyModelGroup {
    override fun buildModels() {
        carousel {
            id("carousel")
            numViewsToShowOnScreen(2.5f)
            models(itemModels)
        }
    }
}

SmartSwipe focuses on gesture handling and swipe actions, while Epoxy provides a more comprehensive solution for building complex, dynamic UIs. SmartSwipe is easier to implement for specific swipe functionalities, whereas Epoxy offers greater flexibility and power for overall UI construction, particularly in list-based interfaces.

Flexible multiple types for Android RecyclerView.

Pros of MultiType

  • Focuses on efficient RecyclerView adapters for multiple view types
  • Simpler API for handling diverse data types in lists
  • Better suited for complex, heterogeneous list layouts

Cons of MultiType

  • Limited to RecyclerView implementations
  • Lacks gesture and swipe functionality
  • May require more setup for simple list scenarios

Code Comparison

MultiType:

class ImageViewBinder : ItemViewBinder<Image, ImageViewBinder.Holder>() {
  override fun onCreateViewHolder(inflater: LayoutInflater, parent: ViewGroup): Holder {
    return Holder(inflater.inflate(R.layout.item_image, parent, false))
  }
  override fun onBindViewHolder(holder: Holder, item: Image) {
    holder.imageView.setImageURI(item.uri)
  }
  class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
    val imageView: ImageView = itemView.findViewById(R.id.image)
  }
}

SmartSwipe:

SmartSwipe.wrap(view)
    .addConsumer(new SpaceConsumer())
    .enableHorizontal()
    .setScaleMode(SpaceConsumer.SCALE_MODE_STRETCH)
    .setRelativeMoveFactor(0.5f);

While MultiType focuses on simplifying RecyclerView adapters for multiple view types, SmartSwipe provides a broader range of swipe and gesture functionalities for various UI elements. MultiType is more specialized for complex list layouts, while SmartSwipe offers more general-purpose touch interaction capabilities.

Flexbox for Android

Pros of flexbox-layout

  • Implements the CSS Flexbox Layout mechanism for Android, providing a powerful and flexible layout system
  • Officially supported by Google, ensuring long-term maintenance and compatibility
  • Extensive documentation and examples available, making it easier for developers to adopt and use

Cons of flexbox-layout

  • Limited to layout functionality, not providing additional UI interaction features
  • May require more setup and configuration compared to simpler layout options
  • Learning curve for developers unfamiliar with CSS Flexbox concepts

Code Comparison

SmartSwipe (gesture handling):

SmartSwipe.wrap(view)
    .addConsumer(new SpaceConsumer())
    .enableHorizontal()
    .setScaleMode(SCALE_MODE_STRETCH);

flexbox-layout (layout configuration):

<com.google.android.flexbox.FlexboxLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:flexDirection="row"
    app:flexWrap="wrap">
    <!-- Child views -->
</com.google.android.flexbox.FlexboxLayout>

While SmartSwipe focuses on gesture handling and UI interactions, flexbox-layout provides a robust layout system based on CSS Flexbox principles. SmartSwipe offers more specialized functionality for swipe gestures, while flexbox-layout excels in creating flexible and responsive layouts for Android applications.

A SnapHelper that snaps a RecyclerView to an edge.

Pros of GravitySnapHelper

  • Focuses specifically on snapping behavior for RecyclerView, providing a more specialized solution
  • Simpler implementation for basic snapping functionality
  • Lightweight library with minimal overhead

Cons of GravitySnapHelper

  • Limited to RecyclerView snapping, lacking the broader gesture support of SmartSwipe
  • Less customizable for complex swiping scenarios
  • May require additional code for advanced use cases

Code Comparison

GravitySnapHelper:

RecyclerView recyclerView = findViewById(R.id.recyclerView);
GravitySnapHelper snapHelper = new GravitySnapHelper(Gravity.START);
snapHelper.attachToRecyclerView(recyclerView);

SmartSwipe:

SmartSwipe.wrap(view)
    .addConsumer(new SpaceConsumer())
    .enableHorizontal()
    .setScaleMode(ScaleMode.SCALE_FACTOR)
    .setScaleFactor(0.8f);

Summary

GravitySnapHelper is a focused solution for RecyclerView snapping, offering simplicity and ease of use for basic scenarios. SmartSwipe, on the other hand, provides a more comprehensive gesture handling system with greater flexibility and customization options. The choice between the two depends on the specific requirements of the project, with GravitySnapHelper being suitable for simple snapping needs and SmartSwipe offering more advanced gesture support.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

SmartSwipe

librarysmart-swipesmart-swipe-supportsmart-swipe-x
latest versionDownloadDownloadDownload

中文文档,更详尽

A smart swipe android library helps you make View (and Activity) swipes easier.

In addition, to facilitate the use, SmartSwipe encapsulates the following tool classes:

  • SmartSwipeBack:
    All Activities slide back in an easy way via a single line code.
    without any super activity class; without translucent theme; without any code into BaseActivity; without any code into xml layout files;
  • SmartSwipeRefresh:
    With a single line code to achieve swipe refresh and load more. Compatible with vertical and horizontal
  • SwipeConsumerExclusiveGroup:
    Manages a set of exclusive SwipeConsumers, can only open one at a time.

Demo

download demo.apk

Stretch
StretchConsumer
Space
SpaceConsumer
Translucent Sliding
TranslucentSlidingConsumer
Drawer above
DrawerConsumer
Drawer behind
(factor is settable)
SlidingConsumer
Doors Open
DoorConsumer
Shutters Open
ShuttersConsumer

Create a cover

Doors openShutters OpenDrawer Open

Activity sliding back

All Activities slide back in an easy way via a single line code.

  • without any super activity class;
  • without translucent theme;
  • without any code into BaseActivity;
  • without any code into xml layout files;
Back via release velocity
StayConsumer
Translucent Sliding Back
ActivitySlidingBackConsumer
Back with bezier
BezierBackConsumer
Like doors open
ActivityDoorBackConsumer
Like shutters open
ActivityShuttersBackConsumer
Global Usage
SmartSwipeBack

Usage

First add SmartSwipe to your project

implementation 'com.billy.android:smart-swipe:latestVersion'

Nested scrolling only compatible after android api above 21(android 5.0) with core library(smart-swipe)

Add extension library to compat for android support library or androidX like below:

implementation 'com.billy.android:smart-swipe:latestVersion'
//compat for android support library
implementation 'com.billy.android:smart-swipe-support:latestVersion'

or

implementation 'com.billy.android:smart-swipe:latestVersion'
//compat for android x
implementation 'com.billy.android:smart-swipe-x:latestVersion'

SmartSwipe can be used by chain programming within a single line code. The usage of API looks like follow:

SmartSwipe.wrap(...) 		//view or Activity
	.addConsumer(...) 		//add a SwipeConsumer
	.enableDirection(...) 	//Specifies which side of the slide the SwipeConsumer will consumes
	.setXxx(...) 			//[optional] some other Settings
	.addListener(...); 		//[optional] add listener(s) to the SwipeConsumer

Sample code:

//	When view cannot scroll vertically (or scrolling to the top/bottom), 
//	if continue to drag, the UI will show elastic stretching effect, 
//	and smooth recovery after release
SmartSwipe.wrap(view)
	.addConsumer(new StretchConsumer())
	.enableVertical();

Add more than one 'SwipeConsumer' to the same View. Such as:

SmartSwipe.wrap(view)
	.addConsumer(new StretchConsumer())
	.enableVertical() 					//Stretch effect at directions: top and bottom
	.addConsumer(new SpaceConsumer())
	.enableHorizontal() 				//Space effect at directions: left and right
	;

Click here for more details about SwipeConsumers

Activity slides back with a single line of code globally

SmartSwipeBack.activityBezierBack(application, null);	//bezier shows while swiping
SmartSwipeBack.activityStayBack(application, null);		//Back via release velocity
SmartSwipeBack.activitySlidingBack(application, null);	//sliding with pre-activity relative moves
SmartSwipeBack.activityDoorBack(application, null);		//finish activity like doors open
SmartSwipeBack.activityShuttersBack(application, null);	//finish activity like shutters open

Click here For more Details

Add swipe refresh to a View via a single line code

//the second parameter within xxxMode:
// false: works vertically(swipe down to refresh and swipe up to load more)
// true: works horizontally(swipe right to refresh and swipe right to load more) 
SmartSwipeRefresh.drawerMode(view, false).setDataLoader(loader);
SmartSwipeRefresh.behindMode(view, false).setDataLoader(loader);
SmartSwipeRefresh.scaleMode(view, false).setDataLoader(loader);
SmartSwipeRefresh.translateMode(view, false).setDataLoader(loader);

You can use default headers and footers, and you can also customize your own.

The refresh extension library(smart-swipe-refresh-ext: Download) will include some fancy third-party headers and footers.

here is the first one(Based on Ifxcyr/ArrowDrawable):

refresh arrow

Click here For more Details

SmartSwipe features:

  • support for 4 directions swipe( left/top/right/bottom)
  • supports adding multiple SwipeConsumers to the same View(/Activity)
  • supports nested usage
  • support to use for list items in ListView and RecyclerView and the list itself
  • compat for NestedScroll (android support library and androidX)
  • A dozen of built-in SwipeConsumers effects

Thanks