react native swipe/slide button component forked from rn-swipe-button
npm install jt-swipe-button
npm install rn-swipe-button --save
import SwipeButton from 'rn-swipe-button';
| iOS | Android | iOS GIF | Android RTL |
![]() | ![]() | ![]() | ![]() |
These screenshots are from demo app under examples folder in the repo
containerStyles: PropTypes.object,
containerPadding: PropTypes.number,
disable: PropTypes.bool,
disableResetOnTap: PropTypes.bool,
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.oneOfType([
PropTypes.string,
PropTypes.number,
]),
onSwipeFail: PropTypes.func,
onSwipeStart: PropTypes.func,
onSwipeSuccess: PropTypes.func,
railBackgroundColor: PropTypes.string,
railBorderColor: PropTypes.string,
railBorderWidth: PropTypes.number,
railFillBackgroundColor: PropTypes.string,
railFillBorderColor: PropTypes.string,
railFillBorderWidth: PropTypes.number,
railStyles: PropTypes.object,
resetAfterSuccessAnimDelay: PropTypes.number, // This is delay before resetting the button after successful swipe When shouldResetAfterSuccess = true
resetAfterSuccessAnimDuration: PropTypes.number,
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,
thumbIconBorderWidth: PropTypes.number,
thumbIconComponent: PropTypes.oneOfType([
PropTypes.element,
PropTypes.node,
PropTypes.func,
]), Pass any react component to replace swipable thumb icon
thumbIconImageSource: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
thumbIconStyles: PropTypes.object,
thumbIconWidth: PropTypes.number,
title: PropTypes.oneOfType([
PropTypes.node,
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
titleStyles: PropTypes.object,
titleMargin: PropTypes.number,
RightEndTemplate: PropTypes.node,
LeftEndTemplate: PropTypes.node,
width: PropTypes.oneOfType([
PropTypes.string,
PropTypes.number,
]),
``
import React, {useState} from 'react';
import {SafeAreaView, View, Text, StatusBar, Button} from 'react-native';
import Icon from 'react-native-vector-icons/FontAwesome';
import thumbIcon from './assets/thumbIcon.png';
import arrowRight from './assets/arrow-right.png';
import styles from './styles';
import SwipeButton from 'rn-swipe-button';
const App: () => React$Node = () => {
const [disableCBButton, setDisableCBButton] = useState(false)
const defaultStatusMessage = 'swipe status appears here';
const [swipeStatusMessage, setSwipeStatusMessage] = useState(
defaultStatusMessage,
);
setInterval(() => setSwipeStatusMessage(defaultStatusMessage), 5000);
const updateSwipeStatusMessage = (message) => setSwipeStatusMessage(message);
const renderSubHeading = (heading) => (
);
let forceResetLastButton = null;
const CheckoutButton = () => {
return(
);
}
return (
<>
{renderSubHeading('Disabled')}
{renderSubHeading('Swipe status callbacks')}
height={30}
onSwipeFail={() => updateSwipeStatusMessage('Incomplete swipe!')}
onSwipeStart={() => updateSwipeStatusMessage('Swipe started!')}
onSwipeSuccess={() =>
updateSwipeStatusMessage('Submitted successfully!')
}
railBackgroundColor="#31a57c"
railStyles={{borderRadius: 5}}
thumbIconComponent={CheckoutButton}
thumbIconImageSource={arrowRight}
thumbIconStyles={{borderRadius: 5}}
thumbIconWidth={100}
title="Submit order"
/>
{renderSubHeading('Reverse swipe enabled')}
onSwipeSuccess={() => updateSwipeStatusMessage('Slide success!')}
railBackgroundColor="#a493d6"
thumbIconBackgroundColor="#FFFFFF"
title="Slide to unlock"
/>
{renderSubHeading('Set a component as thumb icon & use forceReset')}
forceReset={ reset => {
forceResetLastButton = reset
}}
railBackgroundColor="#9fc7e8"
railStyles={{
backgroundColor: '#44000088',
borderColor: '#880000FF',
}}
thumbIconBackgroundColor="#FFFFFF"
title="Slide to unlock"
/>
{renderSubHeading('Set .png image as thumb icon')}
{renderSubHeading('Set height & reset after successful swipe')}
{renderSubHeading('Set height and width')}
>
);
};
``
git clone https://github.com/UdaySravanK/RNSwipeButton.gitcd RNSwipeButton/examples/RNSwipeButtonDemoyarnTo run on an android emulator
yarn android To run on an ios simulator
yarn ios pod deintegrate & pod install