Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,11 @@ Float ParagraphShadowNode::baseline(
TextLayoutManagerExtended(*textLayoutManager_)
.measureLines(
attributedStringBox, content.paragraphAttributes, size);
return LineMeasurement::baseline(lines);
// Yoga expects the baseline from the border box; the ascender is measured
// from the top of the text content.
auto topInset = YGNodeLayoutGetBorder(&yogaNode_, YGEdgeTop) +
YGNodeLayoutGetPadding(&yogaNode_, YGEdgeTop);
return topInset + LineMeasurement::baseline(lines);
} else {
LOG(WARNING)
<< "Baseline alignment is not supported by the current platform";
Expand Down
9 changes: 9 additions & 0 deletions packages/rn-tester/.maestro/text-baseline-insets.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
appId: ${APP_ID}
---
- launchApp
- stopApp
- openLink: rntester://example/Text/paddedTextBaseline
- runFlow: ./helpers/confirm-open-link.yml
- extendedWaitUntil:
visible: 'Top edge difference: 24 dp'
timeout: 30000
30 changes: 30 additions & 0 deletions packages/rn-tester/js/examples/Text/TextSharedExamples.js
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,37 @@ function LastLineClippingExample(): React.Node {
);
}

function PaddedTextBaselineExample(): React.Node {
const [leftY, setLeftY] = useState<?number>(null);
const [rightY, setRightY] = useState<?number>(null);
return (
<View>
<View style={{flexDirection: 'row', alignItems: 'baseline'}}>
<Text
onLayout={event => setLeftY(event.nativeEvent.layout.y)}
style={{paddingBottom: 8}}>
Aa
</Text>
<Text
onLayout={event => setRightY(event.nativeEvent.layout.y)}
style={{paddingTop: 20, borderTopWidth: 4}}>
Aa
</Text>
</View>
{leftY != null && rightY != null && (
<Text>Top edge difference: {Math.round(leftY - rightY)} dp</Text>
)}
</View>
);
}

export default [
{
title: 'Baseline alignment with padding and border',
name: 'paddedTextBaseline',
description: 'The text should line up despite the different top edges.',
render: PaddedTextBaselineExample,
},
{
title: 'Empty Text',
name: 'emptyText',
Expand Down
Loading