You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by ac...@apache.org on 2017/12/21 10:07:14 UTC
incubator-weex git commit: [WEEX-121][iOS] try to fix iOS text crash
Repository: incubator-weex
Updated Branches:
refs/heads/master 6ed0074be -> a45d51b12
[WEEX-121][iOS] try to fix iOS text crash
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/a45d51b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/a45d51b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/a45d51b1
Branch: refs/heads/master
Commit: a45d51b122ab233fc6bbc6f2ccce691fee464934
Parents: 6ed0074
Author: acton393 <zh...@gmail.com>
Authored: Thu Dec 21 18:06:49 2017 +0800
Committer: acton393 <zh...@gmail.com>
Committed: Thu Dec 21 18:06:49 2017 +0800
----------------------------------------------------------------------
.../WeexSDK/Sources/Component/WXTextComponent.h | 1 +
.../WeexSDK/Sources/Component/WXTextComponent.m | 28 ++++++--------------
2 files changed, 9 insertions(+), 20 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a45d51b1/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
index e993366..1d98066 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.h
@@ -20,6 +20,7 @@
#import "WXComponent.h"
@interface WXTextComponent : WXComponent
+@property (atomic, strong) NSString *text;
+ (void)setRenderUsingCoreText:(BOOL)usingCoreText;
- (BOOL)useCoreText;
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/a45d51b1/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
----------------------------------------------------------------------
diff --git a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
index 13ae1ba..3bcf46f 100644
--- a/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
+++ b/ios/sdk/WeexSDK/Sources/Component/WXTextComponent.m
@@ -67,7 +67,7 @@
NSRange semicolonRange = [superDescription rangeOfString:@";"];
NSString * content = _textStorage.string;
if ([(WXTextComponent*)self.wx_component useCoreText]) {
- content = [(WXTextComponent*)self.wx_component valueForKey:@"_text"];
+ content = ((WXTextComponent*)self.wx_component).text;
}
NSString *replacement = [NSString stringWithFormat:@"; text: %@; frame:%f,%f,%f,%f", content, self.frame.origin.x, self.frame.origin.y, self.frame.size.width, self.frame.size.height];
return [superDescription stringByReplacingCharactersInRange:semicolonRange withString:replacement];
@@ -81,7 +81,7 @@
if (![(WXTextComponent*)self.wx_component useCoreText]) {
return _textStorage.string;
}
- return [(WXTextComponent*)self.wx_component valueForKey:@"_text"];
+ return ((WXTextComponent*)self.wx_component).text;
}
- (NSString *)accessibilityLabel
@@ -112,7 +112,6 @@ CGFloat WXTextDefaultLineThroughWidth = 1.2;
NSTextStorage *_textStorage;
CGFloat _textStorageWidth;
- NSString *_text;
UIColor *_color;
NSString *_fontFamily;
CGFloat _fontSize;
@@ -250,9 +249,9 @@ do {\
- (void)fillAttributes:(NSDictionary *)attributes
{
- id text = attributes[@"value"];
- if (text && ![[self text] isEqualToString:text]) {
- [self setText:[WXConvert NSString:text]];
+ id text = [WXConvert NSString:attributes[@"value"]];
+ if (text && ![self.text isEqualToString:text]) {
+ self.text = text;
[self setNeedsRepaint];
[self setNeedsLayout];
}
@@ -359,17 +358,6 @@ do {\
#pragma mark Text Building
-- (NSString *)text
-{
- return _text;
-}
-- (void)setText:(NSString*)text
-{
- pthread_mutex_lock(&(_ctAttributedStringMutex));
- _text = text;
- pthread_mutex_unlock(&(_ctAttributedStringMutex));
-}
-
- (NSAttributedString *)ctAttributedString
{
NSAttributedString * attributedString = nil;
@@ -399,9 +387,9 @@ do {\
- (NSMutableAttributedString *)buildCTAttributeString
{
- NSString * string = [self text];
+ NSString * string = self.text;
if (![string isKindOfClass:[NSString class]]) {
- WXLogError(@"text %@ is invalid", [self text]);
+ WXLogError(@"text %@ is invalid", self.text);
string = @"";
}
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString: string];
@@ -491,7 +479,7 @@ do {\
- (NSAttributedString *)buildAttributeString
{
- NSString *string = [self text] ?: @"";
+ NSString *string = self.text ?: @"";
NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:string];