From e4246c8794eca66dec4948e52b5becf912c14954 Mon Sep 17 00:00:00 2001 From: Alexander Madyankin Date: Wed, 8 Nov 2017 15:18:10 +0300 Subject: [PATCH 1/2] Allow to pass a callback for the negotiatePan prop --- index.js | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/index.js b/index.js index a56df217..b92e5f96 100644 --- a/index.js +++ b/index.js @@ -48,7 +48,7 @@ export default class Drawer extends Component { elevation: PropTypes.number, initializeOpen: PropTypes.bool, open: PropTypes.bool, - negotiatePan: PropTypes.bool, + negotiatePan: PropTypes.oneOfType([PropTypes.bool, PropTypes.func]), onClose: PropTypes.func, onCloseStart: PropTypes.func, onOpen: PropTypes.func, @@ -259,12 +259,18 @@ export default class Drawer extends Component { }; onMoveShouldSetPanResponderCapture = (e, gestureState) => { - if (this.shouldCaptureGestures() && this.props.negotiatePan) return this.processMoveShouldSet(e, gestureState) + if (this.shouldCaptureGestures() && this.negotiatePan(e, gestureState)) { + return this.processMoveShouldSet(e, gestureState) + } + return false }; onMoveShouldSetPanResponder = (e, gestureState) => { - if (!this.shouldCaptureGestures() && this.props.negotiatePan) return this.processMoveShouldSet(e, gestureState) + if (!this.shouldCaptureGestures() && this.negotiatePan(e, gestureState)) { + return this.processMoveShouldSet(e, gestureState) + } + return false }; @@ -301,7 +307,7 @@ export default class Drawer extends Component { if (!inMask) return false this._panStartTime = Date.now() if (inMask && this.shouldCaptureGestures()) return true - if (this.props.negotiatePan) return false + if (this.negotiatePan(e, gestureState)) return false if (!this.props.acceptPan) return false this.terminateActiveTween() return true @@ -312,7 +318,7 @@ export default class Drawer extends Component { if (!inMask && (!this.props.acceptPanOnDrawer || this._open === false )) return false if (!this.props.acceptPan) return false - if (!this.props.negotiatePan || this.props.disabled || !this.props.acceptPan || this._panning) return false + if (!this.negotiatePan(e, gestureState) || this.props.disabled || !this.props.acceptPan || this._panning) return false let delta = this.getGestureDelta(gestureState) let deltaOppositeAxis = this.getGestureDeltaOppositeAxis(gestureState) let swipeToLeftOrTop = (delta < 0) ? true : false @@ -352,6 +358,12 @@ export default class Drawer extends Component { return false } + negotiatePan = (e, gestureState) => { + return typeof this.props.negotiatePan === 'function' + ? this.props.negotiatePan(e, gestureState) + : this.props.negotiatePan + } + testPanResponderMask = (e, gestureState) => { if (this.props.disabled) return false @@ -615,3 +627,4 @@ const styles = StyleSheet.create({ backgroundColor: 'transparent' } }) + From 489d402648c9513cac5f06881d0dd56b1568df3f Mon Sep 17 00:00:00 2001 From: Alexander Madyankin Date: Wed, 25 Jul 2018 14:17:58 +0600 Subject: [PATCH 2/2] Add tween value rounding to fix #349 --- tweener.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tweener.js b/tweener.js index 85bb2688..68393470 100644 --- a/tweener.js +++ b/tweener.js @@ -27,7 +27,7 @@ Tween.prototype._rafLoop = function() { } var tweenVal = easingTypes[easingType](elapsed, start, end, duration); - this._config.onFrame(tweenVal); + this._config.onFrame(Math.round(tweenVal)); requestAnimationFrame(this._rafLoop); };