New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

rn-swipe-button

Package Overview
Dependencies
Maintainers
1
Versions
37
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rn-swipe-button

react native swipe/slide button component

  • 2.0.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7.4K
increased by4.41%
Maintainers
1
Weekly downloads
 
Created
Source

React Native Swipe Button Component

star this repo fork this repo NPM Version npm total downloads Npm Downloads Socke Score Contribuutions Welcome


Installation

npm install rn-swipe-button --save

# OR

yarn add rn-swipe-button

react-native compatibility

rn-swipe-buttonreact-nativereact
<= v1.3.8>= 0.60.5>= 16.8.6
>= v2.0.0>= 0.70.0>= 18.1.0

Usage

import SwipeButton from 'rn-swipe-button'; 

<SwipeButton />


Screenshots

iOSAndroidiOS GIFAndroid RTL

These screenshots are from the demo app.


Component properties

    containerStyles: PropTypes.object,
    disabled: PropTypes.bool,
    disableResetOnTap: PropTypes.bool,
    disabledRailBackgroundColor: PropTypes.string,
    disabledThumbIconBackgroundColor: PropTypes.string,
    disabledThumbIconBorderColor: PropTypes.string,
    enableReverseSwipe: PropTypes.bool,
    finishRemainingSwipeAnimationDuration: PropTypes.number,
    forceCompleteSwipe: PropTypes.func, // RNSwipeButton will call this function by passing a  function as an argument. Calling the returned function will force complete the swipe.
    forceReset: PropTypes.func,  // RNSwipeButton will call this function by passing a "reset" function as an argument. Calling "reset" will reset the swipe thumb.
    height: PropTypes.oneOfType([
       PropTypes.string,
       PropTypes.number,
    ]),
    onSwipeFail: PropTypes.func,
    onSwipeStart: PropTypes.func,
    onSwipeSuccess: PropTypes.func, // Returns a boolean to indicate the swipe completed with real gesture or forceCompleteSwipe was called
    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 
    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.oneOfType([
      PropTypes.string,
      PropTypes.number,
    ]),

You can also check type definitions in types.d.ts file.


Example

import React, { useState } from 'react';
import { View, Text } from 'react-native';

import SwipeButton from 'rn-swipe-button';


function Example() {
  let forceResetLastButton: any = null;
  let forceCompleteCallback: any = null;
  const [finishSwipeAnimDuration, setFinishSwipeAnimDuration] = useState(400)
  
  const forceCompleteButtonCallback = useCallback(() => {
    setFinishSwipeAnimDuration(0)
    forceCompleteCallback()
  }, [])

  const forceResetButtonCallback = useCallback(() => {
    forceResetLastButton()
    setInterval(() => setFinishSwipeAnimDuration(400) , 1000)
  }, [])
  
  return (
    <View>
      <SwipeButton
        disableResetOnTap
        forceReset={ (reset: any) => {
          forceResetLastButton = reset
        }}
        finishRemainingSwipeAnimationDuration={finishSwipeAnimDuration}
        forceCompleteSwipe={ (forceComplete: any) => {
          forceCompleteCallback = forceComplete
        }}
        railBackgroundColor="#9fc7e8"
        railStyles={{
          backgroundColor: '#147cbb',
          borderColor: '#880000FF',
        }}
        thumbIconBackgroundColor="#FFFFFF"
        thumbIconImageSource={require('@/assets/images/react-logo.png')}
        title="Slide to unlock"
      />
      <View style={{ marginBottom: 5, flexDirection: 'row', justifyContent: 'center' }}>
        <Text onPress={forceCompleteButtonCallback}>Force Complete</Text>
        <Text onPress={forceResetButtonCallback}>Force Reset</Text>
      </View>
    </View>
  )
};

Please check the demo app for more examples.


Note

  • In accessibility mode this component works like a regular button (double tap to activate)
  • We are supporting RTL out of the box. For RTL layouts, swipe button works by default as right to left swipe.

Tech Stack

  • Node
  • Yarn/NPM
  • JavaScript
  • TypeScript
  • ReactNative

Running the demo app

  1. git clone https://github.com/UdaySravanK/RNSwipeButtonDemo.git
  2. cd 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.

Workaroud is simply copy the `src` folder from the `RNSwipeButton` and paste it in `RNSwipeButtonDemo` app "app\(tabs)" folder. In the demo app, you see `index.tsx` with HomeScreen. 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.


Contributing

I request more developers from the open-source community to contributing to improve this project. You can find the work by visiting the project associated with this repository. You can find issues related to defects, new feature requests and dev only related tasks like writing unit tests.

Keywords

FAQs

Package last updated on 23 Jan 2025

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