@@ -31,6 +31,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
3131 _cachedTextStorages = [NSMapTable strongToStrongObjectsMapTable ];
3232 _needsUpdateView = YES ;
3333 YGNodeSetMeasureFunc (self.yogaNode , RCTTextShadowViewMeasure);
34+ YGNodeSetBaselineFunc (self.yogaNode , RCTTextShadowViewBaseline);
3435 }
3536
3637 return self;
@@ -307,6 +308,27 @@ - (void)layoutSubviewsWithContext:(RCTLayoutContext)layoutContext
307308 ];
308309}
309310
311+ - (CGFloat)lastBaselineForSize : (CGSize)size
312+ {
313+ NSAttributedString *attributedText =
314+ [self textStorageAndLayoutManagerThatFitsSize: size exclusiveOwnership: NO ];
315+
316+ __block CGFloat maximumDescender = 0.0 ;
317+
318+ [attributedText enumerateAttribute: NSFontAttributeName
319+ inRange: NSMakeRange (0 , attributedText.length)
320+ options: NSAttributedStringEnumerationLongestEffectiveRangeNotRequired
321+ usingBlock:
322+ ^(UIFont *font, NSRange range, __unused BOOL *stop) {
323+ if (maximumDescender > font.descender ) {
324+ maximumDescender = font.descender ;
325+ }
326+ }
327+ ];
328+
329+ return size.height + maximumDescender;
330+ }
331+
310332static YGSize RCTTextShadowViewMeasure (YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode)
311333{
312334 CGSize maximumSize = (CGSize){
@@ -341,4 +363,18 @@ static YGSize RCTTextShadowViewMeasure(YGNodeRef node, float width, YGMeasureMod
341363 };
342364}
343365
366+ static float RCTTextShadowViewBaseline (YGNodeRef node, const float width, const float height)
367+ {
368+ RCTTextShadowView *shadowTextView = (__bridge RCTTextShadowView *)YGNodeGetContext (node);
369+
370+ CGSize size = (CGSize){
371+ RCTCoreGraphicsFloatFromYogaFloat (width),
372+ RCTCoreGraphicsFloatFromYogaFloat (height)
373+ };
374+
375+ CGFloat lastBaseline = [shadowTextView lastBaselineForSize: size];
376+
377+ return RCTYogaFloatFromCoreGraphicsFloat (lastBaseline);
378+ }
379+
344380@end
0 commit comments