diff --git a/README.md b/README.md index e99923e..b3fe1ac 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,34 @@ class MyListItem extends Component { } ``` +#### move() + +Imperatively move swipeable component + +```javascript +class MyListItem extends Component { + + swipeable = null; + + handleUserBeganScrollingParentView() { + // Move swipeable component outside of the view + this.swipeable.move(Animated.timing, { + toValue: { x: Dimensions.get('window').width, y: 0 }, + duration: ANIMATION_DURATION, + easing: Easing.elastic(0.5) + }); + } + + render() { + return ( + this.swipeable = ref} rightButtons={rightButtons}> + My swipeable content + + ); + } +} +``` + #### bounceRight(onDone) Bounce the right component to alert swiping is possible. `onDone` is an optional callback. diff --git a/src/index.js b/src/index.js index ecb295e..9e570c6 100644 --- a/src/index.js +++ b/src/index.js @@ -172,15 +172,13 @@ export default class Swipeable extends PureComponent { rightButtonsActivated: false, rightButtonsOpen: false }; - - componentWillMount() { + + componentDidMount() { const {onPanAnimatedValueRef, onRef} = this.props; onRef(this); onPanAnimatedValueRef(this.state.pan); - } - componentDidMount() { if (this.props.bounceOnMount) { setTimeout(this._bounceOnMount, 700); } @@ -190,7 +188,7 @@ export default class Swipeable extends PureComponent { this._unmounted = true; } - recenter = ( + move = ( animationFn = this.props.swipeReleaseAnimationFn, animationConfig = this.props.swipeReleaseAnimationConfig, onDone @@ -212,6 +210,14 @@ export default class Swipeable extends PureComponent { animationFn(pan, animationConfig).start(onDone); }; + recenter = ( + animationFn = this.props.swipeReleaseAnimationFn, + animationConfig = this.props.swipeReleaseAnimationConfig, + onDone + ) => { + this.move(animationFn, animationConfig, onDone) + }; + _bounceOnMount = () => { if (this._canSwipeLeft()) { this.bounceRight(this.bounceLeft);