diff --git a/Libraries/Text/Text/RCTTextShadowView.m b/Libraries/Text/Text/RCTTextShadowView.m index 2a00e97ba..790916354 100644 --- a/Libraries/Text/Text/RCTTextShadowView.m +++ b/Libraries/Text/Text/RCTTextShadowView.m @@ -31,6 +31,7 @@ _cachedTextStorages = [NSMapTable strongToStrongObjectsMapTable]; _needsUpdateView = YES; YGNodeSetMeasureFunc(self.yogaNode, RCTTextShadowViewMeasure); + YGNodeSetBaselineFunc(self.yogaNode, RCTTextShadowViewBaseline); } return self; @@ -307,6 +308,27 @@ ]; } +- (CGFloat)lastBaselineForSize:(CGSize)size +{ + NSAttributedString *attributedText = + [self textStorageAndLayoutManagerThatFitsSize:size exclusiveOwnership:NO]; + + __block CGFloat maximumDescender = 0.0; + + [attributedText enumerateAttribute:NSFontAttributeName + inRange:NSMakeRange(0, attributedText.length) + options:NSAttributedStringEnumerationLongestEffectiveRangeNotRequired + usingBlock: + ^(UIFont *font, NSRange range, __unused BOOL *stop) { + if (maximumDescender > font.descender) { + maximumDescender = font.descender; + } + } + ]; + + return size.height + maximumDescender; +} + static YGSize RCTTextShadowViewMeasure(YGNodeRef node, float width, YGMeasureMode widthMode, float height, YGMeasureMode heightMode) { CGSize maximumSize = (CGSize){ @@ -341,4 +363,18 @@ static YGSize RCTTextShadowViewMeasure(YGNodeRef node, float width, YGMeasureMod }; } +static float RCTTextShadowViewBaseline(YGNodeRef node, const float width, const float height) +{ + RCTTextShadowView *shadowTextView = (__bridge RCTTextShadowView *)YGNodeGetContext(node); + + CGSize size = (CGSize){ + RCTCoreGraphicsFloatFromYogaFloat(width), + RCTCoreGraphicsFloatFromYogaFloat(height) + }; + + CGFloat lastBaseline = [shadowTextView lastBaselineForSize:size]; + + return RCTYogaFloatFromCoreGraphicsFloat(lastBaseline); +} + @end