From a5e0b31f0212aeb98db86fd91b2faa5b27c108f8 Mon Sep 17 00:00:00 2001 From: Dario Thornhill Date: Wed, 2 Sep 2020 07:17:51 +0200 Subject: [PATCH] Added onSnapReached prop which runs a given callback passing to it the index of the running snappingPoint and it's height. --- SlidingUpPanel.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/SlidingUpPanel.js b/SlidingUpPanel.js index 270ae65..2978cab 100644 --- a/SlidingUpPanel.js +++ b/SlidingUpPanel.js @@ -51,6 +51,7 @@ class SlidingUpPanel extends React.PureComponent { onMomentumDragStart: PropTypes.func, onMomentumDragEnd: PropTypes.func, onBottomReached: PropTypes.func, + onSnapReached: PropTypes.func, allowMomentum: PropTypes.bool, allowDragging: PropTypes.bool, showBackdrop: PropTypes.bool, @@ -80,6 +81,7 @@ class SlidingUpPanel extends React.PureComponent { backdropOpacity: 0.75, friction: Constants.DEFAULT_FRICTION, onBottomReached: () => null, + onSnapReached: () => null, } // eslint-disable-next-line react/sort-comp @@ -282,11 +284,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 @@ -369,6 +376,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 }