From f906a6749716430026450fdceecbe8856fd986c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Thu, 5 Feb 2026 03:38:03 -0800 Subject: [PATCH] Migrate `YogaProps` to Kotlin (#55349) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55349 Migrate com.facebook.yoga.YogaProps to Kotlin. X-link: https://github.com/facebook/yoga/pull/1844 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897771 Pulled By: cortinico --- .../main/java/com/facebook/yoga/YogaNode.kt | 70 ++---- .../java/com/facebook/yoga/YogaProps.java | 201 ------------------ .../main/java/com/facebook/yoga/YogaProps.kt | 183 ++++++++++++++++ 3 files changed, 206 insertions(+), 248 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.kt diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.kt index 27cf0f15ab1..fbd06f2e1bc 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaNode.kt @@ -56,59 +56,37 @@ public abstract class YogaNode : YogaProps { public abstract fun markLayoutSeen() - abstract override fun getStyleDirection(): YogaDirection + abstract override val styleDirection: YogaDirection abstract override fun setDirection(direction: YogaDirection) - abstract override fun getFlexDirection(): YogaFlexDirection + abstract override var flexDirection: YogaFlexDirection - abstract override fun setFlexDirection(flexDirection: YogaFlexDirection) + abstract override var justifyContent: YogaJustify - abstract override fun getJustifyContent(): YogaJustify + abstract override var alignItems: YogaAlign - abstract override fun setJustifyContent(justifyContent: YogaJustify) + abstract override var alignSelf: YogaAlign - abstract override fun getAlignItems(): YogaAlign + abstract override var alignContent: YogaAlign - abstract override fun setAlignItems(alignItems: YogaAlign) + abstract override var positionType: YogaPositionType - abstract override fun getAlignSelf(): YogaAlign + abstract override var boxSizing: YogaBoxSizing - abstract override fun setAlignSelf(alignSelf: YogaAlign) - - abstract override fun getAlignContent(): YogaAlign - - abstract override fun setAlignContent(alignContent: YogaAlign) - - abstract override fun getPositionType(): YogaPositionType - - abstract override fun setPositionType(positionType: YogaPositionType) - - abstract override fun getBoxSizing(): YogaBoxSizing? - - abstract override fun setBoxSizing(boxSizing: YogaBoxSizing?) - - abstract override fun getWrap(): YogaWrap - - abstract override fun setWrap(wrap: YogaWrap) + abstract override var wrap: YogaWrap public abstract var overflow: YogaOverflow? public abstract var display: YogaDisplay? - abstract override fun getFlex(): Float - - abstract override fun setFlex(flex: Float) + abstract override var flex: Float - abstract override fun getFlexGrow(): Float + abstract override var flexGrow: Float - abstract override fun setFlexGrow(flexGrow: Float) + abstract override var flexShrink: Float - abstract override fun getFlexShrink(): Float - - abstract override fun setFlexShrink(flexShrink: Float) - - abstract override fun getFlexBasis(): YogaValue + abstract override val flexBasis: YogaValue abstract override fun setFlexBasis(flexBasis: Float) @@ -138,7 +116,7 @@ public abstract class YogaNode : YogaProps { abstract override fun getBorder(edge: YogaEdge): Float - abstract override fun setBorder(edge: YogaEdge, border: Float) + abstract override fun setBorder(edge: YogaEdge, value: Float) abstract override fun getPosition(edge: YogaEdge): YogaValue @@ -148,7 +126,7 @@ public abstract class YogaNode : YogaProps { public abstract fun setPositionAuto(edge: YogaEdge) - abstract override fun getWidth(): YogaValue + abstract override val width: YogaValue abstract override fun setWidth(width: Float) @@ -162,7 +140,7 @@ public abstract class YogaNode : YogaProps { abstract override fun setWidthStretch() - abstract override fun getHeight(): YogaValue + abstract override val height: YogaValue abstract override fun setHeight(height: Float) @@ -176,7 +154,7 @@ public abstract class YogaNode : YogaProps { abstract override fun setHeightStretch() - abstract override fun getMinWidth(): YogaValue + abstract override val minWidth: YogaValue abstract override fun setMinWidth(minWidth: Float) @@ -188,7 +166,7 @@ public abstract class YogaNode : YogaProps { abstract override fun setMinWidthStretch() - abstract override fun getMinHeight(): YogaValue + abstract override val minHeight: YogaValue abstract override fun setMinHeight(minHeight: Float) @@ -200,7 +178,7 @@ public abstract class YogaNode : YogaProps { abstract override fun setMinHeightStretch() - abstract override fun getMaxWidth(): YogaValue + abstract override val maxWidth: YogaValue abstract override fun setMaxWidth(maxWidth: Float) @@ -212,9 +190,9 @@ public abstract class YogaNode : YogaProps { abstract override fun setMaxWidthStretch() - abstract override fun getMaxHeight(): YogaValue + abstract override val maxHeight: YogaValue - abstract override fun setMaxHeight(maxheight: Float) + abstract override fun setMaxHeight(maxHeight: Float) abstract override fun setMaxHeightPercent(percent: Float) @@ -224,9 +202,7 @@ public abstract class YogaNode : YogaProps { abstract override fun setMaxHeightStretch() - abstract override fun getAspectRatio(): Float - - abstract override fun setAspectRatio(aspectRatio: Float) + abstract override var aspectRatio: Float public abstract fun getGap(gutter: YogaGutter): YogaValue @@ -252,7 +228,7 @@ public abstract class YogaNode : YogaProps { abstract override fun setMeasureFunction(measureFunction: YogaMeasureFunction) - abstract override fun setBaselineFunction(baselineFunction: YogaBaselineFunction) + abstract override fun setBaselineFunction(yogaBaselineFunction: YogaBaselineFunction) public abstract val isMeasureDefined: Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.java deleted file mode 100644 index eefe4a7bd1d..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.java +++ /dev/null @@ -1,201 +0,0 @@ -/* - * Copyright (c) Meta Platforms, Inc. and affiliates. - * - * This source code is licensed under the MIT license found in the - * LICENSE file in the root directory of this source tree. - */ - -package com.facebook.yoga; - -public interface YogaProps { - - /* Width properties */ - - void setWidth(float width); - - void setWidthPercent(float percent); - - void setWidthAuto(); - - void setWidthMaxContent(); - - void setWidthFitContent(); - - void setWidthStretch(); - - void setMinWidth(float minWidth); - - void setMinWidthPercent(float percent); - - void setMinWidthMaxContent(); - - void setMinWidthFitContent(); - - void setMinWidthStretch(); - - void setMaxWidth(float maxWidth); - - void setMaxWidthPercent(float percent); - - void setMaxWidthMaxContent(); - - void setMaxWidthFitContent(); - - void setMaxWidthStretch(); - - /* Height properties */ - - void setHeight(float height); - - void setHeightPercent(float percent); - - void setHeightAuto(); - - void setHeightMaxContent(); - - void setHeightFitContent(); - - void setHeightStretch(); - - void setMinHeight(float minHeight); - - void setMinHeightPercent(float percent); - - void setMinHeightMaxContent(); - - void setMinHeightFitContent(); - - void setMinHeightStretch(); - - void setMaxHeight(float maxHeight); - - void setMaxHeightPercent(float percent); - - void setMaxHeightMaxContent(); - - void setMaxHeightFitContent(); - - void setMaxHeightStretch(); - - /* Margin properties */ - - void setMargin(YogaEdge edge, float margin); - - void setMarginPercent(YogaEdge edge, float percent); - - void setMarginAuto(YogaEdge edge); - - /* Padding properties */ - - void setPadding(YogaEdge edge, float padding); - - void setPaddingPercent(YogaEdge edge, float percent); - - /* Position properties */ - - void setPositionType(YogaPositionType positionType); - - void setPosition(YogaEdge edge, float position); - - void setPositionPercent(YogaEdge edge, float percent); - - /* Alignment properties */ - - void setAlignContent(YogaAlign alignContent); - - void setAlignItems(YogaAlign alignItems); - - void setAlignSelf(YogaAlign alignSelf); - - /* Flex properties */ - - void setFlex(float flex); - - void setFlexBasisAuto(); - - void setFlexBasisPercent(float percent); - - void setFlexBasis(float flexBasis); - - void setFlexBasisMaxContent(); - - void setFlexBasisFitContent(); - - void setFlexBasisStretch(); - - void setFlexDirection(YogaFlexDirection direction); - - void setFlexGrow(float flexGrow); - - void setFlexShrink(float flexShrink); - - /* Other properties */ - - void setJustifyContent(YogaJustify justifyContent); - - void setDirection(YogaDirection direction); - - void setBorder(YogaEdge edge, float value); - - void setWrap(YogaWrap wrap); - - void setAspectRatio(float aspectRatio); - - void setIsReferenceBaseline(boolean isReferenceBaseline); - - void setMeasureFunction(YogaMeasureFunction measureFunction); - - void setBaselineFunction(YogaBaselineFunction yogaBaselineFunction); - - void setBoxSizing(YogaBoxSizing boxSizing); - - /* Getters */ - - YogaValue getWidth(); - - YogaValue getMinWidth(); - - YogaValue getMaxWidth(); - - YogaValue getHeight(); - - YogaValue getMinHeight(); - - YogaValue getMaxHeight(); - - YogaDirection getStyleDirection(); - - YogaFlexDirection getFlexDirection(); - - YogaJustify getJustifyContent(); - - YogaAlign getAlignItems(); - - YogaAlign getAlignSelf(); - - YogaAlign getAlignContent(); - - YogaPositionType getPositionType(); - - float getFlexGrow(); - - float getFlexShrink(); - - YogaValue getFlexBasis(); - - float getFlex(); - - YogaWrap getWrap(); - - float getAspectRatio(); - - YogaValue getMargin(YogaEdge edge); - - YogaValue getPadding(YogaEdge edge); - - YogaValue getPosition(YogaEdge edge); - - float getBorder(YogaEdge edge); - - YogaBoxSizing getBoxSizing(); -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.kt new file mode 100644 index 00000000000..d29ef6bc60d --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/yoga/YogaProps.kt @@ -0,0 +1,183 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.yoga + +public interface YogaProps { + + /* Width properties */ + + public fun setWidth(width: Float) + + public fun setWidthPercent(percent: Float) + + public fun setWidthAuto() + + public fun setWidthMaxContent() + + public fun setWidthFitContent() + + public fun setWidthStretch() + + public fun setMinWidth(minWidth: Float) + + public fun setMinWidthPercent(percent: Float) + + public fun setMinWidthMaxContent() + + public fun setMinWidthFitContent() + + public fun setMinWidthStretch() + + public fun setMaxWidth(maxWidth: Float) + + public fun setMaxWidthPercent(percent: Float) + + public fun setMaxWidthMaxContent() + + public fun setMaxWidthFitContent() + + public fun setMaxWidthStretch() + + /* Height properties */ + + public fun setHeight(height: Float) + + public fun setHeightPercent(percent: Float) + + public fun setHeightAuto() + + public fun setHeightMaxContent() + + public fun setHeightFitContent() + + public fun setHeightStretch() + + public fun setMinHeight(minHeight: Float) + + public fun setMinHeightPercent(percent: Float) + + public fun setMinHeightMaxContent() + + public fun setMinHeightFitContent() + + public fun setMinHeightStretch() + + public fun setMaxHeight(maxHeight: Float) + + public fun setMaxHeightPercent(percent: Float) + + public fun setMaxHeightMaxContent() + + public fun setMaxHeightFitContent() + + public fun setMaxHeightStretch() + + /* Margin properties */ + + public fun setMargin(edge: YogaEdge, margin: Float) + + public fun setMarginPercent(edge: YogaEdge, percent: Float) + + public fun setMarginAuto(edge: YogaEdge) + + /* Padding properties */ + + public fun setPadding(edge: YogaEdge, padding: Float) + + public fun setPaddingPercent(edge: YogaEdge, percent: Float) + + /* Position properties */ + + public fun setPosition(edge: YogaEdge, position: Float) + + public fun setPositionPercent(edge: YogaEdge, percent: Float) + + /* Border properties */ + + public fun setBorder(edge: YogaEdge, value: Float) + + /* Flex basis properties */ + + public fun setFlexBasisAuto() + + public fun setFlexBasisPercent(percent: Float) + + public fun setFlexBasis(flexBasis: Float) + + public fun setFlexBasisMaxContent() + + public fun setFlexBasisFitContent() + + public fun setFlexBasisStretch() + + /* Direction property - setter has different name than getter */ + + public fun setDirection(direction: YogaDirection) + + /* Other functions */ + + public fun setIsReferenceBaseline(isReferenceBaseline: Boolean) + + public fun setMeasureFunction(measureFunction: YogaMeasureFunction) + + public fun setBaselineFunction(yogaBaselineFunction: YogaBaselineFunction) + + /* Mutable properties - getter and setter with matching types */ + + public var flexDirection: YogaFlexDirection + + public var justifyContent: YogaJustify + + public var alignItems: YogaAlign + + public var alignSelf: YogaAlign + + public var alignContent: YogaAlign + + public var positionType: YogaPositionType + + public var flexGrow: Float + + public var flexShrink: Float + + public var flex: Float + + public var aspectRatio: Float + + public var wrap: YogaWrap + + public var boxSizing: YogaBoxSizing + + /* Read-only properties - getter only, or setter has different type/name */ + + public val styleDirection: YogaDirection + + public val width: YogaValue + + public val minWidth: YogaValue + + public val maxWidth: YogaValue + + public val height: YogaValue + + public val minHeight: YogaValue + + public val maxHeight: YogaValue + + public val flexBasis: YogaValue + + /* Functions with parameters */ + + public fun getMargin(edge: YogaEdge): YogaValue + + public fun getPadding(edge: YogaEdge): YogaValue + + public fun getPosition(edge: YogaEdge): YogaValue + + public fun getBorder(edge: YogaEdge): Float +}