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
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<Swipeable onRef={ref => this.swipeable = ref} rightButtons={rightButtons}>
<Text>My swipeable content</Text>
</Swipeable>
);
}
}
```

#### bounceRight(onDone)

Bounce the right component to alert swiping is possible. `onDone` is an optional callback.
Expand Down
16 changes: 11 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -190,7 +188,7 @@ export default class Swipeable extends PureComponent {
this._unmounted = true;
}

recenter = (
move = (
animationFn = this.props.swipeReleaseAnimationFn,
animationConfig = this.props.swipeReleaseAnimationConfig,
onDone
Expand All @@ -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);
Expand Down