mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 16:54:52 +00:00
Add touch events support for G elements
This commit is contained in:
@@ -5,7 +5,8 @@ import React, {
|
|||||||
import Svg, {
|
import Svg, {
|
||||||
Circle,
|
Circle,
|
||||||
Path,
|
Path,
|
||||||
Rect
|
Rect,
|
||||||
|
G
|
||||||
} from 'react-native-svg';
|
} from 'react-native-svg';
|
||||||
|
|
||||||
class PressExample extends Component {
|
class PressExample extends Component {
|
||||||
@@ -65,6 +66,19 @@ class HoverExample extends Component {
|
|||||||
/>
|
/>
|
||||||
</Svg>;
|
</Svg>;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class GroupExample extends Component {
|
||||||
|
static title = 'Bind touch events callback on Group element';
|
||||||
|
|
||||||
|
render () {
|
||||||
|
return <Svg height="120" width="120">
|
||||||
|
<G onPress={() => alert('Pressed')}>
|
||||||
|
<Rect x="20" y="20" width="40" height="40" fill="yellow" />
|
||||||
|
<Circle cx="80" cy="80" r="30" fill="green" />
|
||||||
|
</G>
|
||||||
|
</Svg>;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,7 +97,8 @@ const icon = <Svg
|
|||||||
|
|
||||||
const samples = [
|
const samples = [
|
||||||
PressExample,
|
PressExample,
|
||||||
HoverExample
|
HoverExample,
|
||||||
|
GroupExample
|
||||||
];
|
];
|
||||||
|
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
[](https://www.npmjs.com/package/react-native-svg)
|
[](https://www.npmjs.com/package/react-native-svg)
|
||||||
[](https://travis-ci.org/magicismight/react-native-svg)
|
[](https://travis-ci.org/magicismight/react-native-svg)
|
||||||
|
[](https://snyk.io/test/npm/react-native-svg)
|
||||||
|
|
||||||
`react-native-svg` is built to provide a SVG interface to react native on both iOS and Android
|
`react-native-svg` is built to provide a SVG interface to react native on both iOS and Android
|
||||||
|
|
||||||
@@ -575,10 +576,9 @@ npm install
|
|||||||
|
|
||||||
#### TODO:
|
#### TODO:
|
||||||
1. add native method for elements
|
1. add native method for elements
|
||||||
2. more Text features support
|
2. more Text features support (textPath, tref, tspan)
|
||||||
3. Pattern element
|
3. Pattern element
|
||||||
4. implement Animated elements
|
4. implement Animated elements
|
||||||
5. refactor defs element (cannot use id prop for shape elements)
|
|
||||||
|
|
||||||
#### Thanks:
|
#### Thanks:
|
||||||
|
|
||||||
|
|||||||
+5
-10
@@ -1,10 +1,11 @@
|
|||||||
import React, {Component} from 'react';
|
import React from 'react';
|
||||||
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
|
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
|
||||||
|
import Shape from './Shape';
|
||||||
import {transformProps} from '../lib/props';
|
import {transformProps} from '../lib/props';
|
||||||
import {GroupAttributes} from '../lib/attributes';
|
import {GroupAttributes} from '../lib/attributes';
|
||||||
import extractProps from '../lib/extract/extractProps';
|
import extractProps from '../lib/extract/extractProps';
|
||||||
|
|
||||||
class G extends Component{
|
class G extends Shape{
|
||||||
static displayName = 'G';
|
static displayName = 'G';
|
||||||
|
|
||||||
static propTypes = transformProps;
|
static propTypes = transformProps;
|
||||||
@@ -16,17 +17,11 @@ class G extends Component{
|
|||||||
render() {
|
render() {
|
||||||
let {props} = this;
|
let {props} = this;
|
||||||
|
|
||||||
let extractedProps = extractProps(props, {
|
|
||||||
stroke: true,
|
|
||||||
fill: true,
|
|
||||||
transform: true
|
|
||||||
});
|
|
||||||
|
|
||||||
return <RNSVGGroup
|
return <RNSVGGroup
|
||||||
{...extractedProps}
|
{...this.extractProps(props)}
|
||||||
ref={ele => {this.root = ele;}}
|
ref={ele => {this.root = ele;}}
|
||||||
>
|
>
|
||||||
{this.props.children}
|
{props.children}
|
||||||
</RNSVGGroup>;
|
</RNSVGGroup>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -12,7 +12,7 @@ class Shape extends Component {
|
|||||||
this.state = this.touchableGetInitialState();
|
this.state = this.touchableGetInitialState();
|
||||||
}
|
}
|
||||||
|
|
||||||
extractProps = (props, options = {stroke: true, transform: true, fill: true, responder: true}) => {
|
extractProps = (props, options) => {
|
||||||
let extractedProps = extractProps(props, options);
|
let extractedProps = extractProps(props, options);
|
||||||
if (extractedProps.touchable && !extractedProps.disabled) {
|
if (extractedProps.touchable && !extractedProps.disabled) {
|
||||||
_.assign(extractedProps, {
|
_.assign(extractedProps, {
|
||||||
|
|||||||
+1
-6
@@ -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 + '"');
|
console.warn('Invalid `href` prop for `Use` element, expected a href like `"#id"`, but got: "' + props.href + '"');
|
||||||
}
|
}
|
||||||
|
|
||||||
let extractedProps = this.extractProps(props, {
|
let extractedProps = this.extractProps(props);
|
||||||
stroke: true,
|
|
||||||
fill: true,
|
|
||||||
responder: true,
|
|
||||||
transform: true
|
|
||||||
});
|
|
||||||
|
|
||||||
return <RNSVGUse
|
return <RNSVGUse
|
||||||
ref={ele => {this.root = ele;}}
|
ref={ele => {this.root = ele;}}
|
||||||
|
|||||||
@@ -46,7 +46,7 @@
|
|||||||
if ([node isKindOfClass:[RNSVGNode class]]) {
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
UIView *view = [node hitTest: point withEvent:event];
|
UIView *view = [node hitTest: point withEvent:event];
|
||||||
if (view) {
|
if (view) {
|
||||||
return view;
|
return self;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user