SmartSwipe
An android library to make swipe more easier and more powerful. Android各种侧滑,有这一个就够了
Top Related Projects
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.
A declarative framework for building efficient UIs on Android.
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
- Basic swipe-to-finish activity:
SmartSwipe.wrap(this)
.addConsumer(new ActivitySlidingBackConsumer(this))
.enableLeft();
- Adding swipe-to-refresh functionality:
SmartSwipeRefresh.createClassicRefresh(recyclerView)
.setOnRefreshListener(new SmartSwipeRefresh.OnRefreshListener() {
@Override
public void onRefresh() {
// Perform refresh action
}
});
- 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:
- Add the JitPack repository to your project's build.gradle file:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add the SmartSwipe dependency to your app's build.gradle file:
dependencies {
implementation 'com.github.luckybilly:SmartSwipe:1.1.2'
}
-
Sync your project with Gradle files.
-
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
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
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.
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 designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
SmartSwipe
library | smart-swipe | smart-swipe-support | smart-swipe-x |
---|---|---|---|
latest version |
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 exclusiveSwipeConsumer
s, can only open one at a time.
Demo
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 open | Shutters Open | Drawer 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
: ) will include some fancy third-party headers and footers.
here is the first one(Based on Ifxcyr/ArrowDrawable):
Click here For more Details
SmartSwipe
featuresï¼
- support for 4 directions swipe( left/top/right/bottom)
- supports adding multiple
SwipeConsumer
s 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
SwipeConsumer
s effects
Thanks
Top Related Projects
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.
A declarative framework for building efficient UIs on Android.
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.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot