mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-26 05:15:49 +08:00
[React Native] #WIP Modify RCTShadowText measure function to honor maxNumberOfLines property
This commit is contained in:
@@ -23,15 +23,7 @@
|
||||
- (instancetype)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if ((self = [super initWithFrame:frame])) {
|
||||
_textContainer = [[NSTextContainer alloc] init];
|
||||
_textContainer.lineBreakMode = NSLineBreakByTruncatingTail;
|
||||
_textContainer.lineFragmentPadding = 0.0;
|
||||
|
||||
_layoutManager = [[NSLayoutManager alloc] init];
|
||||
[_layoutManager addTextContainer:_textContainer];
|
||||
|
||||
_textStorage = [[NSTextStorage alloc] init];
|
||||
[_textStorage addLayoutManager:_layoutManager];
|
||||
|
||||
self.contentMode = UIViewContentModeRedraw;
|
||||
}
|
||||
@@ -50,25 +42,31 @@
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (NSUInteger)numberOfLines
|
||||
- (void)setTextContainer:(NSTextContainer *)textContainer
|
||||
{
|
||||
return _textContainer.maximumNumberOfLines;
|
||||
}
|
||||
if ([_textContainer isEqual:textContainer]) return;
|
||||
|
||||
_textContainer = textContainer;
|
||||
|
||||
for (NSInteger i = _layoutManager.textContainers.count - 1; i >= 0; i--) {
|
||||
[_layoutManager removeTextContainerAtIndex:i];
|
||||
}
|
||||
[_layoutManager addTextContainer:_textContainer];
|
||||
|
||||
- (void)setNumberOfLines:(NSUInteger)numberOfLines
|
||||
{
|
||||
_textContainer.maximumNumberOfLines = numberOfLines;
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
- (NSLineBreakMode)lineBreakMode
|
||||
- (void)setLayoutManager:(NSLayoutManager *)layoutManager
|
||||
{
|
||||
return _textContainer.lineBreakMode;
|
||||
}
|
||||
if ([_layoutManager isEqual:layoutManager]) return;
|
||||
|
||||
_layoutManager = layoutManager;
|
||||
|
||||
for (NSLayoutManager *layoutManager in _textStorage.layoutManagers) {
|
||||
[_textStorage removeLayoutManager:layoutManager];
|
||||
}
|
||||
[_textStorage addLayoutManager:_layoutManager];
|
||||
|
||||
- (void)setLineBreakMode:(NSLineBreakMode)lineBreakMode
|
||||
{
|
||||
_textContainer.lineBreakMode = lineBreakMode;
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user