diff --git a/index.js b/index.js index c69393b2..697a3d68 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, @@ -260,12 +260,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 }; @@ -307,7 +313,7 @@ export default class Drawer extends Component { if (!this._open && Math.abs(gestureState.dy) >= Math.abs(gestureState.dx)) 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 @@ -318,7 +324,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 @@ -358,6 +364,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 @@ -621,3 +633,4 @@ const styles = StyleSheet.create({ backgroundColor: 'transparent' } }) + 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); };