Skip to content
This repository has been archived by the owner on Jun 3, 2021. It is now read-only.

[WEEX-173][iOS] iconfont redraw failed sometimes on iOS #997

Merged
merged 1 commit into from
Jan 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 10 additions & 12 deletions ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ @implementation WXTextComponent

pthread_mutex_t _ctAttributedStringMutex;
pthread_mutexattr_t _propertMutexAttr;
BOOL _observerIconfont;
}

+ (void)setRenderUsingCoreText:(BOOL)usingCoreText
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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]),
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion ios/sdk/WeexSDK/Sources/Manager/WXRuleManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down