Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ The code is based on the experimental SwipeableListView of react-native.
npm install --save react-native-swipeable-view
```

If using React Native < 0.54, you must stay at <= 1.0.0.

## Usage example

```
Expand All @@ -36,7 +38,7 @@ var btnsArray = [

Prop | Type | Optional | Default | Description
------------------- | ------ | -------- | --------- | -----------
isOpen         | bool   | Yes | false | Swipeout is open or not
isOpen         | bool   | Yes | false | Swipeout is open or not. CHanging this value will animate the Swipeout open or closed.
autoClose       | bool   | Yes     | false   | Auto-Close on button press
btnsArray | array | No | [] | Swipe buttons array
onOpen | func | Yes | | Callback when swipe is opened
Expand Down
43 changes: 21 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,14 @@ class SwipeableView extends Component {
};

this._swipeoutRef = null;
}

componentWillMount() {
this._panResponder = PanResponder.create({
onMoveShouldSetPanResponderCapture: this._handleMoveShouldSetPanResponderCapture.bind(this),
onPanResponderGrant: this._handlePanResponderGrant.bind(this),
onPanResponderMove: this._handlePanResponderMove.bind(this),
onPanResponderRelease: this._handlePanResponderEnd.bind(this),
onPanResponderTerminationRequest: this._onPanResponderTerminationRequest.bind(this),
onPanResponderTerminate: this._handlePanResponderEnd.bind(this),
onMoveShouldSetPanResponderCapture: this._handleMoveShouldSetPanResponderCapture,
onPanResponderGrant: this._handlePanResponderGrant,
onPanResponderMove: this._handlePanResponderMove,
onPanResponderRelease: this._handlePanResponderEnd,
onPanResponderTerminationRequest: this._onPanResponderTerminationRequest,
onPanResponderTerminate: this._handlePanResponderEnd,
onShouldBlockNativeResponder: () => false,
});
}
Expand All @@ -151,8 +149,6 @@ class SwipeableView extends Component {
this._animateBounceBack(ON_MOUNT_BOUNCE_DURATION);
}, ON_MOUNT_BOUNCE_DELAY);
}

setTimeout(this._measureSwipeout.bind(this));
}

componentWillUnmount() {
Expand All @@ -161,14 +157,16 @@ class SwipeableView extends Component {
}
}

componentWillReceiveProps(nextProps) {
componentDidUpdate(prevProps) {
const { isOpen } = this.props;
/**
* We do not need an "animateOpen(noCallback)" because this animation is
* handled internally by this component.
*/
if (isOpen && !nextProps.isOpen) {
if (prevProps.isOpen && !isOpen) {
this._animateToClosedPosition();
} else if (!prevProps.isOpen && isOpen) {
this._animateToOpenPosition();
}
}

Expand All @@ -183,7 +181,7 @@ class SwipeableView extends Component {
return true;
}

_onPanResponderTerminationRequest() {
_onPanResponderTerminationRequest = () => {
return false;
}

Expand All @@ -204,7 +202,7 @@ class SwipeableView extends Component {
this._animateTo(CLOSED_LEFT_POSITION, duration);
}

_animateToClosedPositionDuringBounce() {
_animateToClosedPositionDuringBounce = () => {
this._animateToClosedPosition(RIGHT_SWIPE_BOUNCE_BACK_DURATION);
}

Expand Down Expand Up @@ -246,7 +244,7 @@ class SwipeableView extends Component {
this._animateTo(
-swipeBounceBackDistance,
duration,
this._animateToClosedPositionDuringBounce.bind(this),
this._animateToClosedPositionDuringBounce,
);
}

Expand All @@ -261,7 +259,7 @@ class SwipeableView extends Component {
);
}

_handlePanResponderEnd(event, gestureState) {
_handlePanResponderEnd = (event, gestureState) => {
const { onOpen, onClose, onSwipeEnd, isRTL } = this.props;
const horizontalDistance = isRTL ? -gestureState.dx : gestureState.dx;

Expand Down Expand Up @@ -319,7 +317,7 @@ class SwipeableView extends Component {
);
}

_handlePanResponderMove(event, gestureState) {
_handlePanResponderMove = (event, gestureState) => {
const { onSwipeStart } = this.props;

if (this._isSwipingExcessivelyRightFromClosedPosition(gestureState)) {
Expand All @@ -335,10 +333,10 @@ class SwipeableView extends Component {
}
}

_handlePanResponderGrant() {
_handlePanResponderGrant = () => {
}

_handleMoveShouldSetPanResponderCapture(event, gestureState) {
_handleMoveShouldSetPanResponderCapture = (event, gestureState) => {
// Decides whether a swipe is responded to by this component or its child
return gestureState.dy < 10 && this._isValidSwipe(gestureState);
}
Expand Down Expand Up @@ -392,7 +390,7 @@ class SwipeableView extends Component {
}
}

_measureSwipeout() {
_measureSwipeout = () => {
if (this._swipeoutRef) {
this._swipeoutRef.measure((a, b, width, height) => {
const { btnsArray } = this.props;
Expand All @@ -417,7 +415,7 @@ class SwipeableView extends Component {
};
}

_onSwipeableViewLayout(event) {
_onSwipeableViewLayout = (event) => {
this.setState({
isSwipeableViewRendered: true,
rowHeight: event.nativeEvent.layout.height,
Expand Down Expand Up @@ -464,7 +462,7 @@ class SwipeableView extends Component {
// The swipeable item
const swipeableView = (
<Animated.View
onLayout={this._onSwipeableViewLayout.bind(this)}
onLayout={this._onSwipeableViewLayout}
style={{transform: [{translateX: this.state.currentLeft}], backgroundColor: 'white'}}>
{this.props.children}
</Animated.View>
Expand All @@ -473,6 +471,7 @@ class SwipeableView extends Component {
return (
<View
ref={ (ref) => (this._swipeoutRef = ref) }
onLayout={this._measureSwipeout}
{...this._panResponder.panHandlers}
collapsable={false}>
{btnsArray}
Expand Down