0.3.0 • Published 7 years ago

rn-swipe-out v0.3.0

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

React Native Swipeout

The iOS-style Swipeout component, implement with javascript, running on iOS and Android. High performance, interactive, and configurable.

Installation

npm install rn-swipe-out --save

Usage

import React from 'react';

import {
    Text,
    StyleSheet
} from 'react-native';

import Swipeout from 'rn-swipe-out';

export default class SwipeoutDemo extends React.Component {
    option = {
        text: 'Cancel',
        style: {
            backgroundColor: '#ccc'
        }
    };
    render() {
        return (
            <Swipeout style={styles.swipe} right={this.option}>
                <Text>Swipe out from right to left</Text>
            </Swipeout>
        );
    }
}

const styles = StyleSheet.create({
    swipe: {
        height: 44
    }
});

Props

PropDefaultTypeDescription
style{}View.propTypes.styleStyling Swipeout, you can treat it as a View.
left[]Object/ArrayThe configuration on the left, more info.
right[]Object/ArrayThe configuration on the right, more info.
onPressemptyFnFunctionCalled when the touch is released, but not if cancelled (e.g. by a scroll that steals the responder lock).
onPressInemptyFnFunctionCalled when the touch is started.
onPressOutemptyFnFunctionCalled when the touch is released.
onLongPressemptyFnFunctionCalled when the touch is continued more than 500ms.
onOpenemptyFnFunctionCalled when the option is swipe out.
onCloseemptyFnFunctionCalled when the option is close.
underlayColor''StringThe color of the underlay that will show through when the touch is active.
activeOpacity1NumberDetermines what the opacity of the wrapped view should be when touch is active.
optionWidth64NumberThe single option's width, decided the swipe out options size.
snapVelocity0.3NumberThe minimum guesture velocity to perform animation.
actionThreshold0.5NumberThe minimum distance to swipe out option. If value <= 1, distance = actionThreshold optionWidth options.length, if value > 1, distance = actionThreshold
useNativeDrivertrueBooleanIn react-native 0.40+, Swipeout setting its true to improve performance, and you can set false to prevent it. That's ok if you set it false, because even without this addition, Swipeout can also get a high performance.

The configuration for the left and right

  • text (String/Number) Option's text
  • style _(Text.propTypes.style) Option's style
  • onPress (Function) Called when the touch is released, but not if cancelled (e.g. by a scroll that steals the responder lock).
  • onPressIn (Function) Called when the touch is started.
  • onPressOut (Function) Called when the touch is released.
  • underlayColor (String) The color of the underlay that will show through when the touch is active.
  • activeOpacity (Number) Determines what the opacity of the wrapped view should be when touch is active.
  • onLongPress (Function) Called when the touch is continued more than 500ms.
  • component (Function) If the default option unable to meet your demand, you can set a custom component for Swipeout. Be careful once set a custom component, the option's click event will not close itself (Gesture to close can always work). So you have to hide it to execute a hide function. Swipeout seen component as a React Stateless Component and passing two useful props, which inner the source is <option.component hide={this.hide} animatedValue={this.panAnim} />. In your component you can use this.props.hide() to close option. animatedValue is a Animated.Value instance which hold the Swipeout animation value, you can use to get some interactive animation. see the example to get more info.

Example

Basic Use

Complete Example


MIT Licensed