mirror of
https://github.com/zoriya/react-native-svg.git
synced 2026-06-08 09:10:44 +00:00
Fix retain cycle for the textRoot property.
This commit is contained in:
@@ -72,12 +72,13 @@
|
|||||||
|
|
||||||
- (void)pushGlyphContext
|
- (void)pushGlyphContext
|
||||||
{
|
{
|
||||||
[[[self getTextRoot] getGlyphContext] pushContext:self font:self.font];
|
__weak typeof(self) weakSelf = self;
|
||||||
|
[[self.textRoot getGlyphContext] pushContext:weakSelf font:self.font];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)popGlyphContext
|
- (void)popGlyphContext
|
||||||
{
|
{
|
||||||
[[[self getTextRoot] getGlyphContext] popContext];
|
[[self.textRoot getGlyphContext] popContext];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)renderPathTo:(CGContextRef)context
|
- (void)renderPathTo:(CGContextRef)context
|
||||||
|
|||||||
+1
-1
@@ -38,10 +38,10 @@ extern CGFloat const RNSVG_DEFAULT_FONT_SIZE;
|
|||||||
* RNSVGSvgView which ownes current RNSVGNode
|
* RNSVGSvgView which ownes current RNSVGNode
|
||||||
*/
|
*/
|
||||||
@property (nonatomic, readonly, weak) RNSVGSvgView *svgView;
|
@property (nonatomic, readonly, weak) RNSVGSvgView *svgView;
|
||||||
|
@property (nonatomic, readonly, weak) RNSVGGroup *textRoot;
|
||||||
|
|
||||||
- (void)invalidate;
|
- (void)invalidate;
|
||||||
|
|
||||||
- (RNSVGGroup *)getTextRoot;
|
|
||||||
- (RNSVGGroup *)getParentTextRoot;
|
- (RNSVGGroup *)getParentTextRoot;
|
||||||
|
|
||||||
- (void)renderTo:(CGContextRef)context;
|
- (void)renderTo:(CGContextRef)context;
|
||||||
|
|||||||
+22
-20
@@ -14,11 +14,11 @@
|
|||||||
|
|
||||||
@interface RNSVGNode()
|
@interface RNSVGNode()
|
||||||
@property (nonatomic, readwrite, weak) RNSVGSvgView *svgView;
|
@property (nonatomic, readwrite, weak) RNSVGSvgView *svgView;
|
||||||
|
@property (nonatomic, readwrite, weak) RNSVGGroup *textRoot;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation RNSVGNode
|
@implementation RNSVGNode
|
||||||
{
|
{
|
||||||
RNSVGGroup *_textRoot;
|
|
||||||
RNSVGGlyphContext *glyphContext;
|
RNSVGGlyphContext *glyphContext;
|
||||||
BOOL _transparent;
|
BOOL _transparent;
|
||||||
CGPathRef _cachedClipPath;
|
CGPathRef _cachedClipPath;
|
||||||
@@ -59,23 +59,25 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
[container invalidate];
|
[container invalidate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RNSVGGroup *)getTextRoot
|
- (RNSVGGroup *)textRoot
|
||||||
{
|
{
|
||||||
|
if (_textRoot) {
|
||||||
|
return _textRoot;
|
||||||
|
}
|
||||||
|
|
||||||
RNSVGNode* node = self;
|
RNSVGNode* node = self;
|
||||||
if (_textRoot == nil) {
|
while (node != nil) {
|
||||||
while (node != nil) {
|
if ([node isKindOfClass:[RNSVGGroup class]] && [((RNSVGGroup*) node) getGlyphContext] != nil) {
|
||||||
if ([node isKindOfClass:[RNSVGGroup class]] && [((RNSVGGroup*) node) getGlyphContext] != nil) {
|
_textRoot = (RNSVGGroup*)node;
|
||||||
_textRoot = (RNSVGGroup*)node;
|
break;
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
|
UIView* parent = [node superview];
|
||||||
UIView* parent = [node superview];
|
|
||||||
|
if (![node isKindOfClass:[RNSVGNode class]]) {
|
||||||
if (![node isKindOfClass:[RNSVGNode class]]) {
|
node = nil;
|
||||||
node = nil;
|
} else {
|
||||||
} else {
|
node = (RNSVGNode*)parent;
|
||||||
node = (RNSVGNode*)parent;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,13 +90,13 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
if (![parent isKindOfClass:[RNSVGGroup class]]) {
|
if (![parent isKindOfClass:[RNSVGGroup class]]) {
|
||||||
return nil;
|
return nil;
|
||||||
} else {
|
} else {
|
||||||
return [parent getTextRoot];
|
return parent.textRoot;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CGFloat)getFontSizeFromContext
|
- (CGFloat)getFontSizeFromContext
|
||||||
{
|
{
|
||||||
RNSVGGroup* root = [self getTextRoot];
|
RNSVGGroup* root = self.textRoot;
|
||||||
if (root == nil) {
|
if (root == nil) {
|
||||||
return RNSVG_DEFAULT_FONT_SIZE;
|
return RNSVG_DEFAULT_FONT_SIZE;
|
||||||
}
|
}
|
||||||
@@ -274,7 +276,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
|
|
||||||
- (CGFloat)getContextWidth
|
- (CGFloat)getContextWidth
|
||||||
{
|
{
|
||||||
RNSVGGroup * root = [self getTextRoot];
|
RNSVGGroup * root = self.textRoot;
|
||||||
RNSVGGlyphContext * gc = [root getGlyphContext];
|
RNSVGGlyphContext * gc = [root getGlyphContext];
|
||||||
if (root == nil || gc == nil) {
|
if (root == nil || gc == nil) {
|
||||||
return CGRectGetWidth([self.svgView getContextBounds]);
|
return CGRectGetWidth([self.svgView getContextBounds]);
|
||||||
@@ -285,7 +287,7 @@ CGFloat const RNSVG_DEFAULT_FONT_SIZE = 12;
|
|||||||
|
|
||||||
- (CGFloat)getContextHeight
|
- (CGFloat)getContextHeight
|
||||||
{
|
{
|
||||||
RNSVGGroup * root = [self getTextRoot];
|
RNSVGGroup * root = self.textRoot;
|
||||||
RNSVGGlyphContext * gc = [root getGlyphContext];
|
RNSVGGlyphContext * gc = [root getGlyphContext];
|
||||||
if (root == nil || gc == nil) {
|
if (root == nil || gc == nil) {
|
||||||
return CGRectGetHeight([self.svgView getContextBounds]);
|
return CGRectGetHeight([self.svgView getContextBounds]);
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ static double RNSVGTSpan_radToDeg = 180 / M_PI;
|
|||||||
// Create a dictionary for this font
|
// Create a dictionary for this font
|
||||||
CTFontRef fontRef = [self getFontFromContext];
|
CTFontRef fontRef = [self getFontFromContext];
|
||||||
CGMutablePathRef path = CGPathCreateMutable();
|
CGMutablePathRef path = CGPathCreateMutable();
|
||||||
RNSVGGlyphContext* gc = [[self getTextRoot] getGlyphContext];
|
RNSVGGlyphContext* gc = [self.textRoot getGlyphContext];
|
||||||
RNSVGFontData* font = [gc getFont];
|
RNSVGFontData* font = [gc getFont];
|
||||||
NSUInteger n = str.length;
|
NSUInteger n = str.length;
|
||||||
/*
|
/*
|
||||||
|
|||||||
+18
-20
@@ -15,7 +15,6 @@
|
|||||||
|
|
||||||
@implementation RNSVGText
|
@implementation RNSVGText
|
||||||
{
|
{
|
||||||
RNSVGText *_textRoot;
|
|
||||||
RNSVGGlyphContext *_glyphContext;
|
RNSVGGlyphContext *_glyphContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,20 +75,19 @@
|
|||||||
[self popGlyphContext];
|
[self popGlyphContext];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (RNSVGText *)getTextRoot
|
// TODO: Optimisation required
|
||||||
|
- (RNSVGText *)textRoot
|
||||||
{
|
{
|
||||||
if (!_textRoot) {
|
RNSVGText *root = self;
|
||||||
_textRoot = self;
|
while (root && [root class] != [RNSVGText class]) {
|
||||||
while (_textRoot && [_textRoot class] != [RNSVGText class]) {
|
if (![root isKindOfClass:[RNSVGText class]]) {
|
||||||
if (![_textRoot isKindOfClass:[RNSVGText class]]) {
|
//todo: throw exception here
|
||||||
//todo: throw exception here
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
_textRoot = (RNSVGText*)[_textRoot superview];
|
|
||||||
}
|
}
|
||||||
|
root = (RNSVGText*)[root superview];
|
||||||
}
|
}
|
||||||
|
|
||||||
return _textRoot;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*) getAlignmentBaseline
|
- (NSString*) getAlignmentBaseline
|
||||||
@@ -147,23 +145,23 @@
|
|||||||
|
|
||||||
- (void)pushGlyphContext
|
- (void)pushGlyphContext
|
||||||
{
|
{
|
||||||
[[[self getTextRoot] getGlyphContext] pushContext:self
|
[[self.textRoot getGlyphContext] pushContext:self
|
||||||
font:self.font
|
font:self.font
|
||||||
x:self.positionX
|
x:self.positionX
|
||||||
y:self.positionY
|
y:self.positionY
|
||||||
deltaX:self.deltaX
|
deltaX:self.deltaX
|
||||||
deltaY:self.deltaY
|
deltaY:self.deltaY
|
||||||
rotate:self.rotate];
|
rotate:self.rotate];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)popGlyphContext
|
- (void)popGlyphContext
|
||||||
{
|
{
|
||||||
[[[self getTextRoot] getGlyphContext] popContext];
|
[[self.textRoot getGlyphContext] popContext];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (CTFontRef)getFontFromContext
|
- (CTFontRef)getFontFromContext
|
||||||
{
|
{
|
||||||
return [[[self getTextRoot] getGlyphContext] getGlyphFont];
|
return [[self.textRoot getGlyphContext] getGlyphFont];
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
Reference in New Issue
Block a user