mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-07 00:42:31 +00:00
Fix retain cycle for nested views.
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
- (void)parseReference
|
- (void)parseReference
|
||||||
{
|
{
|
||||||
[[self getSvgView] defineClipPath:self clipPathName:self.name];
|
[self.svgView defineClipPath:self clipPathName:self.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -33,10 +33,10 @@
|
|||||||
- (void)renderGroupTo:(CGContextRef)context
|
- (void)renderGroupTo:(CGContextRef)context
|
||||||
{
|
{
|
||||||
[self pushGlyphContext];
|
[self pushGlyphContext];
|
||||||
RNSVGSvgView* svg = [self getSvgView];
|
|
||||||
[self traverseSubviews:^(RNSVGNode *node) {
|
[self traverseSubviews:^(RNSVGNode *node) {
|
||||||
if (node.responsible && !svg.responsible) {
|
if (node.responsible && !self.svgView.responsible) {
|
||||||
svg.responsible = YES;
|
self.svgView.responsible = YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
if ([node isKindOfClass:[RNSVGRenderable class]]) {
|
||||||
@@ -142,8 +142,8 @@
|
|||||||
- (void)parseReference
|
- (void)parseReference
|
||||||
{
|
{
|
||||||
if (self.name) {
|
if (self.name) {
|
||||||
RNSVGSvgView* svg = [self getSvgView];
|
typeof(self) __weak weakSelf = self;
|
||||||
[svg defineTemplate:self templateName:self.name];
|
[self.svgView defineTemplate:weakSelf templateName:self.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self traverseSubviews:^(__kindof RNSVGNode *node) {
|
[self traverseSubviews:^(__kindof RNSVGNode *node) {
|
||||||
|
|||||||
@@ -34,12 +34,11 @@
|
|||||||
[painter setTransform:self.gradientTransform];
|
[painter setTransform:self.gradientTransform];
|
||||||
[painter setLinearGradientColors:self.gradient];
|
[painter setLinearGradientColors:self.gradient];
|
||||||
|
|
||||||
RNSVGSvgView *svg = [self getSvgView];
|
|
||||||
if (self.gradientUnits == kRNSVGUnitsUserSpaceOnUse) {
|
if (self.gradientUnits == kRNSVGUnitsUserSpaceOnUse) {
|
||||||
[painter setUserSpaceBoundingBox:[svg getContextBounds]];
|
[painter setUserSpaceBoundingBox:[self.svgView getContextBounds]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[svg definePainter:painter painterName:self.name];
|
[self.svgView definePainter:painter painterName:self.name];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|||||||
@@ -32,12 +32,11 @@
|
|||||||
[painter setTransform:self.gradientTransform];
|
[painter setTransform:self.gradientTransform];
|
||||||
[painter setRadialGradientColors:self.gradient];
|
[painter setRadialGradientColors:self.gradient];
|
||||||
|
|
||||||
RNSVGSvgView *svg = [self getSvgView];
|
|
||||||
if (self.gradientUnits == kRNSVGUnitsUserSpaceOnUse) {
|
if (self.gradientUnits == kRNSVGUnitsUserSpaceOnUse) {
|
||||||
[painter setUserSpaceBoundingBox:[svg getContextBounds]];
|
[painter setUserSpaceBoundingBox:[self.svgView getContextBounds]];
|
||||||
}
|
}
|
||||||
|
|
||||||
[svg definePainter:painter painterName:self.name];
|
[self.svgView definePainter:painter painterName:self.name];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
|
|
||||||
- (void)renderLayerTo:(CGContextRef)context
|
- (void)renderLayerTo:(CGContextRef)context
|
||||||
{
|
{
|
||||||
RNSVGNode* template = [[self getSvgView] getDefinedTemplate:self.href];
|
RNSVGNode* template = [self.svgView getDefinedTemplate:self.href];
|
||||||
if (template) {
|
if (template) {
|
||||||
[self beginTransparencyLayer:context];
|
[self beginTransparencyLayer:context];
|
||||||
[self clip:context];
|
[self clip:context];
|
||||||
|
|||||||
+5
-5
@@ -34,6 +34,11 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
|
|||||||
@property (nonatomic, assign) CGAffineTransform matrix;
|
@property (nonatomic, assign) CGAffineTransform matrix;
|
||||||
@property (nonatomic, assign) BOOL active;
|
@property (nonatomic, assign) BOOL active;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* RNSVGSvgView which ownes current RNSVGNode
|
||||||
|
*/
|
||||||
|
@property (nonatomic, readonly, weak) RNSVGSvgView *svgView;
|
||||||
|
|
||||||
- (void)invalidate;
|
- (void)invalidate;
|
||||||
|
|
||||||
- (RNSVGGroup *)getTextRoot;
|
- (RNSVGGroup *)getTextRoot;
|
||||||
@@ -73,11 +78,6 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
|
|||||||
*/
|
*/
|
||||||
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event withTransform:(CGAffineTransform)transfrom;
|
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event withTransform:(CGAffineTransform)transfrom;
|
||||||
|
|
||||||
/**
|
|
||||||
* get RNSVGSvgView which ownes current RNSVGNode
|
|
||||||
*/
|
|
||||||
- (RNSVGSvgView *)getSvgView;
|
|
||||||
|
|
||||||
- (CGFloat)relativeOnWidth:(NSString *)length;
|
- (CGFloat)relativeOnWidth:(NSString *)length;
|
||||||
|
|
||||||
- (CGFloat)relativeOnHeight:(NSString *)length;
|
- (CGFloat)relativeOnHeight:(NSString *)length;
|
||||||
|
|||||||
+13
-11
@@ -12,13 +12,16 @@
|
|||||||
#import "RNSVGGroup.h"
|
#import "RNSVGGroup.h"
|
||||||
#import "RNSVGGlyphContext.h"
|
#import "RNSVGGlyphContext.h"
|
||||||
|
|
||||||
|
@interface RNSVGNode()
|
||||||
|
@property (nonatomic, readwrite, weak) RNSVGSvgView *svgView;
|
||||||
|
@end
|
||||||
|
|
||||||
@implementation RNSVGNode
|
@implementation RNSVGNode
|
||||||
{
|
{
|
||||||
RNSVGGroup *_textRoot;
|
RNSVGGroup *_textRoot;
|
||||||
RNSVGGlyphContext *glyphContext;
|
RNSVGGlyphContext *glyphContext;
|
||||||
BOOL _transparent;
|
BOOL _transparent;
|
||||||
CGPathRef _cachedClipPath;
|
CGPathRef _cachedClipPath;
|
||||||
RNSVGSvgView *_svgView;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CGFloat const RNSVG_M_SQRT1_2l = 0.707106781186547524400844362104849039;
|
CGFloat const RNSVG_M_SQRT1_2l = 0.707106781186547524400844362104849039;
|
||||||
@@ -173,7 +176,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
{
|
{
|
||||||
if (self.clipPath) {
|
if (self.clipPath) {
|
||||||
CGPathRelease(_cachedClipPath);
|
CGPathRelease(_cachedClipPath);
|
||||||
_cachedClipPath = CGPathRetain([[[self getSvgView] getDefinedClipPath:self.clipPath] getPath:context]);
|
_cachedClipPath = CGPathRetain([[self.svgView getDefinedClipPath:self.clipPath] getPath:context]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [self getClipPath];
|
return [self getClipPath];
|
||||||
@@ -218,7 +221,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RNSVGSvgView *)getSvgView
|
- (RNSVGSvgView *)svgView
|
||||||
{
|
{
|
||||||
if (_svgView) {
|
if (_svgView) {
|
||||||
return _svgView;
|
return _svgView;
|
||||||
@@ -229,8 +232,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
if ([parent class] == [RNSVGSvgView class]) {
|
if ([parent class] == [RNSVGSvgView class]) {
|
||||||
_svgView = parent;
|
_svgView = parent;
|
||||||
} else if ([parent isKindOfClass:[RNSVGNode class]]) {
|
} else if ([parent isKindOfClass:[RNSVGNode class]]) {
|
||||||
RNSVGNode *node = parent;
|
_svgView = ((RNSVGNode *)parent).svgView;
|
||||||
_svgView = [node getSvgView];
|
|
||||||
} else {
|
} else {
|
||||||
RCTLogError(@"RNSVG: %@ should be descendant of a SvgViewShadow.", NSStringFromClass(self.class));
|
RCTLogError(@"RNSVG: %@ should be descendant of a SvgViewShadow.", NSStringFromClass(self.class));
|
||||||
}
|
}
|
||||||
@@ -275,7 +277,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
RNSVGGroup * root = [self getTextRoot];
|
RNSVGGroup * root = [self getTextRoot];
|
||||||
RNSVGGlyphContext * gc = [root getGlyphContext];
|
RNSVGGlyphContext * gc = [root getGlyphContext];
|
||||||
if (root == nil || gc == nil) {
|
if (root == nil || gc == nil) {
|
||||||
return CGRectGetWidth([[self getSvgView] getContextBounds]);
|
return CGRectGetWidth([self.svgView getContextBounds]);
|
||||||
} else {
|
} else {
|
||||||
return [gc getWidth];
|
return [gc getWidth];
|
||||||
}
|
}
|
||||||
@@ -286,7 +288,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
RNSVGGroup * root = [self getTextRoot];
|
RNSVGGroup * root = [self getTextRoot];
|
||||||
RNSVGGlyphContext * gc = [root getGlyphContext];
|
RNSVGGlyphContext * gc = [root getGlyphContext];
|
||||||
if (root == nil || gc == nil) {
|
if (root == nil || gc == nil) {
|
||||||
return CGRectGetHeight([[self getSvgView] getContextBounds]);
|
return CGRectGetHeight([self.svgView getContextBounds]);
|
||||||
} else {
|
} else {
|
||||||
return [gc getHeight];
|
return [gc getHeight];
|
||||||
}
|
}
|
||||||
@@ -294,19 +296,19 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
|
|
||||||
- (CGFloat)getContextLeft
|
- (CGFloat)getContextLeft
|
||||||
{
|
{
|
||||||
return CGRectGetMinX([[self getSvgView] getContextBounds]);
|
return CGRectGetMinX([self.svgView getContextBounds]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGFloat)getContextTop
|
- (CGFloat)getContextTop
|
||||||
{
|
{
|
||||||
return CGRectGetMinY([[self getSvgView] getContextBounds]);
|
return CGRectGetMinY([self.svgView getContextBounds]);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)parseReference
|
- (void)parseReference
|
||||||
{
|
{
|
||||||
if (self.name) {
|
if (self.name) {
|
||||||
RNSVGSvgView* svg = [self getSvgView];
|
typeof(self) __weak weakSelf = self;
|
||||||
[svg defineTemplate:self templateName:self.name];
|
[self.svgView defineTemplate:weakSelf templateName:self.name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -202,7 +202,7 @@
|
|||||||
CGContextClip(context);
|
CGContextClip(context);
|
||||||
[self.fill paint:context
|
[self.fill paint:context
|
||||||
opacity:self.fillOpacity
|
opacity:self.fillOpacity
|
||||||
painter:[[self getSvgView] getDefinedPainter:self.fill.brushRef]
|
painter:[self.svgView getDefinedPainter:self.fill.brushRef]
|
||||||
];
|
];
|
||||||
CGContextRestoreGState(context);
|
CGContextRestoreGState(context);
|
||||||
|
|
||||||
@@ -247,7 +247,7 @@
|
|||||||
|
|
||||||
[self.stroke paint:context
|
[self.stroke paint:context
|
||||||
opacity:self.strokeOpacity
|
opacity:self.strokeOpacity
|
||||||
painter:[[self getSvgView] getDefinedPainter:self.stroke.brushRef]
|
painter:[self.svgView getDefinedPainter:self.stroke.brushRef]
|
||||||
];
|
];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,8 +114,7 @@ void RNSVGPerformanceBezier_addLine(CGPoint *last, const CGPoint *next, NSMutabl
|
|||||||
|
|
||||||
- (void)getPathLength:(CGFloat*)lengthP lineCount:(NSUInteger*)lineCountP lengths:(NSArray* __strong *)lengthsP lines:(NSArray* __strong *)linesP isClosed:(BOOL*)isClosedP
|
- (void)getPathLength:(CGFloat*)lengthP lineCount:(NSUInteger*)lineCountP lengths:(NSArray* __strong *)lengthsP lines:(NSArray* __strong *)linesP isClosed:(BOOL*)isClosedP
|
||||||
{
|
{
|
||||||
RNSVGSvgView *svg = [self getSvgView];
|
RNSVGNode *template = [self.svgView getDefinedTemplate:self.href];
|
||||||
RNSVGNode *template = [svg getDefinedTemplate:self.href];
|
|
||||||
CGPathRef path = [template getPath:nil];
|
CGPathRef path = [template getPath:nil];
|
||||||
|
|
||||||
if (_path != path) {
|
if (_path != path) {
|
||||||
|
|||||||
Reference in New Issue
Block a user