Skip to content

Commit

Permalink
Added onSnapReached prop which runs a given callback passing to it th…
Browse files Browse the repository at this point in the history
…e index of the running snappingPoint and it's height.
  • Loading branch information
dariothornhill committed Sep 2, 2020
1 parent ad996b9 commit 9ac9cc7
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions SlidingUpPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class SlidingUpPanel extends React.PureComponent {
backdropOpacity: 0.75,
friction: Constants.DEFAULT_FRICTION,
onBottomReached: () => null,
onSnapReached: () => null,
}

// eslint-disable-next-line react/sort-comp
Expand Down Expand Up @@ -282,11 +283,16 @@ class SlidingUpPanel extends React.PureComponent {

_onAnimatedValueChange({value}) {
const isAtBottom = this._isAtBottom(value)
const isAtSnap = this._isAtSnap(value)

if (isAtBottom) {
this.props.onBottomReached()
this.props.avoidKeyboard && Keyboard.dismiss()
}
if (isAtSnap > -1 && !isAtBottom) {
this.props.onSnapReached(isAtSnap, value);
this.props.avoidKeyboard && Keyboard.dismiss()
}

if (this._backdrop == null) {
return
Expand Down Expand Up @@ -369,6 +375,15 @@ class SlidingUpPanel extends React.PureComponent {
return value <= bottom
}

_isAtSnap(value) {
const snappingPoints= this.props.snappingPoints;
let found = -1;
if (snappingPoints) {
found = snappingPoints.findIndex((point) => point === value);
}
return found;
}

_storeKeyboardPosition(value) {
this._keyboardYPosition = value
}
Expand Down

0 comments on commit 9ac9cc7

Please sign in to comment.