Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow to pass a callback via the negotiatePan prop #333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 18 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
};

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -615,3 +627,4 @@ const styles = StyleSheet.create({
backgroundColor: 'transparent'
}
})