[React Native] #WIP Modify RCTShadowText measure function to honor maxNumberOfLines property

This commit is contained in:
Alex Akers
2015-04-07 02:19:49 -07:00
parent 2aa52880b7
commit 397d4666d9
5 changed files with 77 additions and 44 deletions

View File

@@ -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];
}