Skip to content

Commit

Permalink
added openRight/openLeft instance methods
Browse files Browse the repository at this point in the history
  • Loading branch information
gurs1kh committed Mar 18, 2019
1 parent 8badc48 commit 3abfe52
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
40 changes: 40 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3abfe52

Please sign in to comment.