@@ -25,8 +25,8 @@ - (dispatch_queue_t)methodQueue
2525 reject (@" invalid_width" , @" missing required width property" , nil );
2626 return ;
2727 }
28- if ([options objectForKey: @" texts " ] == nil ) {
29- reject (@" invalid_texts " , @" missing required texts property" , nil );
28+ if ([options objectForKey: @" text " ] == nil ) {
29+ reject (@" invalid_text " , @" missing required text property" , nil );
3030 return ;
3131 }
3232 if ([options objectForKey: @" fontSize" ] == nil ) {
@@ -35,29 +35,41 @@ - (dispatch_queue_t)methodQueue
3535 }
3636
3737 float width = [RCTConvert float: options[@" width" ]];
38- NSArray *texts = [RCTConvert NSArray : options[@" texts " ]];
38+ NSString *text = [RCTConvert NSString : options[@" text " ]];
3939 CGFloat fontSize = [RCTConvert CGFloat: options[@" fontSize" ]];
4040
41- NSMutableArray * results = [[NSMutableArray alloc ] init ];
41+ NSMutableDictionary * result = [[NSMutableDictionary alloc ] init ];
42+
4243 UIFont *font = [UIFont systemFontOfSize: fontSize];
43-
44- for (NSString * text in texts) {
45- NSTextStorage *textStorage = [[NSTextStorage alloc ] initWithString: text];
44+
45+ CGFloat firstHeight = 0 ;
46+
47+ for (NSString *s in [NSArray arrayWithObjects: @" " , text, nil ]) {
48+ NSTextStorage *textStorage = [[NSTextStorage alloc ] initWithString: s];
4649 NSTextContainer *textContainer = [[NSTextContainer alloc ] initWithSize: CGSizeMake (width, FLT_MAX)];
4750 NSLayoutManager *layoutManager = [[NSLayoutManager alloc ] init ];
48-
51+
4952 [layoutManager addTextContainer: textContainer];
5053 [textStorage addLayoutManager: layoutManager];
51-
54+
5255 [textStorage addAttribute: NSFontAttributeName value: font
5356 range: NSMakeRange (0 , [textStorage length ])];
5457 [textContainer setLineFragmentPadding: 0.0 ];
5558 (void ) [layoutManager glyphRangeForTextContainer: textContainer];
5659 CGRect resultRect = [layoutManager usedRectForTextContainer: textContainer];
57-
58- [results addObject: [NSNumber numberWithFloat: resultRect.size.height]];
60+ if (firstHeight == 0 ) {
61+ firstHeight = resultRect.size .height ;
62+ } else {
63+ CGFloat height = resultRect.size .height ;
64+ int lines = height / firstHeight;
65+ result[@" width" ] = @(resultRect.size .width );
66+ result[@" height" ] = @(height);
67+ result[@" lineCount" ] = @(lines);
68+ result[@" lastLineWidth" ] = @(0 );
69+ }
5970 }
60- resolve (results);
71+
72+ resolve (result);
6173}
6274
6375@end
0 commit comments