mirror of
https://github.com/status-im/react-native.git
synced 2025-02-26 16:10:58 +00:00
[React Native] Fix RCTText crashes
This commit is contained in:
parent
17ab4f2fb3
commit
fcc87916d2
@ -38,34 +38,53 @@
|
|||||||
|
|
||||||
- (void)setAttributedText:(NSAttributedString *)attributedText
|
- (void)setAttributedText:(NSAttributedString *)attributedText
|
||||||
{
|
{
|
||||||
[_textStorage setAttributedString:attributedText];
|
for (NSLayoutManager *existingLayoutManager in _textStorage.layoutManagers) {
|
||||||
|
[_textStorage removeLayoutManager:existingLayoutManager];
|
||||||
|
}
|
||||||
|
|
||||||
|
_textStorage = [[NSTextStorage alloc] initWithAttributedString:attributedText];
|
||||||
|
|
||||||
|
if (_layoutManager) {
|
||||||
|
[_textStorage addLayoutManager:_layoutManager];
|
||||||
|
}
|
||||||
|
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setTextContainer:(NSTextContainer *)textContainer
|
- (void)setTextContainer:(NSTextContainer *)textContainer
|
||||||
{
|
{
|
||||||
if ([_textContainer isEqual:textContainer]) return;
|
if ([_textContainer isEqual:textContainer]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_textContainer = textContainer;
|
_textContainer = textContainer;
|
||||||
|
|
||||||
for (NSInteger i = _layoutManager.textContainers.count - 1; i >= 0; i--) {
|
for (NSInteger i = _layoutManager.textContainers.count - 1; i >= 0; i--) {
|
||||||
[_layoutManager removeTextContainerAtIndex:i];
|
[_layoutManager removeTextContainerAtIndex:i];
|
||||||
}
|
}
|
||||||
[_layoutManager addTextContainer:_textContainer];
|
|
||||||
|
if (_textContainer) {
|
||||||
|
[_layoutManager addTextContainer:_textContainer];
|
||||||
|
}
|
||||||
|
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setLayoutManager:(NSLayoutManager *)layoutManager
|
- (void)setLayoutManager:(NSLayoutManager *)layoutManager
|
||||||
{
|
{
|
||||||
if ([_layoutManager isEqual:layoutManager]) return;
|
if ([_layoutManager isEqual:layoutManager]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
_layoutManager = layoutManager;
|
_layoutManager = layoutManager;
|
||||||
|
|
||||||
for (NSLayoutManager *existingLayoutManager in _textStorage.layoutManagers) {
|
for (NSLayoutManager *existingLayoutManager in _textStorage.layoutManagers) {
|
||||||
[_textStorage removeLayoutManager:existingLayoutManager];
|
[_textStorage removeLayoutManager:existingLayoutManager];
|
||||||
}
|
}
|
||||||
[_textStorage addLayoutManager:_layoutManager];
|
|
||||||
|
if (_layoutManager) {
|
||||||
|
[_textStorage addLayoutManager:_layoutManager];
|
||||||
|
}
|
||||||
|
|
||||||
[self setNeedsDisplay];
|
[self setNeedsDisplay];
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user