From 6c7c2fdf3f0d7c6d51f396b8230ed79e285578ba Mon Sep 17 00:00:00 2001 From: Horcrux Date: Sun, 31 Jul 2016 22:01:14 +0800 Subject: [PATCH] Add touch events support for G elements --- Example/examples/TouchEvents.js | 19 +++++++++++++++++-- README.md | 4 ++-- elements/G.js | 15 +++++---------- elements/Shape.js | 2 +- elements/Use.js | 7 +------ ios/Elements/RNSVGGroup.m | 2 +- 6 files changed, 27 insertions(+), 22 deletions(-) diff --git a/Example/examples/TouchEvents.js b/Example/examples/TouchEvents.js index cc20b935..8963bcf2 100644 --- a/Example/examples/TouchEvents.js +++ b/Example/examples/TouchEvents.js @@ -5,7 +5,8 @@ import React, { import Svg, { Circle, Path, - Rect + Rect, + G } from 'react-native-svg'; class PressExample extends Component { @@ -65,6 +66,19 @@ class HoverExample extends Component { /> ; } +} + +class GroupExample extends Component { + static title = 'Bind touch events callback on Group element'; + + render () { + return + alert('Pressed')}> + + + + ; + } } @@ -83,7 +97,8 @@ const icon = {this.root = ele;}} > - {this.props.children} + {props.children} ; } } diff --git a/elements/Shape.js b/elements/Shape.js index 911f5a94..25d13461 100644 --- a/elements/Shape.js +++ b/elements/Shape.js @@ -12,7 +12,7 @@ class Shape extends Component { this.state = this.touchableGetInitialState(); } - extractProps = (props, options = {stroke: true, transform: true, fill: true, responder: true}) => { + extractProps = (props, options) => { let extractedProps = extractProps(props, options); if (extractedProps.touchable && !extractedProps.disabled) { _.assign(extractedProps, { diff --git a/elements/Use.js b/elements/Use.js index 6e52a944..f02645f4 100644 --- a/elements/Use.js +++ b/elements/Use.js @@ -34,12 +34,7 @@ class Use extends Shape { console.warn('Invalid `href` prop for `Use` element, expected a href like `"#id"`, but got: "' + props.href + '"'); } - let extractedProps = this.extractProps(props, { - stroke: true, - fill: true, - responder: true, - transform: true - }); + let extractedProps = this.extractProps(props); return {this.root = ele;}} diff --git a/ios/Elements/RNSVGGroup.m b/ios/Elements/RNSVGGroup.m index f9b4b14b..18a0896e 100644 --- a/ios/Elements/RNSVGGroup.m +++ b/ios/Elements/RNSVGGroup.m @@ -46,7 +46,7 @@ if ([node isKindOfClass:[RNSVGNode class]]) { UIView *view = [node hitTest: point withEvent:event]; if (view) { - return view; + return self; } } }