Socket
Socket
Sign inDemoInstall

react-native-swipeable

Package Overview
Dependencies
487
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-native-swipeable

A powerful React Native swipe component


Version published
Weekly downloads
4.3K
increased by2.92%
Maintainers
1
Install size
285 kB
Created
Weekly downloads
 

Readme

Source

React Native Swipeable NPM version

A powerful React Native swipe component. Supports both iOS and Android.

Installation

npm i --save react-native-swipeable

Usage

Wrap your ListView/TableView items with the Swipeable component:

import Swipeable from 'react-native-swipeable';

const leftContent = <Text>Pull to activate</Text>;

const rightButtons = [
  <TouchableHighlight><Text>Button 1</Text></TouchableHighlight>,
  <TouchableHighlight><Text>Button 2</Text></TouchableHighlight>
];

function MyListItem() {
  return (
    <Swipeable leftContent={leftContent} rightButtons={rightButtons}>
      <Text>My swipeable content</Text>
    </Swipeable>
  );
}

Props

proptypedefaultdescription
childrenrenderablenullswipeable content
leftContentrenderablenull(optional) left content visible during pull action
rightContentrenderablenull(optional) right content visible during pull action
leftButtonsrenderable[]null(optional) array of buttons, first being the innermost; ignored if leftContent present
rightButtonsrenderable[]null(optional) array of buttons, first being the innermost; ignored if rightContent present
leftActionActivationDistanceinteger125(optional) minimum swipe distance to activate left action
onLeftActionReleasefunctionnull(optional) user has swiped beyond leftActionActivationDistance and released
rightActionActivationDistanceinteger125(optional) minimum swipe distance to activate right action
onRightActionReleasefunctionnull(optional) user has swiped beyond rightActionActivationDistance and released
leftButtonWidthinteger75(optional) resting visible peek of each left button after buttons are swiped open
rightButtonWidthinteger75(optional) resting visible peek of each right button after buttons are swiped open
onReffunctionnull(optional) receive swipeable component instance reference
onPanAnimatedValueReffunctionnull(optional) receive swipeable pan Animated.ValueXY reference for upstream animations

Advanced Props

Check out the Swipeable component's propTypes for a huge list of options including animation lifecycle hooks and low-level overrides.

Instance Methods

recenter()

Imperatively reset swipeable component back to initial position. This is useful if buttons are exposed and the user has begun scrolling the parent view.

class MyListItem extends Component {

  swipeable = null;

  handleUserBeganScrollingParentView() {
    this.swipeable.recenter();
  }

  render() {
    return (
      <Swipeable onRef={ref => this.swipeable = ref} rightButtons={rightButtons}>
        <Text>My swipeable content</Text>
      </Swipeable>
    );
  }
}

Example

To run the example:

npm run build
cd example
npm install
react-native run-ios # or run-android

Common Issues

Action being triggered more than once (#3)

This seems to occur occasionally (but not always) with certain ScrollView and ListView configurations. The fix is simple though, just ensure that scrollEnabled is set to false while the user is swiping a row.

<ScrollView scrollEnabled={!this.state.isSwiping}>
  <Swipeable
    onSwipeStart={() => this.setState({isSwiping: true})}
    onSwipeRelease={() => this.setState({isSwiping: false})}
  </Swipeable>
</ScrollView>

or:

<ListView
  scrollEnabled={!this.state.isSwiping}
  renderRow={() => (
    <Swipeable
      onSwipeStart={() => this.setState({isSwiping: true})}
      onSwipeRelease={() => this.setState({isSwiping: false})}
    </Swipeable>
  )}
/>

License

MIT

Keywords

FAQs

Last updated on 10 Jul 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc