diff --git a/README.md b/README.md index e99923e..9cf0c84 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,14 @@ Bounce the right component to alert swiping is possible. `onDone` is an optional Bounce the left component to alert swiping is possible. `onDone` is an optional callback. +#### openRight(onDone) + +Programmatically open the right component. `onDone` is an optional callback. + +#### openLeft(onDone) + +Programmatically open the left component. `onDone` is an optional callback. + ## Example To run [the example](https://github.com/jshanson7/react-native-swipeable/blob/master/example/swipeable-example.js): diff --git a/src/index.js b/src/index.js index 244bf99..a4fd568 100644 --- a/src/index.js +++ b/src/index.js @@ -212,6 +212,46 @@ export default class Swipeable extends PureComponent { animationFn(pan, animationConfig).start(onDone); }; + openRight = ( + animationFn = this.props.swipeReleaseAnimationFn, + onDone + ) => { + const {pan} = this.state; + + this.setState({ + lastOffset: {x: 0, y: 0}, + leftActionActivated: false, + leftButtonsActivated: false, + leftButtonsOpen: false, + rightActionActivated: true, + rightButtonsActivated: true, + rightButtonsOpen: true, + }, () => { + let animationConfig = this._getReleaseAnimationConfig(); + animationFn(pan, animationConfig).start(onDone); + }); + }; + + openLeft = ( + animationFn = this.props.swipeReleaseAnimationFn, + onDone + ) => { + const {pan} = this.state; + + this.setState({ + lastOffset: {x: 0, y: 0}, + leftActionActivated: true, + leftButtonsActivated: true, + leftButtonsOpen: true, + rightActionActivated: false, + rightButtonsActivated: false, + rightButtonsOpen: false, + }, () => { + let animationConfig = this._getReleaseAnimationConfig(); + animationFn(pan, animationConfig).start(onDone); + }); + }; + _bounceOnMount = () => { if (this._canSwipeLeft()) { this.bounceRight(this.bounceLeft);