@@ -31,6 +31,7 @@ - (instancetype)initWithBridge:(RCTBridge *)bridge
31
31
_cachedTextStorages = [NSMapTable strongToStrongObjectsMapTable ];
32
32
_needsUpdateView = YES ;
33
33
YGNodeSetMeasureFunc (self.yogaNode , RCTTextShadowViewMeasure);
34
+ YGNodeSetBaselineFunc (self.yogaNode , RCTTextShadowViewBaseline);
34
35
}
35
36
36
37
return self;
@@ -307,6 +308,27 @@ - (void)layoutSubviewsWithContext:(RCTLayoutContext)layoutContext
307
308
];
308
309
}
309
310
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
+
310
332
static YGSize RCTTextShadowViewMeasure (YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode)
311
333
{
312
334
CGSize maximumSize = (CGSize ){
@@ -341,4 +363,18 @@ static YGSize RCTTextShadowViewMeasure(YGNodeRef node, float width, YGMeasureMod
341
363
};
342
364
}
343
365
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
+
344
380
@end
0 commit comments