Skip to content

Commit

Permalink
Add support for press handlers in children.
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Jan 20, 2018
1 parent 21c6968 commit 9e6f73f
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
25 changes: 17 additions & 8 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,24 @@ export default class ZoomableSvg extends Component {
}

componentWillMount() {
const noop = () => {};
const yes = () => true;
const moveThreshold = this.props.moveThreshold || 5;
const shouldRespond = (evt, { dx, dy }) => {
return (
evt.nativeEvent.touches.length === 2 ||
dx * dx + dy * dy >= moveThreshold
);
};
this._panResponder = PanResponder.create({
onPanResponderGrant: () => {},
onPanResponderTerminate: () => {},
onMoveShouldSetPanResponder: () => true,
onStartShouldSetPanResponder: () => true,
onShouldBlockNativeResponder: () => true,
onPanResponderTerminationRequest: () => true,
onMoveShouldSetPanResponderCapture: () => true,
onStartShouldSetPanResponderCapture: () => true,
onPanResponderGrant: noop,
onPanResponderTerminate: noop,
onShouldBlockNativeResponder: yes,
onPanResponderTerminationRequest: yes,
onMoveShouldSetPanResponder: shouldRespond,
onStartShouldSetPanResponder: shouldRespond,
onMoveShouldSetPanResponderCapture: shouldRespond,
onStartShouldSetPanResponderCapture: shouldRespond,
onPanResponderMove: evt => {
const touches = evt.nativeEvent.touches;
const length = touches.length;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zoomable-svg",
"version": "1.0.0",
"version": "1.0.1",
"description": "Pinch to pan-n-zoom react-native-svg components using a render prop.",
"main": "index.js",
"repository": "https://github.com/msand/zoomable-svg",
Expand Down

0 comments on commit 9e6f73f

Please sign in to comment.