Skip to content

Commit 8e18f15

Browse files
yxztjAdlai Holler
authored andcommitted
[TextKit] Fix text layout issue for CJK laungages (facebookarchive#3026)
* [TextKit] Fix text layout issue for CJK laungages * [ASTextKitContext] Delay filling _textStorage with attributedString until calling addLayoutManager.
1 parent a6e7490 commit 8e18f15

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

AsyncDisplayKit/TextKit/ASTextKitContext.mm

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,18 @@ - (instancetype)initWithAttributedString:(NSAttributedString *)attributedString
3939
__instanceLock__ = std::make_shared<ASDN::Mutex>();
4040

4141
// Create the TextKit component stack with our default configuration.
42-
_textStorage = (attributedString ? [[NSTextStorage alloc] initWithAttributedString:attributedString] : [[NSTextStorage alloc] init]);
42+
43+
_textStorage = [[NSTextStorage alloc] init];
4344
_layoutManager = [[ASLayoutManager alloc] init];
4445
_layoutManager.usesFontLeading = NO;
4546
[_textStorage addLayoutManager:_layoutManager];
47+
48+
// Instead of calling [NSTextStorage initWithAttributedString:], setting attributedString just after calling addlayoutManager can fix CJK language layout issues.
49+
// See https://github.com/facebook/AsyncDisplayKit/issues/2894
50+
if (attributedString) {
51+
[_textStorage setAttributedString:attributedString];
52+
}
53+
4654
_textContainer = [[NSTextContainer alloc] initWithSize:constrainedSize];
4755
// We want the text laid out up to the very edges of the container.
4856
_textContainer.lineFragmentPadding = 0;

0 commit comments

Comments
 (0)