React Native Swipe Button Component


npm install rn-swipe-button --save

import SwipeButton from 'rn-swipe-button';

<SwipeButton />

NPM Package

https://www.npmjs.com/package/rn-swipe-button

Screenshots

Android

iOS

iOS gif

Android RTL



Component properties

    containerStyles: PropTypes.object,

    disabled: PropTypes.bool,

    disableResetOnTap: PropTypes.bool, // After swipe success, tapping on the button resets it. Set this prop to true to disable this behavior.

    disabledRailBackgroundColor: PropTypes.string,

    disabledThumbIconBackgroundColor: PropTypes.string,

    disabledThumbIconBorderColor: PropTypes.string,

    enableReverseSwipe: PropTypes.bool,

    forceReset: PropTypes.func, // RNSwipeButton will call this function by passing a "reset" function as argument. Calling "reset" will reset the swipe thumb.
    
    height: PropTypes.number,

    onSwipeFail: PropTypes.func,

    onSwipeStart: PropTypes.func,

    onSwipeSuccess: PropTypes.func,

    railBackgroundColor: PropTypes.string,

    railBorderColor: PropTypes.string,

    railFillBackgroundColor: PropTypes.string,

    railFillBorderColor: PropTypes.string,

    railStyles: PropTypes.object,

    resetAfterSuccessAnimDelay: PropTypes.number,  This is delay before resetting the button after successful swipe When shouldResetAfterSuccess = true
    
    resetAfterSuccessAnimDuration: PropTypes.number,
    
    screenReaderEnabled: PropTypes.bool,
    
    shouldResetAfterSuccess: PropTypes.bool, // If set to true, buttun resets automatically after swipe success with default delay of 1000ms

    swipeSuccessThreshold: PropTypes.number, // Ex: 70. Swipping 70% will be considered as successful swipe

    thumbIconBackgroundColor: PropTypes.string,

    thumbIconBorderColor: PropTypes.string,

    thumbIconComponent: PropTypes.node, Pass any react component to replace swipable thumb icon

    thumbIconImageSource: PropTypes.oneOfType([
      PropTypes.string,
      PropTypes.number,
    ]),

    thumbIconStyles: PropTypes.object,

    thumbIconWidth: PropTypes.number,

    title: PropTypes.string,

    titleColor: PropTypes.string,

    titleFontSize: PropTypes.number,

    titleMaxFontScale: PropTypes.number, // Ex: 2. will limit font size increasing to 200% when user increases font size in device properties
    
    titleMaxLines: PropTypes.number, // Use other title related props for additional UI customization

    titleStyles: PropTypes.object,

    width: PropTypes.number,

    

Note:


Running example app

  1. git close https://github.com/UdaySravanK/RNSwipeButton.git
  2. cd RNSwipeButton/examples/RNSwipeButtonDemo
  3. yarn
  4. To run on an android emulator

    yarn android
    Make sure of
    • Android Studio is configured
    • Global paths set correctly for Android SDK i.e ANDROID_HOME, tools, platform-tools
    • Java8 is installed
    • At least one emulator is ready
  5. To run on an ios simulator

    yarn ios
    Make sure of
    • xcode is configured
    • cocoapods installed
    • If seeing issues then run pod deintegrate & pod install
    • If seeing issues with fonts
      1. Open ios workspace project in xcode
      2. Select RNSwipeButtonDemo
      3. Go to Build phases
      4. Open 'Copy Bundle Resources' and delete all .ttf files

Making changes and seeing them in the demo app

Mapping the local npm package using `npm link` is not working for me but you can give a try and update this readme to help others.

As a workaroud, simply copy the `src` folder from the `RNSwipeButton` and paste it in `RNSwipeButtonDemo` app. In the demo app, you see `App.tsx`. When you open it, you will see a commented import and a note. Simply use the copied source code. I understand it is not the ideal way to work but this is a simple component and won't take more than 10seconds to do this.