@@ -180,12 +180,13 @@ - (instancetype)initWithFrame:(CGRect)frame
180180 return self;
181181}
182182
183- - (CGFloat )computeSegmentLayoutForWidth : (CGFloat)width applyFrames : (BOOL )applyFrames
183+ - (CGSize )computeSegmentLayoutForWidth : (CGFloat)width applyFrames : (BOOL )applyFrames
184184{
185185 if (_segmentViews.count == 0 )
186- return 0.0 ;
186+ return CGSizeZero ;
187187
188188 __block CGFloat yOffset = 0.0 ;
189+ __block CGFloat maxContentWidth = 0.0 ;
189190 const NSUInteger lastIndex = _segmentViews.count - 1 ;
190191
191192 [_segmentViews enumerateObjectsUsingBlock: ^(RCTUIView *segment, NSUInteger i, BOOL *stop) {
@@ -197,16 +198,20 @@ - (CGFloat)computeSegmentLayoutForWidth:(CGFloat)width applyFrames:(BOOL)applyFr
197198 if ([segment isKindOfClass: [EnrichedMarkdownInternalText class ]]) {
198199 EnrichedMarkdownInternalText *textView = (EnrichedMarkdownInternalText *)segment;
199200 textView.allowTrailingMargin = shouldAddBottomMargin;
200- segmentHeight = [textView measureHeight: width];
201+ CGSize textSize = [textView measureSize: width];
202+ segmentHeight = textSize.height ;
203+ maxContentWidth = MAX (maxContentWidth, textSize.width );
201204
202205 } else if ([segment isKindOfClass: [TableContainerView class ]]) {
203206 yOffset += _config.tableMarginTop ;
204207 segmentHeight = [(TableContainerView *)segment measureHeight: width];
208+ maxContentWidth = width;
205209 }
206210#if ENRICHED_MARKDOWN_MATH
207211 else if ([segment isKindOfClass: [ENRMMathContainerView class ]]) {
208212 yOffset += _config.mathMarginTop ;
209213 segmentHeight = [(ENRMMathContainerView *)segment measureHeight: width];
214+ maxContentWidth = width;
210215 }
211216#endif
212217
@@ -236,19 +241,20 @@ - (CGFloat)computeSegmentLayoutForWidth:(CGFloat)width applyFrames:(BOOL)applyFr
236241#endif
237242 }];
238243
239- return yOffset;
244+ return CGSizeMake (maxContentWidth, yOffset) ;
240245}
241246
242247- (CGSize)measureSize : (CGFloat)maxWidth
243248{
244249 CGFloat defaultHeight = UIFontLineHeight ([UIFont systemFontOfSize: 16.0 ]);
245- CGFloat totalHeight = [self computeSegmentLayoutForWidth: maxWidth applyFrames: NO ];
246- if (totalHeight == 0 )
250+ CGSize contentSize = [self computeSegmentLayoutForWidth: maxWidth applyFrames: NO ];
251+ if (contentSize. height == 0 )
247252 return CGSizeMake (maxWidth, defaultHeight);
248253
249- // Round to pixel boundaries to match React Native's <Text> measurement
250254 CGFloat scale = RCTScreenScale ();
251- return CGSizeMake (maxWidth, ceil (totalHeight * scale) / scale);
255+ CGFloat measuredWidth = MIN (ceil (contentSize.width * scale) / scale, maxWidth);
256+ CGFloat measuredHeight = ceil (contentSize.height * scale) / scale;
257+ return CGSizeMake (measuredWidth, measuredHeight);
252258}
253259
254260- (BOOL )hasRenderedMarkdown : (NSString *)markdown
0 commit comments