Fix touch events on Text elements

This commit is contained in:
Horcrux
2017-01-11 18:55:42 +08:00
parent d7daee343c
commit 6e81ecf147
4 changed files with 30 additions and 65 deletions
-41
View File
@@ -1,41 +0,0 @@
import React, {PropTypes} from 'react';
import createReactNativeComponentClass from 'react/lib/createReactNativeComponentClass';
import {SpanAttributes} from '../lib/attributes';
import Shape from './Shape';
import {pathProps, numberProp, fontProps} from '../lib/props';
// Span components are only for internal use for Text.
class Span extends Shape {
static displayName = 'Span';
static propTypes = {
...pathProps,
frame: PropTypes.shape({
content: PropTypes.string.isRequired,
dx: numberProp,
dy: numberProp,
px: numberProp,
py: numberProp,
font: PropTypes.shape(fontProps)
})
};
render() {
return <RNSVGSpan
{...this.extractProps({
...this.props,
x: null,
y: null
})}
{...this.props.frame}
/>;
}
}
const RNSVGSpan = createReactNativeComponentClass({
validAttributes: SpanAttributes,
uiViewClassName: 'RNSVGSpan'
});
export default Span;
+21 -18
View File
@@ -59,6 +59,11 @@
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event withTransform:(CGAffineTransform)transform
{
UIView *hitSelf = [super hitTest:point withEvent:event withTransform:transform];
if (hitSelf) {
return hitSelf;
}
CGAffineTransform matrix = CGAffineTransformConcat(self.matrix, transform);
CGPathRef clip = [self getClipPath];
@@ -72,25 +77,23 @@
}
}
for (RNSVGNode *node in [self.subviews reverseObjectEnumerator]) {
if ([node isKindOfClass:[RNSVGNode class]]) {
if (event) {
node.active = NO;
} else if (node.active) {
return node;
}
UIView *view = [node hitTest: point withEvent:event withTransform:matrix];
if (view) {
node.active = YES;
if (node.responsible || (node != view)) {
return view;
} else {
return self;
}
}
if (![node isKindOfClass:[RNSVGNode class]]) {
continue;
}
if (event) {
node.active = NO;
} else if (node.active) {
return node;
}
UIView *hitChild = [node hitTest: point withEvent:event withTransform:matrix];
if (hitChild) {
node.active = YES;
return (node.responsible || (node != hitChild)) ? hitChild : self;
}
}
return nil;
+4
View File
@@ -266,6 +266,10 @@
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event withTransform:(CGAffineTransform)transform
{
if (!_hitArea) {
return nil;
}
if (self.active) {
if (!event) {
self.active = NO;
+5 -6
View File
@@ -29,8 +29,12 @@
[self clip:context];
CGContextSaveGState(context);
[self setupGlyphContext:context];
CGAffineTransform transform = [self getAlignTransform:context];
CGPathRef path = [self getPath:context];
CGAffineTransform transform = [self getAlignTransform:context path:path];
CGContextConcatCTM(context, transform);
[self setHitArea:path];
[self renderGroupTo:context];
[self releaseCachedPath];
CGContextRestoreGState(context);
@@ -80,11 +84,6 @@
[self popGlyphContext];
}
- (CGAffineTransform)getAlignTransform:(CGContextRef)context
{
return [self getAlignTransform:context path:[self getGroupPath:context]];
}
- (CGAffineTransform)getAlignTransform:(CGContextRef)context path:(CGPathRef)path
{
CGFloat width = CGRectGetWidth(CGPathGetBoundingBox(path));