2016-05-04 22:49:02 +00:00
|
|
|
/**
|
2017-03-24 21:36:07 +00:00
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
2016-05-04 22:49:02 +00:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* @providesModule SwipeableRow
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const Animated = require('Animated');
|
2016-07-12 03:43:53 +00:00
|
|
|
const I18nManager = require('I18nManager');
|
2017-02-03 21:47:50 +00:00
|
|
|
const PanResponder = require('PanResponder');
|
2016-05-04 22:49:02 +00:00
|
|
|
const React = require('React');
|
2017-04-12 23:09:48 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2016-05-04 22:49:02 +00:00
|
|
|
const StyleSheet = require('StyleSheet');
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2016-06-07 16:07:30 +00:00
|
|
|
const TimerMixin = require('react-timer-mixin');
|
2016-05-04 22:49:02 +00:00
|
|
|
const View = require('View');
|
|
|
|
|
2017-07-07 21:24:25 +00:00
|
|
|
const createReactClass = require('create-react-class');
|
2017-09-06 10:25:01 +00:00
|
|
|
/* $FlowFixMe(>=0.54.0 site=react_native_oss) This comment suppresses an error
|
|
|
|
* found when Flow v0.54 was deployed. To see the error delete this comment and
|
|
|
|
* run Flow. */
|
2016-06-06 20:47:21 +00:00
|
|
|
const emptyFunction = require('fbjs/lib/emptyFunction');
|
2016-05-17 03:21:47 +00:00
|
|
|
|
2016-07-08 19:02:44 +00:00
|
|
|
const IS_RTL = I18nManager.isRTL;
|
|
|
|
|
2016-06-07 16:07:30 +00:00
|
|
|
// NOTE: Eventually convert these consts to an input object of configurations
|
|
|
|
|
2016-05-04 22:49:02 +00:00
|
|
|
// Position of the left of the swipable item when closed
|
|
|
|
const CLOSED_LEFT_POSITION = 0;
|
2016-05-05 02:50:09 +00:00
|
|
|
// Minimum swipe distance before we recognize it as such
|
2016-06-16 02:02:35 +00:00
|
|
|
const HORIZONTAL_SWIPE_DISTANCE_THRESHOLD = 10;
|
2016-06-07 16:07:30 +00:00
|
|
|
// Minimum swipe speed before we fully animate the user's action (open/close)
|
2016-06-16 02:02:35 +00:00
|
|
|
const HORIZONTAL_FULL_SWIPE_SPEED_THRESHOLD = 0.3;
|
2016-06-06 21:49:23 +00:00
|
|
|
// Factor to divide by to get slow speed; i.e. 4 means 1/4 of full speed
|
|
|
|
const SLOW_SPEED_SWIPE_FACTOR = 4;
|
2016-06-07 16:07:30 +00:00
|
|
|
// Time, in milliseconds, of how long the animated swipe should be
|
2016-09-01 01:07:14 +00:00
|
|
|
const SWIPE_DURATION = 300;
|
2016-06-07 16:07:30 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* On SwipeableListView mount, the 1st item will bounce to show users it's
|
|
|
|
* possible to swipe
|
|
|
|
*/
|
|
|
|
const ON_MOUNT_BOUNCE_DELAY = 700;
|
2016-06-11 00:26:02 +00:00
|
|
|
const ON_MOUNT_BOUNCE_DURATION = 400;
|
2016-06-07 16:07:30 +00:00
|
|
|
|
|
|
|
// Distance left of closed position to bounce back when right-swiping from closed
|
2016-09-01 01:07:14 +00:00
|
|
|
const RIGHT_SWIPE_BOUNCE_BACK_DISTANCE = 30;
|
|
|
|
const RIGHT_SWIPE_BOUNCE_BACK_DURATION = 300;
|
2016-06-06 21:49:23 +00:00
|
|
|
/**
|
|
|
|
* Max distance of right swipe to allow (right swipes do functionally nothing).
|
|
|
|
* Must be multiplied by SLOW_SPEED_SWIPE_FACTOR because gestureState.dx tracks
|
|
|
|
* how far the finger swipes, and not the actual animation distance.
|
|
|
|
*/
|
|
|
|
const RIGHT_SWIPE_THRESHOLD = 30 * SLOW_SPEED_SWIPE_FACTOR;
|
2016-05-04 22:49:02 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a swipable row that allows taps on the main item and a custom View
|
2016-06-07 18:55:38 +00:00
|
|
|
* on the item hidden behind the row. Typically this should be used in
|
|
|
|
* conjunction with SwipeableListView for additional functionality, but can be
|
|
|
|
* used in a normal ListView. See the renderRow for SwipeableListView to see how
|
|
|
|
* to use this component separately.
|
2016-05-04 22:49:02 +00:00
|
|
|
*/
|
2017-07-07 21:24:25 +00:00
|
|
|
const SwipeableRow = createReactClass({
|
|
|
|
displayName: 'SwipeableRow',
|
2016-05-04 22:49:02 +00:00
|
|
|
_panResponder: {},
|
|
|
|
_previousLeft: CLOSED_LEFT_POSITION,
|
|
|
|
|
2016-06-07 16:07:30 +00:00
|
|
|
mixins: [TimerMixin],
|
|
|
|
|
2016-05-04 22:49:02 +00:00
|
|
|
propTypes: {
|
2016-06-13 23:57:11 +00:00
|
|
|
children: PropTypes.any,
|
2016-05-05 18:48:25 +00:00
|
|
|
isOpen: PropTypes.bool,
|
2017-07-08 02:52:10 +00:00
|
|
|
preventSwipeRight: PropTypes.bool,
|
2016-05-20 04:39:58 +00:00
|
|
|
maxSwipeDistance: PropTypes.number.isRequired,
|
2016-06-06 21:49:23 +00:00
|
|
|
onOpen: PropTypes.func.isRequired,
|
2017-02-02 12:47:49 +00:00
|
|
|
onClose: PropTypes.func.isRequired,
|
2016-05-17 03:21:47 +00:00
|
|
|
onSwipeEnd: PropTypes.func.isRequired,
|
|
|
|
onSwipeStart: PropTypes.func.isRequired,
|
2016-06-07 16:07:30 +00:00
|
|
|
// Should bounce the row on mount
|
|
|
|
shouldBounceOnMount: PropTypes.bool,
|
2016-05-04 22:49:02 +00:00
|
|
|
/**
|
|
|
|
* A ReactElement that is unveiled when the user swipes
|
|
|
|
*/
|
|
|
|
slideoutView: PropTypes.node.isRequired,
|
|
|
|
/**
|
|
|
|
* The minimum swipe distance required before fully animating the swipe. If
|
|
|
|
* the user swipes less than this distance, the item will return to its
|
|
|
|
* previous (open/close) position.
|
|
|
|
*/
|
|
|
|
swipeThreshold: PropTypes.number.isRequired,
|
|
|
|
},
|
|
|
|
|
|
|
|
getInitialState(): Object {
|
|
|
|
return {
|
|
|
|
currentLeft: new Animated.Value(this._previousLeft),
|
2016-05-17 03:21:47 +00:00
|
|
|
/**
|
|
|
|
* In order to render component A beneath component B, A must be rendered
|
|
|
|
* before B. However, this will cause "flickering", aka we see A briefly
|
|
|
|
* then B. To counter this, _isSwipeableViewRendered flag is used to set
|
|
|
|
* component A to be transparent until component B is loaded.
|
|
|
|
*/
|
|
|
|
isSwipeableViewRendered: false,
|
2016-05-20 04:40:03 +00:00
|
|
|
rowHeight: (null: ?number),
|
2016-05-04 22:49:02 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
getDefaultProps(): Object {
|
|
|
|
return {
|
2016-05-05 18:48:25 +00:00
|
|
|
isOpen: false,
|
2017-07-08 02:52:10 +00:00
|
|
|
preventSwipeRight: false,
|
2016-05-20 04:39:58 +00:00
|
|
|
maxSwipeDistance: 0,
|
2016-06-06 21:49:23 +00:00
|
|
|
onOpen: emptyFunction,
|
2017-02-02 12:47:49 +00:00
|
|
|
onClose: emptyFunction,
|
2016-05-17 03:21:47 +00:00
|
|
|
onSwipeEnd: emptyFunction,
|
|
|
|
onSwipeStart: emptyFunction,
|
|
|
|
swipeThreshold: 30,
|
2016-05-04 22:49:02 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
componentWillMount(): void {
|
|
|
|
this._panResponder = PanResponder.create({
|
2016-05-05 02:50:09 +00:00
|
|
|
onMoveShouldSetPanResponderCapture: this._handleMoveShouldSetPanResponderCapture,
|
2016-05-17 03:21:47 +00:00
|
|
|
onPanResponderGrant: this._handlePanResponderGrant,
|
2016-05-04 22:49:02 +00:00
|
|
|
onPanResponderMove: this._handlePanResponderMove,
|
|
|
|
onPanResponderRelease: this._handlePanResponderEnd,
|
2016-05-17 03:21:47 +00:00
|
|
|
onPanResponderTerminationRequest: this._onPanResponderTerminationRequest,
|
2016-05-04 22:49:02 +00:00
|
|
|
onPanResponderTerminate: this._handlePanResponderEnd,
|
2017-01-19 22:41:48 +00:00
|
|
|
onShouldBlockNativeResponder: (event, gestureState) => false,
|
2016-05-04 22:49:02 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-06-07 16:07:30 +00:00
|
|
|
componentDidMount(): void {
|
|
|
|
if (this.props.shouldBounceOnMount) {
|
|
|
|
/**
|
|
|
|
* Do the on mount bounce after a delay because if we animate when other
|
|
|
|
* components are loading, the animation will be laggy
|
|
|
|
*/
|
|
|
|
this.setTimeout(() => {
|
|
|
|
this._animateBounceBack(ON_MOUNT_BOUNCE_DURATION);
|
|
|
|
}, ON_MOUNT_BOUNCE_DELAY);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-05-05 18:48:25 +00:00
|
|
|
componentWillReceiveProps(nextProps: Object): void {
|
|
|
|
/**
|
|
|
|
* We do not need an "animateOpen(noCallback)" because this animation is
|
|
|
|
* handled internally by this component.
|
|
|
|
*/
|
|
|
|
if (this.props.isOpen && !nextProps.isOpen) {
|
2016-05-17 03:21:47 +00:00
|
|
|
this._animateToClosedPosition();
|
2016-05-05 18:48:25 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-07 16:07:30 +00:00
|
|
|
shouldComponentUpdate(nextProps: Object, nextState: Object): boolean {
|
|
|
|
if (this.props.shouldBounceOnMount && !nextProps.shouldBounceOnMount) {
|
|
|
|
// No need to rerender if SwipeableListView is disabling the bounce flag
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
},
|
|
|
|
|
2016-10-16 11:11:59 +00:00
|
|
|
render(): React.Element<any> {
|
2016-05-04 22:49:02 +00:00
|
|
|
// The view hidden behind the main view
|
2016-05-20 04:39:58 +00:00
|
|
|
let slideOutView;
|
2017-02-03 21:47:50 +00:00
|
|
|
if (this.state.isSwipeableViewRendered && this.state.rowHeight) {
|
2016-05-20 04:39:58 +00:00
|
|
|
slideOutView = (
|
2016-05-20 04:40:03 +00:00
|
|
|
<View style={[
|
|
|
|
styles.slideOutContainer,
|
|
|
|
{height: this.state.rowHeight},
|
|
|
|
]}>
|
2016-05-20 04:39:58 +00:00
|
|
|
{this.props.slideoutView}
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2016-05-04 22:49:02 +00:00
|
|
|
|
2016-05-20 04:39:58 +00:00
|
|
|
// The swipeable item
|
2016-05-06 03:44:48 +00:00
|
|
|
const swipeableView = (
|
2016-05-04 22:49:02 +00:00
|
|
|
<Animated.View
|
2016-05-06 03:44:48 +00:00
|
|
|
onLayout={this._onSwipeableViewLayout}
|
2017-02-08 23:54:51 +00:00
|
|
|
style={{transform: [{translateX: this.state.currentLeft}]}}>
|
2016-05-04 22:49:02 +00:00
|
|
|
{this.props.children}
|
|
|
|
</Animated.View>
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<View
|
2016-05-20 04:40:03 +00:00
|
|
|
{...this._panResponder.panHandlers}>
|
2016-05-04 22:49:02 +00:00
|
|
|
{slideOutView}
|
2016-05-06 03:44:48 +00:00
|
|
|
{swipeableView}
|
2016-05-04 22:49:02 +00:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2017-07-04 02:03:21 +00:00
|
|
|
close(): void {
|
|
|
|
this.props.onClose();
|
|
|
|
this._animateToClosedPosition();
|
|
|
|
},
|
|
|
|
|
2016-05-06 03:44:48 +00:00
|
|
|
_onSwipeableViewLayout(event: Object): void {
|
2016-06-13 23:57:11 +00:00
|
|
|
this.setState({
|
|
|
|
isSwipeableViewRendered: true,
|
|
|
|
rowHeight: event.nativeEvent.layout.height,
|
|
|
|
});
|
2016-05-06 03:44:48 +00:00
|
|
|
},
|
|
|
|
|
2016-05-05 02:50:09 +00:00
|
|
|
_handleMoveShouldSetPanResponderCapture(
|
|
|
|
event: Object,
|
|
|
|
gestureState: Object,
|
|
|
|
): boolean {
|
2016-05-17 03:21:47 +00:00
|
|
|
// Decides whether a swipe is responded to by this component or its child
|
2016-05-31 23:23:51 +00:00
|
|
|
return gestureState.dy < 10 && this._isValidSwipe(gestureState);
|
2016-05-04 22:49:02 +00:00
|
|
|
},
|
|
|
|
|
2016-05-17 03:21:47 +00:00
|
|
|
_handlePanResponderGrant(event: Object, gestureState: Object): void {
|
2016-05-04 22:49:02 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_handlePanResponderMove(event: Object, gestureState: Object): void {
|
2016-06-06 21:49:23 +00:00
|
|
|
if (this._isSwipingExcessivelyRightFromClosedPosition(gestureState)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-05-17 03:21:47 +00:00
|
|
|
this.props.onSwipeStart();
|
2016-05-31 23:23:51 +00:00
|
|
|
|
2016-06-06 21:49:23 +00:00
|
|
|
if (this._isSwipingRightFromClosed(gestureState)) {
|
|
|
|
this._swipeSlowSpeed(gestureState);
|
|
|
|
} else {
|
|
|
|
this._swipeFullSpeed(gestureState);
|
2016-05-31 23:23:51 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2016-06-06 21:49:23 +00:00
|
|
|
_isSwipingRightFromClosed(gestureState: Object): boolean {
|
2016-07-08 19:02:44 +00:00
|
|
|
const gestureStateDx = IS_RTL ? -gestureState.dx : gestureState.dx;
|
|
|
|
return this._previousLeft === CLOSED_LEFT_POSITION && gestureStateDx > 0;
|
2016-05-04 22:49:02 +00:00
|
|
|
},
|
|
|
|
|
2016-06-06 21:49:23 +00:00
|
|
|
_swipeFullSpeed(gestureState: Object): void {
|
|
|
|
this.state.currentLeft.setValue(this._previousLeft + gestureState.dx);
|
|
|
|
},
|
|
|
|
|
|
|
|
_swipeSlowSpeed(gestureState: Object): void {
|
|
|
|
this.state.currentLeft.setValue(
|
|
|
|
this._previousLeft + gestureState.dx / SLOW_SPEED_SWIPE_FACTOR,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_isSwipingExcessivelyRightFromClosedPosition(gestureState: Object): boolean {
|
|
|
|
/**
|
|
|
|
* We want to allow a BIT of right swipe, to allow users to know that
|
|
|
|
* swiping is available, but swiping right does not do anything
|
|
|
|
* functionally.
|
|
|
|
*/
|
2016-07-08 19:02:44 +00:00
|
|
|
const gestureStateDx = IS_RTL ? -gestureState.dx : gestureState.dx;
|
2016-06-06 21:49:23 +00:00
|
|
|
return (
|
|
|
|
this._isSwipingRightFromClosed(gestureState) &&
|
2016-07-08 19:02:44 +00:00
|
|
|
gestureStateDx > RIGHT_SWIPE_THRESHOLD
|
2016-06-06 21:49:23 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
|
|
|
_onPanResponderTerminationRequest(
|
|
|
|
event: Object,
|
|
|
|
gestureState: Object,
|
|
|
|
): boolean {
|
2016-05-17 03:21:47 +00:00
|
|
|
return false;
|
2016-05-04 22:49:02 +00:00
|
|
|
},
|
|
|
|
|
2016-06-07 16:07:30 +00:00
|
|
|
_animateTo(
|
|
|
|
toValue: number,
|
|
|
|
duration: number = SWIPE_DURATION,
|
|
|
|
callback: Function = emptyFunction,
|
|
|
|
): void {
|
2016-05-17 03:21:47 +00:00
|
|
|
Animated.timing(
|
|
|
|
this.state.currentLeft,
|
|
|
|
{
|
2016-06-07 16:07:30 +00:00
|
|
|
duration,
|
|
|
|
toValue,
|
2017-07-04 02:03:21 +00:00
|
|
|
useNativeDriver: true,
|
2016-05-17 03:21:47 +00:00
|
|
|
},
|
|
|
|
).start(() => {
|
2016-05-04 22:49:02 +00:00
|
|
|
this._previousLeft = toValue;
|
2016-06-06 21:49:23 +00:00
|
|
|
callback();
|
2016-05-04 22:49:02 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-05-17 03:21:47 +00:00
|
|
|
_animateToOpenPosition(): void {
|
2016-07-08 19:02:44 +00:00
|
|
|
const maxSwipeDistance = IS_RTL ? -this.props.maxSwipeDistance : this.props.maxSwipeDistance;
|
|
|
|
this._animateTo(-maxSwipeDistance);
|
2016-05-04 22:49:02 +00:00
|
|
|
},
|
|
|
|
|
2016-09-01 01:07:14 +00:00
|
|
|
_animateToOpenPositionWith(
|
|
|
|
speed: number,
|
|
|
|
distMoved: number,
|
|
|
|
): void {
|
|
|
|
/**
|
|
|
|
* Ensure the speed is at least the set speed threshold to prevent a slow
|
|
|
|
* swiping animation
|
|
|
|
*/
|
|
|
|
speed = (
|
|
|
|
speed > HORIZONTAL_FULL_SWIPE_SPEED_THRESHOLD ?
|
|
|
|
speed :
|
|
|
|
HORIZONTAL_FULL_SWIPE_SPEED_THRESHOLD
|
|
|
|
);
|
|
|
|
/**
|
|
|
|
* Calculate the duration the row should take to swipe the remaining distance
|
|
|
|
* at the same speed the user swiped (or the speed threshold)
|
|
|
|
*/
|
|
|
|
const duration = Math.abs((this.props.maxSwipeDistance - Math.abs(distMoved)) / speed);
|
|
|
|
const maxSwipeDistance = IS_RTL ? -this.props.maxSwipeDistance : this.props.maxSwipeDistance;
|
|
|
|
this._animateTo(-maxSwipeDistance, duration);
|
|
|
|
},
|
|
|
|
|
2016-06-11 00:26:02 +00:00
|
|
|
_animateToClosedPosition(duration: number = SWIPE_DURATION): void {
|
|
|
|
this._animateTo(CLOSED_LEFT_POSITION, duration);
|
2016-05-04 22:49:02 +00:00
|
|
|
},
|
|
|
|
|
2016-06-11 00:26:02 +00:00
|
|
|
_animateToClosedPositionDuringBounce(): void {
|
|
|
|
this._animateToClosedPosition(RIGHT_SWIPE_BOUNCE_BACK_DURATION);
|
|
|
|
},
|
|
|
|
|
|
|
|
_animateBounceBack(duration: number): void {
|
2016-06-06 21:49:23 +00:00
|
|
|
/**
|
|
|
|
* When swiping right, we want to bounce back past closed position on release
|
|
|
|
* so users know they should swipe right to get content.
|
|
|
|
*/
|
2016-07-12 03:43:53 +00:00
|
|
|
const swipeBounceBackDistance = IS_RTL ?
|
|
|
|
-RIGHT_SWIPE_BOUNCE_BACK_DISTANCE :
|
|
|
|
RIGHT_SWIPE_BOUNCE_BACK_DISTANCE;
|
2016-06-06 21:49:23 +00:00
|
|
|
this._animateTo(
|
2016-07-08 19:02:44 +00:00
|
|
|
-swipeBounceBackDistance,
|
2016-06-07 16:07:30 +00:00
|
|
|
duration,
|
2016-06-11 00:26:02 +00:00
|
|
|
this._animateToClosedPositionDuringBounce,
|
2016-06-06 21:49:23 +00:00
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-05-17 03:21:47 +00:00
|
|
|
// Ignore swipes due to user's finger moving slightly when tapping
|
|
|
|
_isValidSwipe(gestureState: Object): boolean {
|
2017-08-01 21:03:27 +00:00
|
|
|
if (this.props.preventSwipeRight && this._previousLeft === CLOSED_LEFT_POSITION && gestureState.dx > 0) {
|
2017-07-08 02:52:10 +00:00
|
|
|
return false;
|
|
|
|
}
|
2017-08-01 21:03:27 +00:00
|
|
|
|
2016-05-17 03:21:47 +00:00
|
|
|
return Math.abs(gestureState.dx) > HORIZONTAL_SWIPE_DISTANCE_THRESHOLD;
|
|
|
|
},
|
|
|
|
|
2016-06-07 16:07:30 +00:00
|
|
|
_shouldAnimateRemainder(gestureState: Object): boolean {
|
|
|
|
/**
|
|
|
|
* If user has swiped past a certain distance, animate the rest of the way
|
|
|
|
* if they let go
|
|
|
|
*/
|
|
|
|
return (
|
|
|
|
Math.abs(gestureState.dx) > this.props.swipeThreshold ||
|
|
|
|
gestureState.vx > HORIZONTAL_FULL_SWIPE_SPEED_THRESHOLD
|
|
|
|
);
|
|
|
|
},
|
|
|
|
|
2016-05-04 22:49:02 +00:00
|
|
|
_handlePanResponderEnd(event: Object, gestureState: Object): void {
|
2016-07-08 19:02:44 +00:00
|
|
|
const horizontalDistance = IS_RTL ? -gestureState.dx : gestureState.dx;
|
2016-06-06 21:49:23 +00:00
|
|
|
if (this._isSwipingRightFromClosed(gestureState)) {
|
|
|
|
this.props.onOpen();
|
2016-06-11 00:26:02 +00:00
|
|
|
this._animateBounceBack(RIGHT_SWIPE_BOUNCE_BACK_DURATION);
|
2016-06-07 16:07:30 +00:00
|
|
|
} else if (this._shouldAnimateRemainder(gestureState)) {
|
2016-05-17 03:21:47 +00:00
|
|
|
if (horizontalDistance < 0) {
|
|
|
|
// Swiped left
|
2016-06-06 21:49:23 +00:00
|
|
|
this.props.onOpen();
|
2016-09-01 01:07:14 +00:00
|
|
|
this._animateToOpenPositionWith(gestureState.vx, horizontalDistance);
|
2016-05-17 03:21:47 +00:00
|
|
|
} else {
|
|
|
|
// Swiped right
|
2017-02-02 12:47:49 +00:00
|
|
|
this.props.onClose();
|
2016-05-17 03:21:47 +00:00
|
|
|
this._animateToClosedPosition();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (this._previousLeft === CLOSED_LEFT_POSITION) {
|
|
|
|
this._animateToClosedPosition();
|
|
|
|
} else {
|
|
|
|
this._animateToOpenPosition();
|
|
|
|
}
|
2016-05-04 22:49:02 +00:00
|
|
|
}
|
|
|
|
|
2016-05-17 03:21:47 +00:00
|
|
|
this.props.onSwipeEnd();
|
2016-05-04 22:49:02 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
slideOutContainer: {
|
2016-05-17 08:35:47 +00:00
|
|
|
bottom: 0,
|
|
|
|
left: 0,
|
|
|
|
position: 'absolute',
|
|
|
|
right: 0,
|
|
|
|
top: 0,
|
2016-05-04 22:49:02 +00:00
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = SwipeableRow;
|