mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 00:42:31 +00:00
[ios] Improve gesture responder and onPress/In/Out transform handling
This commit is contained in:
@@ -91,7 +91,7 @@ public class SvgView extends ReactViewGroup implements ReactCompoundView, ReactC
|
|||||||
if (mBitmap != null)
|
if (mBitmap != null)
|
||||||
canvas.drawBitmap(mBitmap, 0, 0, null);
|
canvas.drawBitmap(mBitmap, 0, 0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
|
||||||
super.onSizeChanged(w, h, oldw, oldh);
|
super.onSizeChanged(w, h, oldw, oldh);
|
||||||
|
|||||||
+11
-12
@@ -35,7 +35,7 @@
|
|||||||
{
|
{
|
||||||
[self pushGlyphContext];
|
[self pushGlyphContext];
|
||||||
|
|
||||||
__block CGRect groupRect = CGRectNull;
|
__block CGRect bounds = CGRectNull;
|
||||||
|
|
||||||
[self traverseSubviews:^(UIView *node) {
|
[self traverseSubviews:^(UIView *node) {
|
||||||
if ([node isKindOfClass:[RNSVGNode class]]) {
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
CGRect nodeRect = svgNode.clientRect;
|
CGRect nodeRect = svgNode.clientRect;
|
||||||
if (!CGRectIsEmpty(nodeRect)) {
|
if (!CGRectIsEmpty(nodeRect)) {
|
||||||
groupRect = CGRectUnion(groupRect, nodeRect);
|
bounds = CGRectUnion(bounds, nodeRect);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
||||||
@@ -72,16 +72,16 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}];
|
}];
|
||||||
[self setHitArea:[self getPath:context]];
|
[self setHitArea:[self getPath:context]];
|
||||||
self.clientRect = groupRect;
|
self.clientRect = bounds;
|
||||||
|
|
||||||
const CGAffineTransform matrix = self.matrix;
|
CGAffineTransform matrix = self.transform;
|
||||||
const CGAffineTransform current = CGContextGetCTM(context);
|
CGPoint mid = CGPointMake(CGRectGetMidX(bounds), CGRectGetMidY(bounds));
|
||||||
const CGAffineTransform svgToClientTransform = CGAffineTransformConcat(current, self.svgView.invInitialCTM);
|
CGPoint center = CGPointApplyAffineTransform(mid, matrix);
|
||||||
const CGRect clientRect = CGRectApplyAffineTransform(groupRect, svgToClientTransform);
|
CGRect frame = CGRectApplyAffineTransform(bounds, matrix);
|
||||||
const CGSize clientSize = clientRect.size;
|
|
||||||
|
|
||||||
self.bounds = CGRectMake(0, 0, clientSize.width, clientSize.height);
|
self.bounds = bounds;
|
||||||
self.frame = CGRectMake(matrix.tx, matrix.ty, clientSize.width, clientSize.height);
|
self.center = center;
|
||||||
|
self.frame = frame;
|
||||||
|
|
||||||
[self popGlyphContext];
|
[self popGlyphContext];
|
||||||
}
|
}
|
||||||
@@ -89,7 +89,6 @@
|
|||||||
- (void)setupGlyphContext:(CGContextRef)context
|
- (void)setupGlyphContext:(CGContextRef)context
|
||||||
{
|
{
|
||||||
CGRect clipBounds = CGContextGetClipBoundingBox(context);
|
CGRect clipBounds = CGContextGetClipBoundingBox(context);
|
||||||
clipBounds = CGRectApplyAffineTransform(clipBounds, self.matrix);
|
|
||||||
clipBounds = CGRectApplyAffineTransform(clipBounds, self.transform);
|
clipBounds = CGRectApplyAffineTransform(clipBounds, self.transform);
|
||||||
CGFloat width = CGRectGetWidth(clipBounds);
|
CGFloat width = CGRectGetWidth(clipBounds);
|
||||||
CGFloat height = CGRectGetHeight(clipBounds);
|
CGFloat height = CGRectGetHeight(clipBounds);
|
||||||
@@ -124,7 +123,7 @@
|
|||||||
CGMutablePathRef __block path = CGPathCreateMutable();
|
CGMutablePathRef __block path = CGPathCreateMutable();
|
||||||
[self traverseSubviews:^(RNSVGNode *node) {
|
[self traverseSubviews:^(RNSVGNode *node) {
|
||||||
if ([node isKindOfClass:[RNSVGNode class]]) {
|
if ([node isKindOfClass:[RNSVGNode class]]) {
|
||||||
CGAffineTransform transform = node.matrix;
|
CGAffineTransform transform = node.transform;
|
||||||
CGPathAddPath(path, &transform, [node getPath:context]);
|
CGPathAddPath(path, &transform, [node getPath:context]);
|
||||||
}
|
}
|
||||||
return YES;
|
return YES;
|
||||||
|
|||||||
@@ -163,12 +163,16 @@
|
|||||||
self.initialCTM = CGContextGetCTM(context);
|
self.initialCTM = CGContextGetCTM(context);
|
||||||
self.invInitialCTM = CGAffineTransformInvert(self.initialCTM);
|
self.invInitialCTM = CGAffineTransformInvert(self.initialCTM);
|
||||||
if (self.align) {
|
if (self.align) {
|
||||||
_viewBoxTransform = [RNSVGViewBox getTransform:CGRectMake(self.minX, self.minY, self.vbWidth, self.vbHeight)
|
CGRect tRect = CGRectMake(self.minX, self.minY, self.vbWidth, self.vbHeight);
|
||||||
|
_viewBoxTransform = [RNSVGViewBox getTransform:tRect
|
||||||
eRect:rect
|
eRect:rect
|
||||||
align:self.align
|
align:self.align
|
||||||
meetOrSlice:self.meetOrSlice];
|
meetOrSlice:self.meetOrSlice];
|
||||||
_invviewBoxTransform = CGAffineTransformInvert(_viewBoxTransform);
|
_invviewBoxTransform = CGAffineTransformInvert(_viewBoxTransform);
|
||||||
CGContextConcatCTM(context, _viewBoxTransform);
|
CGContextConcatCTM(context, _viewBoxTransform);
|
||||||
|
} else {
|
||||||
|
_viewBoxTransform = CGAffineTransformIdentity;
|
||||||
|
_invviewBoxTransform = CGAffineTransformIdentity;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (UIView *node in self.subviews) {
|
for (UIView *node in self.subviews) {
|
||||||
|
|||||||
@@ -33,6 +33,7 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
|
|||||||
@property (nonatomic, strong) NSString *mask;
|
@property (nonatomic, strong) NSString *mask;
|
||||||
@property (nonatomic, assign) BOOL responsible;
|
@property (nonatomic, assign) BOOL responsible;
|
||||||
@property (nonatomic, assign) CGAffineTransform matrix;
|
@property (nonatomic, assign) CGAffineTransform matrix;
|
||||||
|
@property (nonatomic, assign) CGAffineTransform transforms;
|
||||||
@property (nonatomic, assign) CGAffineTransform invmatrix;
|
@property (nonatomic, assign) CGAffineTransform invmatrix;
|
||||||
@property (nonatomic, assign) CGAffineTransform invTransform;
|
@property (nonatomic, assign) CGAffineTransform invTransform;
|
||||||
@property (nonatomic, assign) BOOL active;
|
@property (nonatomic, assign) BOOL active;
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
{
|
{
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
self.opacity = 1;
|
self.opacity = 1;
|
||||||
|
self.transforms = CGAffineTransformIdentity;
|
||||||
self.invTransform = CGAffineTransformIdentity;
|
self.invTransform = CGAffineTransformIdentity;
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
@@ -165,6 +166,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
}
|
}
|
||||||
_matrix = matrix;
|
_matrix = matrix;
|
||||||
_invmatrix = CGAffineTransformInvert(matrix);
|
_invmatrix = CGAffineTransformInvert(matrix);
|
||||||
|
self.transform = CGAffineTransformConcat(matrix, self.transforms);
|
||||||
id<RNSVGContainer> container = (id<RNSVGContainer>)self.superview;
|
id<RNSVGContainer> container = (id<RNSVGContainer>)self.superview;
|
||||||
[container invalidate];
|
[container invalidate];
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-5
@@ -168,7 +168,6 @@ UInt32 saturate(CGFloat value) {
|
|||||||
{
|
{
|
||||||
// This needs to be painted on a layer before being composited.
|
// This needs to be painted on a layer before being composited.
|
||||||
CGContextSaveGState(context);
|
CGContextSaveGState(context);
|
||||||
CGContextConcatCTM(context, self.matrix);
|
|
||||||
CGContextConcatCTM(context, self.transform);
|
CGContextConcatCTM(context, self.transform);
|
||||||
CGContextSetAlpha(context, self.opacity);
|
CGContextSetAlpha(context, self.opacity);
|
||||||
|
|
||||||
@@ -297,15 +296,24 @@ UInt32 saturate(CGFloat value) {
|
|||||||
|
|
||||||
const CGRect pathBounding = CGPathGetBoundingBox(self.path);
|
const CGRect pathBounding = CGPathGetBoundingBox(self.path);
|
||||||
|
|
||||||
const CGAffineTransform matrix = self.matrix;
|
|
||||||
const CGAffineTransform current = CGContextGetCTM(context);
|
const CGAffineTransform current = CGContextGetCTM(context);
|
||||||
const CGAffineTransform svgToClientTransform = CGAffineTransformConcat(current, self.svgView.invInitialCTM);
|
const CGAffineTransform svgToClientTransform = CGAffineTransformConcat(current, self.svgView.invInitialCTM);
|
||||||
const CGRect clientRect = CGRectApplyAffineTransform(pathBounding, svgToClientTransform);
|
const CGRect clientRect = CGRectApplyAffineTransform(pathBounding, svgToClientTransform);
|
||||||
const CGSize clientSize = clientRect.size;
|
|
||||||
|
|
||||||
self.clientRect = clientRect;
|
self.clientRect = clientRect;
|
||||||
self.bounds = CGRectMake(0, 0, clientSize.width, clientSize.height);
|
|
||||||
self.frame = CGRectMake(matrix.tx, matrix.ty, clientSize.width, clientSize.height);
|
const CGAffineTransform vbmatrix = self.svgView.getViewBoxTransform;
|
||||||
|
const CGAffineTransform matrix = CGAffineTransformConcat(self.transform, vbmatrix);
|
||||||
|
|
||||||
|
const CGRect bounds = CGRectMake(0, 0, CGRectGetWidth(clientRect), CGRectGetHeight(clientRect));
|
||||||
|
const CGPoint mid = CGPointMake(CGRectGetMidX(pathBounding), CGRectGetMidY(pathBounding));
|
||||||
|
CGPoint center = CGPointApplyAffineTransform(mid, matrix);
|
||||||
|
|
||||||
|
const CGRect frame = CGRectApplyAffineTransform(pathBounding, matrix);
|
||||||
|
|
||||||
|
self.bounds = bounds;
|
||||||
|
self.center = center;
|
||||||
|
self.frame = frame;
|
||||||
|
|
||||||
CGPathDrawingMode mode = kCGPathStroke;
|
CGPathDrawingMode mode = kCGPathStroke;
|
||||||
BOOL fillColor = NO;
|
BOOL fillColor = NO;
|
||||||
|
|||||||
@@ -159,7 +159,8 @@ RCT_CUSTOM_VIEW_PROPERTY(transform, CATransform3D, RNSVGNode)
|
|||||||
CATransform3D transform3d = json ? [RNSVGNodeManager CATransform3D:json] : defaultView.layer.transform;
|
CATransform3D transform3d = json ? [RNSVGNodeManager CATransform3D:json] : defaultView.layer.transform;
|
||||||
CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d);
|
CGAffineTransform transform = CATransform3DGetAffineTransform(transform3d);
|
||||||
view.invTransform = CGAffineTransformInvert(transform);
|
view.invTransform = CGAffineTransformInvert(transform);
|
||||||
view.transform = transform;
|
view.transforms = transform;
|
||||||
|
view.transform = CGAffineTransformConcat(view.matrix, transform);
|
||||||
[view invalidate];
|
[view invalidate];
|
||||||
}
|
}
|
||||||
RCT_EXPORT_VIEW_PROPERTY(mask, NSString)
|
RCT_EXPORT_VIEW_PROPERTY(mask, NSString)
|
||||||
|
|||||||
Reference in New Issue
Block a user