diff --git a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java
index 46bc1e9b500..26257ebe938 100644
--- a/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java
+++ b/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactTextShadowNode.java
@@ -32,6 +32,7 @@ import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIViewOperationQueue;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.events.RCTEventEmitter;
+import com.facebook.yoga.YogaBaselineFunction;
import com.facebook.yoga.YogaConstants;
import com.facebook.yoga.YogaDirection;
import com.facebook.yoga.YogaMeasureFunction;
@@ -159,6 +160,20 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
}
};
+ private final YogaBaselineFunction mTextBaselineFunction =
+ new YogaBaselineFunction() {
+ @Override
+ public float baseline(YogaNode node, float width, float height) {
+ Spannable text =
+ Assertions.assertNotNull(
+ mPreparedSpannableText,
+ "Spannable element has not been prepared in onBeforeLayout");
+
+ Layout layout = measureSpannedText(text, width, YogaMeasureMode.EXACTLY);
+ return layout.getLineBaseline(layout.getLineCount() - 1);
+ }
+ };
+
public ReactTextShadowNode() {
this(null);
}
@@ -171,6 +186,7 @@ public class ReactTextShadowNode extends ReactBaseTextShadowNode {
private void initMeasureFunction() {
if (!isVirtual()) {
setMeasureFunction(mTextMeasureFunction);
+ setBaselineFunction(mTextBaselineFunction);
}
}
diff --git a/packages/rn-tester/js/examples/Text/TextExample.android.js b/packages/rn-tester/js/examples/Text/TextExample.android.js
index d44aff22b42..aacb5fa973d 100644
--- a/packages/rn-tester/js/examples/Text/TextExample.android.js
+++ b/packages/rn-tester/js/examples/Text/TextExample.android.js
@@ -884,6 +884,62 @@ const styles = StyleSheet.create({
alignSelf: 'center',
},
});
+
+function TextBaseLineLayoutExample(props: {}): React.Node {
+ const texts = [];
+ for (let i = 9; i >= 0; i--) {
+ texts.push(
+
+ {i}
+ ,
+ );
+ }
+
+ const marker = (
+
+ );
+ const subtitleStyle = {fontSize: 16, marginTop: 8, fontWeight: 'bold'};
+
+ return (
+
+ {'Nested s:'}
+
+ {marker}
+ {texts}
+ {marker}
+
+
+ {'Array of s in :'}
+
+ {marker}
+ {texts}
+ {marker}
+
+
+ {'Interleaving and :'}
+
+ {marker}
+
+ Some text.
+
+ {marker}
+ Text inside View.
+ {marker}
+
+
+ {marker}
+
+
+ );
+}
+
exports.title = 'Text';
exports.documentationURL = 'https://reactnative.dev/docs/text';
exports.category = 'Basic';
@@ -895,4 +951,10 @@ exports.examples = [
return ;
},
},
+ {
+ title: "Text `alignItems: 'baseline'` style",
+ render: function(): React.Node {
+ return ;
+ },
+ },
];