From ce4b6bf005f74c8d4e43d2b86cc446061d90b109 Mon Sep 17 00:00:00 2001 From: acton393 Date: Mon, 22 Jan 2018 22:01:53 +0800 Subject: [PATCH] [WEEX-173][iOS] iconfont redraw failed sometimes on iOS --- .../Sources/Component/WXTextComponent.m | 22 +++++++++---------- .../WeexSDK/Sources/Manager/WXRuleManager.m | 2 +- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m index 5cdfd3d52f..65f7ae3079 100644 --- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m +++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m @@ -131,6 +131,7 @@ @implementation WXTextComponent pthread_mutex_t _ctAttributedStringMutex; pthread_mutexattr_t _propertMutexAttr; + BOOL _observerIconfont; } + (void)setRenderUsingCoreText:(BOOL)usingCoreText @@ -187,7 +188,7 @@ - (BOOL)useCoreText - (void)dealloc { - if (_fontFamily) { + if (_fontFamily && _observerIconfont) { [[NSNotificationCenter defaultCenter] removeObserver:self name:WX_ICONFONT_DOWNLOAD_NOTIFICATION object:nil]; } pthread_mutex_destroy(&_ctAttributedStringMutex); @@ -250,7 +251,11 @@ - (void)fillCSSStyles:(NSDictionary *)styles WX_STYLE_FILL_TEXT_PIXEL(letterSpacing, letterSpacing, YES) WX_STYLE_FILL_TEXT(wordWrap, wordWrap, NSString, YES); WX_STYLE_FILL_TEXT(direction, direction, NSString, YES) - + if (_fontFamily && !_observerIconfont) { + // notification received when custom icon font file download finish + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repaintText:) name:WX_ICONFONT_DOWNLOAD_NOTIFICATION object:nil]; + _observerIconfont = YES; + } UIEdgeInsets padding = { WXFloorPixelValue(self.cssNode->style.padding[CSS_TOP] + self.cssNode->style.border[CSS_TOP]), WXFloorPixelValue(self.cssNode->style.padding[CSS_LEFT] + self.cssNode->style.border[CSS_LEFT]), @@ -381,6 +386,9 @@ - (NSAttributedString *)ctAttributedString pthread_mutex_lock(&(_ctAttributedStringMutex)); if (!_ctAttributedString) { _ctAttributedString = [self buildCTAttributeString]; + WXPerformBlockOnComponentThread(^{ + [self.weexInstance.componentManager startComponentTasks]; + }); } attributedString = [_ctAttributedString copy]; pthread_mutex_unlock(&(_ctAttributedStringMutex)); @@ -414,11 +422,6 @@ - (NSMutableAttributedString *)buildCTAttributeString [attributedString addAttribute:NSForegroundColorAttributeName value:_color range:NSMakeRange(0, string.length)]; } - if (_fontFamily) { - // notification received when custom icon font file download finish - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repaintText:) name:WX_ICONFONT_DOWNLOAD_NOTIFICATION object:nil]; - } - // set font UIFont *font = [WXUtility fontWithSize:_fontSize textWeight:_fontWeight textStyle:_fontStyle fontFamily:_fontFamily scaleFactor:self.weexInstance.pixelScaleFactor useCoreText:[self useCoreText]]; CTFontRef ctFont = CTFontCreateWithName((__bridge CFStringRef)font.fontName, @@ -505,11 +508,6 @@ - (NSAttributedString *)buildAttributeString [attributedString addAttribute:NSForegroundColorAttributeName value:_color range:NSMakeRange(0, string.length)]; } - if (_fontFamily) { - // notification received when custom icon font file download finish - [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(repaintText:) name:WX_ICONFONT_DOWNLOAD_NOTIFICATION object:nil]; - } - // set font UIFont *font = [WXUtility fontWithSize:_fontSize textWeight:_fontWeight textStyle:_fontStyle fontFamily:_fontFamily scaleFactor:self.weexInstance.pixelScaleFactor]; if (font) { diff --git a/ios/sdk/WeexSDK/Sources/Manager/WXRuleManager.m b/ios/sdk/WeexSDK/Sources/Manager/WXRuleManager.m index dc1220742b..5125194152 100644 --- a/ios/sdk/WeexSDK/Sources/Manager/WXRuleManager.m +++ b/ios/sdk/WeexSDK/Sources/Manager/WXRuleManager.m @@ -84,7 +84,7 @@ - (void)addRule:(NSString*)type rule:(NSDictionary *)rule fontSrc = newURL; NSMutableDictionary * fontFamily = [self.fontStorage objectForKey:rule[@"fontFamily"]]; - if (fontFamily && [fontFamily[@"src"] isEqualToString:fontSrc]) { + if (fontFamily && [fontFamily[@"tempSrc"] isEqualToString:fontSrc]) { // if the new src is same as src in dictionary , ignore it, or update it return; }