From da5ba7f7c6d15fbcc8a1f054de96408588bcc30f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Mon, 11 Aug 2025 08:47:34 -0700 Subject: [PATCH 01/14] Migrate `YogaLogger` to Kotlin (#1834) Summary: Migrate com.facebook.yoga.YogaLogger to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1834 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897742 Pulled By: cortinico fbshipit-source-id: 79b926a7abadce9038fc55ad0f608e92bc77a55a --- .../yoga/{YogaLogger.java => YogaLogger.kt} | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) rename java/com/facebook/yoga/{YogaLogger.java => YogaLogger.kt} (52%) diff --git a/java/com/facebook/yoga/YogaLogger.java b/java/com/facebook/yoga/YogaLogger.kt similarity index 52% rename from java/com/facebook/yoga/YogaLogger.java rename to java/com/facebook/yoga/YogaLogger.kt index f40292dd..bc0a6fb3 100644 --- a/java/com/facebook/yoga/YogaLogger.java +++ b/java/com/facebook/yoga/YogaLogger.kt @@ -5,16 +5,15 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.yoga; +package com.facebook.yoga -import com.facebook.yoga.annotations.DoNotStrip; +import com.facebook.yoga.annotations.DoNotStrip /** - * Interface for receiving logs from native layer. Use by setting YogaNode.setLogger(myLogger); - * See YogaLogLevel for the different log levels. + * Interface for receiving logs from native layer. Use by setting YogaNode.setLogger(myLogger); See + * YogaLogLevel for the different log levels. */ @DoNotStrip -public interface YogaLogger { - @DoNotStrip - void log(YogaLogLevel level, String message); +public fun interface YogaLogger { + @DoNotStrip public fun log(level: YogaLogLevel, message: String) } From d4b5220e6c56579a204b4a8e53194681088db0ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Mon, 11 Aug 2025 10:51:55 -0700 Subject: [PATCH 02/14] Migrate `YogaBaselineFunction` to Kotlin (#1831) Summary: Migrate com.facebook.yoga.YogaBaselineFunction to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1831 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: joevilches, mdvacca Differential Revision: D79897676 Pulled By: cortinico fbshipit-source-id: 2f175bf60a871c4635d1575faec1096f9c970f48 --- .../{YogaBaselineFunction.java => YogaBaselineFunction.kt} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename java/com/facebook/yoga/{YogaBaselineFunction.java => YogaBaselineFunction.kt} (70%) diff --git a/java/com/facebook/yoga/YogaBaselineFunction.java b/java/com/facebook/yoga/YogaBaselineFunction.kt similarity index 70% rename from java/com/facebook/yoga/YogaBaselineFunction.java rename to java/com/facebook/yoga/YogaBaselineFunction.kt index d3444215..b061fc88 100644 --- a/java/com/facebook/yoga/YogaBaselineFunction.java +++ b/java/com/facebook/yoga/YogaBaselineFunction.kt @@ -5,12 +5,12 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.yoga; +package com.facebook.yoga -public interface YogaBaselineFunction { +public fun interface YogaBaselineFunction { /** * Return the baseline of the node in points. When no baseline function is set the baseline * default to the computed height of the node. */ - float baseline(YogaNode node, float width, float height); + public fun baseline(node: YogaNode, width: Float, height: Float): Float } From 714d4b2ebe64381820b36dbeb4e23a29102d06aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 12 Aug 2025 03:34:21 -0700 Subject: [PATCH 03/14] Migrate `YogaStyleInputs` to Kotlin (#1830) Summary: Migrate com.facebook.yoga.YogaStyleInputs to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1830 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897662 Pulled By: cortinico fbshipit-source-id: a4063a8c0f608050162cd3707834040e35f9ebf7 --- java/com/facebook/yoga/YogaStyleInputs.java | 51 --------------------- java/com/facebook/yoga/YogaStyleInputs.kt | 51 +++++++++++++++++++++ 2 files changed, 51 insertions(+), 51 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaStyleInputs.java create mode 100644 java/com/facebook/yoga/YogaStyleInputs.kt diff --git a/java/com/facebook/yoga/YogaStyleInputs.java b/java/com/facebook/yoga/YogaStyleInputs.java deleted file mode 100644 index 405a2770..00000000 --- a/java/com/facebook/yoga/YogaStyleInputs.java +++ /dev/null @@ -1,51 +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 class YogaStyleInputs { - public static final short LAYOUT_DIRECTION = 0; - public static final short FLEX_DIRECTION = 1; - public static final short FLEX = 2; - public static final short FLEX_GROW = 3; - public static final short FLEX_SHRINK = 4; - public static final short FLEX_BASIS = 5; - public static final short FLEX_BASIS_PERCENT = 6; - public static final short FLEX_BASIS_AUTO = 7; - public static final short FLEX_WRAP = 8; - public static final short WIDTH = 9; - public static final short WIDTH_PERCENT = 10; - public static final short WIDTH_AUTO = 11; - public static final short MIN_WIDTH = 12; - public static final short MIN_WIDTH_PERCENT = 13; - public static final short MAX_WIDTH = 14; - public static final short MAX_WIDTH_PERCENT = 15; - public static final short HEIGHT = 16; - public static final short HEIGHT_PERCENT = 17; - public static final short HEIGHT_AUTO = 18; - public static final short MIN_HEIGHT = 19; - public static final short MIN_HEIGHT_PERCENT = 20; - public static final short MAX_HEIGHT = 21; - public static final short MAX_HEIGHT_PERCENT = 22; - public static final short JUSTIFY_CONTENT = 23; - public static final short ALIGN_ITEMS = 24; - public static final short ALIGN_SELF = 25; - public static final short ALIGN_CONTENT = 26; - public static final short POSITION_TYPE = 27; - public static final short ASPECT_RATIO = 28; - public static final short OVERFLOW = 29; - public static final short DISPLAY = 30; - public static final short MARGIN = 31; - public static final short MARGIN_PERCENT = 32; - public static final short MARGIN_AUTO = 33; - public static final short PADDING = 34; - public static final short PADDING_PERCENT = 35; - public static final short BORDER = 36; - public static final short POSITION = 37; - public static final short POSITION_PERCENT = 38; - public static final short IS_REFERENCE_BASELINE = 39; -} diff --git a/java/com/facebook/yoga/YogaStyleInputs.kt b/java/com/facebook/yoga/YogaStyleInputs.kt new file mode 100644 index 00000000..33c439a6 --- /dev/null +++ b/java/com/facebook/yoga/YogaStyleInputs.kt @@ -0,0 +1,51 @@ +/* + * 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 object YogaStyleInputs { + public const val LAYOUT_DIRECTION: Short = 0 + public const val FLEX_DIRECTION: Short = 1 + public const val FLEX: Short = 2 + public const val FLEX_GROW: Short = 3 + public const val FLEX_SHRINK: Short = 4 + public const val FLEX_BASIS: Short = 5 + public const val FLEX_BASIS_PERCENT: Short = 6 + public const val FLEX_BASIS_AUTO: Short = 7 + public const val FLEX_WRAP: Short = 8 + public const val WIDTH: Short = 9 + public const val WIDTH_PERCENT: Short = 10 + public const val WIDTH_AUTO: Short = 11 + public const val MIN_WIDTH: Short = 12 + public const val MIN_WIDTH_PERCENT: Short = 13 + public const val MAX_WIDTH: Short = 14 + public const val MAX_WIDTH_PERCENT: Short = 15 + public const val HEIGHT: Short = 16 + public const val HEIGHT_PERCENT: Short = 17 + public const val HEIGHT_AUTO: Short = 18 + public const val MIN_HEIGHT: Short = 19 + public const val MIN_HEIGHT_PERCENT: Short = 20 + public const val MAX_HEIGHT: Short = 21 + public const val MAX_HEIGHT_PERCENT: Short = 22 + public const val JUSTIFY_CONTENT: Short = 23 + public const val ALIGN_ITEMS: Short = 24 + public const val ALIGN_SELF: Short = 25 + public const val ALIGN_CONTENT: Short = 26 + public const val POSITION_TYPE: Short = 27 + public const val ASPECT_RATIO: Short = 28 + public const val OVERFLOW: Short = 29 + public const val DISPLAY: Short = 30 + public const val MARGIN: Short = 31 + public const val MARGIN_PERCENT: Short = 32 + public const val MARGIN_AUTO: Short = 33 + public const val PADDING: Short = 34 + public const val PADDING_PERCENT: Short = 35 + public const val BORDER: Short = 36 + public const val POSITION: Short = 37 + public const val POSITION_PERCENT: Short = 38 + public const val IS_REFERENCE_BASELINE: Short = 39 +} From d1037226c0576350302a5e9aff4c939ee27d2ae6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 12 Aug 2025 07:40:31 -0700 Subject: [PATCH 04/14] Migrate `YogaMeasureFunction` to Kotlin (#1835) Summary: Migrate com.facebook.yoga.YogaMeasureFunction to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1835 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: mdvacca Differential Revision: D79897728 Pulled By: cortinico fbshipit-source-id: 959ae976622838147685cf6088674dce25f5cc99 --- .../facebook/yoga/YogaMeasureFunction.java | 20 ------------------- java/com/facebook/yoga/YogaMeasureFunction.kt | 19 ++++++++++++++++++ 2 files changed, 19 insertions(+), 20 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaMeasureFunction.java create mode 100644 java/com/facebook/yoga/YogaMeasureFunction.kt diff --git a/java/com/facebook/yoga/YogaMeasureFunction.java b/java/com/facebook/yoga/YogaMeasureFunction.java deleted file mode 100644 index 21da35fe..00000000 --- a/java/com/facebook/yoga/YogaMeasureFunction.java +++ /dev/null @@ -1,20 +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 YogaMeasureFunction { - /** - * Return a value created by YogaMeasureOutput.make(width, height); - */ - long measure( - YogaNode node, - float width, - YogaMeasureMode widthMode, - float height, - YogaMeasureMode heightMode); -} diff --git a/java/com/facebook/yoga/YogaMeasureFunction.kt b/java/com/facebook/yoga/YogaMeasureFunction.kt new file mode 100644 index 00000000..10b5cfc0 --- /dev/null +++ b/java/com/facebook/yoga/YogaMeasureFunction.kt @@ -0,0 +1,19 @@ +/* + * 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 fun interface YogaMeasureFunction { + /** Return a value created by YogaMeasureOutput.make(width, height); */ + public fun measure( + node: YogaNode, + width: Float, + widthMode: YogaMeasureMode, + height: Float, + heightMode: YogaMeasureMode + ): Long +} From cf50bc9adfee1eb03a65589c10fe1c2fe54e6381 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 12 Aug 2025 07:55:41 -0700 Subject: [PATCH 05/14] Migrate `YogaMeasureOutput` to Kotlin (#1842) Summary: Migrate com.facebook.yoga.YogaMeasureOutput to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1842 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897681 Pulled By: cortinico fbshipit-source-id: 63280b6aed9bbeeb1e71458a1793c9647dcf0726 --- java/com/facebook/yoga/YogaMeasureOutput.java | 32 ------------------- java/com/facebook/yoga/YogaMeasureOutput.kt | 29 +++++++++++++++++ 2 files changed, 29 insertions(+), 32 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaMeasureOutput.java create mode 100644 java/com/facebook/yoga/YogaMeasureOutput.kt diff --git a/java/com/facebook/yoga/YogaMeasureOutput.java b/java/com/facebook/yoga/YogaMeasureOutput.java deleted file mode 100644 index c7a77aba..00000000 --- a/java/com/facebook/yoga/YogaMeasureOutput.java +++ /dev/null @@ -1,32 +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; - -/** - * Helpers for building measure output value. - */ -public class YogaMeasureOutput { - - public static long make(float width, float height) { - final int wBits = Float.floatToRawIntBits(width); - final int hBits = Float.floatToRawIntBits(height); - return ((long) wBits) << 32 | ((long) hBits); - } - - public static long make(int width, int height) { - return make((float) width, (float) height); - } - - public static float getWidth(long measureOutput) { - return Float.intBitsToFloat((int) (0xFFFFFFFF & (measureOutput >> 32))); - } - - public static float getHeight(long measureOutput) { - return Float.intBitsToFloat((int) (0xFFFFFFFF & measureOutput)); - } -} diff --git a/java/com/facebook/yoga/YogaMeasureOutput.kt b/java/com/facebook/yoga/YogaMeasureOutput.kt new file mode 100644 index 00000000..9185ef46 --- /dev/null +++ b/java/com/facebook/yoga/YogaMeasureOutput.kt @@ -0,0 +1,29 @@ +/* + * 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 + +/** Helpers for building measure output value. */ +public object YogaMeasureOutput { + @JvmStatic + public fun make(width: Float, height: Float): Long { + val wBits = java.lang.Float.floatToRawIntBits(width) + val hBits = java.lang.Float.floatToRawIntBits(height) + return (wBits.toLong()) shl 32 or (hBits.toLong()) + } + + @JvmStatic + public fun make(width: Int, height: Int): Long = make(width.toFloat(), height.toFloat()) + + @JvmStatic + public fun getWidth(measureOutput: Long): Float = + java.lang.Float.intBitsToFloat((0xFFFFFFFFL and (measureOutput shr 32)).toInt()) + + @JvmStatic + public fun getHeight(measureOutput: Long): Float = + java.lang.Float.intBitsToFloat((0xFFFFFFFFL and measureOutput).toInt()) +} From c54215fd775a9b190592e3fc00dedac7744c93b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 12 Aug 2025 08:57:43 -0700 Subject: [PATCH 06/14] Migrate `YogaNodeFactory` to Kotlin (#1832) Summary: Migrate com.facebook.yoga.YogaNodeFactory to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1832 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: zielinskimz Differential Revision: D79897733 Pulled By: cortinico fbshipit-source-id: 3ea4f5635eb8c910719c13d3087356b96b6f0746 --- java/com/facebook/yoga/YogaNodeFactory.java | 18 ------------------ java/com/facebook/yoga/YogaNodeFactory.kt | 14 ++++++++++++++ 2 files changed, 14 insertions(+), 18 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaNodeFactory.java create mode 100644 java/com/facebook/yoga/YogaNodeFactory.kt diff --git a/java/com/facebook/yoga/YogaNodeFactory.java b/java/com/facebook/yoga/YogaNodeFactory.java deleted file mode 100644 index 912083a7..00000000 --- a/java/com/facebook/yoga/YogaNodeFactory.java +++ /dev/null @@ -1,18 +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 abstract class YogaNodeFactory { - public static YogaNode create() { - return new YogaNodeJNIFinalizer(); - } - - public static YogaNode create(YogaConfig config) { - return new YogaNodeJNIFinalizer(config); - } -} diff --git a/java/com/facebook/yoga/YogaNodeFactory.kt b/java/com/facebook/yoga/YogaNodeFactory.kt new file mode 100644 index 00000000..ead0d2be --- /dev/null +++ b/java/com/facebook/yoga/YogaNodeFactory.kt @@ -0,0 +1,14 @@ +/* + * 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 object YogaNodeFactory { + @JvmStatic public fun create(): YogaNode = YogaNodeJNIFinalizer() + + @JvmStatic public fun create(config: YogaConfig): YogaNode = YogaNodeJNIFinalizer(config) +} From c90aecbdfe96220b3e322a9f9523ac4060a25166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 12 Aug 2025 09:10:30 -0700 Subject: [PATCH 07/14] Migrate `LayoutPassReason` to Kotlin (#1836) Summary: Migrate com.facebook.yoga.LayoutPassReason to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1836 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897685 Pulled By: cortinico fbshipit-source-id: 87d2e4b95fbdbfe48d84019e9ffb50deb9286d8c --- java/com/facebook/yoga/LayoutPassReason.java | 43 -------------------- java/com/facebook/yoga/LayoutPassReason.kt | 35 ++++++++++++++++ 2 files changed, 35 insertions(+), 43 deletions(-) delete mode 100644 java/com/facebook/yoga/LayoutPassReason.java create mode 100644 java/com/facebook/yoga/LayoutPassReason.kt diff --git a/java/com/facebook/yoga/LayoutPassReason.java b/java/com/facebook/yoga/LayoutPassReason.java deleted file mode 100644 index 59046f05..00000000 --- a/java/com/facebook/yoga/LayoutPassReason.java +++ /dev/null @@ -1,43 +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 enum LayoutPassReason { - INITIAL(0), - ABS_LAYOUT(1), - STRETCH(2), - MULTILINE_STRETCH(3), - FLEX_LAYOUT(4), - MEASURE(5), - ABS_MEASURE(6), - FLEX_MEASURE(7); - - private final int mIntValue; - - LayoutPassReason(int intValue) { - mIntValue = intValue; - } - - public int intValue() { - return mIntValue; - } - - public static LayoutPassReason fromInt(int value) { - switch (value) { - case 0: return INITIAL; - case 1: return ABS_LAYOUT; - case 2: return STRETCH; - case 3: return MULTILINE_STRETCH; - case 4: return FLEX_LAYOUT; - case 5: return MEASURE; - case 6: return ABS_MEASURE; - case 7: return FLEX_MEASURE; - default: throw new IllegalArgumentException("Unknown enum value: " + value); - } - } -} diff --git a/java/com/facebook/yoga/LayoutPassReason.kt b/java/com/facebook/yoga/LayoutPassReason.kt new file mode 100644 index 00000000..3c765726 --- /dev/null +++ b/java/com/facebook/yoga/LayoutPassReason.kt @@ -0,0 +1,35 @@ +/* + * 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 enum class LayoutPassReason(public val intValue: Int) { + INITIAL(0), + ABS_LAYOUT(1), + STRETCH(2), + MULTILINE_STRETCH(3), + FLEX_LAYOUT(4), + MEASURE(5), + ABS_MEASURE(6), + FLEX_MEASURE(7); + + public companion object { + @JvmStatic + public fun fromInt(value: Int): LayoutPassReason = + when (value) { + 0 -> INITIAL + 1 -> ABS_LAYOUT + 2 -> STRETCH + 3 -> MULTILINE_STRETCH + 4 -> FLEX_LAYOUT + 5 -> MEASURE + 6 -> ABS_MEASURE + 7 -> FLEX_MEASURE + else -> throw IllegalArgumentException("Unknown enum value: $value") + } + } +} From 8087edaafe27123b771ad2c81de2ceda67a85f97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 12 Aug 2025 09:49:31 -0700 Subject: [PATCH 08/14] Migrate `YogaLayoutType` to Kotlin (#1837) Summary: Migrate com.facebook.yoga.YogaLayoutType to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1837 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897708 Pulled By: cortinico fbshipit-source-id: e3c8a3cc60f806d151d2be956b26dd98963254a6 --- java/com/facebook/yoga/YogaLayoutType.java | 35 ---------------------- java/com/facebook/yoga/YogaLayoutType.kt | 27 +++++++++++++++++ 2 files changed, 27 insertions(+), 35 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaLayoutType.java create mode 100644 java/com/facebook/yoga/YogaLayoutType.kt diff --git a/java/com/facebook/yoga/YogaLayoutType.java b/java/com/facebook/yoga/YogaLayoutType.java deleted file mode 100644 index 8c861ff7..00000000 --- a/java/com/facebook/yoga/YogaLayoutType.java +++ /dev/null @@ -1,35 +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 enum YogaLayoutType { - LAYOUT(0), - MEASURE(1), - CACHED_LAYOUT(2), - CACHED_MEASURE(3); - - private final int mIntValue; - - YogaLayoutType(int intValue) { - mIntValue = intValue; - } - - public int intValue() { - return mIntValue; - } - - public static YogaLayoutType fromInt(int value) { - switch (value) { - case 0: return LAYOUT; - case 1: return MEASURE; - case 2: return CACHED_LAYOUT; - case 3: return CACHED_MEASURE; - default: throw new IllegalArgumentException("Unknown enum value: " + value); - } - } -} diff --git a/java/com/facebook/yoga/YogaLayoutType.kt b/java/com/facebook/yoga/YogaLayoutType.kt new file mode 100644 index 00000000..6177a412 --- /dev/null +++ b/java/com/facebook/yoga/YogaLayoutType.kt @@ -0,0 +1,27 @@ +/* + * 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 enum class YogaLayoutType(public val intValue: Int) { + LAYOUT(0), + MEASURE(1), + CACHED_LAYOUT(2), + CACHED_MEASURE(3); + + public companion object { + @JvmStatic + public fun fromInt(value: Int): YogaLayoutType = + when (value) { + 0 -> LAYOUT + 1 -> MEASURE + 2 -> CACHED_LAYOUT + 3 -> CACHED_MEASURE + else -> throw IllegalArgumentException("Unknown enum value: $value") + } + } +} From 499a825836f3e066162c9f4ca1d27f96028f6563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Tue, 12 Aug 2025 10:54:27 -0700 Subject: [PATCH 09/14] Migrate `DoNotStrip` to Kotlin (#1840) Summary: Migrate com.facebook.yoga.annotations.DoNotStrip to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1840 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897758 Pulled By: cortinico fbshipit-source-id: 79585e6ab793bd72e04440581d866f7721667db3 --- .../facebook/yoga/annotations/DoNotStrip.java | 18 ------------------ .../facebook/yoga/annotations/DoNotStrip.kt | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 18 deletions(-) delete mode 100644 java/com/facebook/yoga/annotations/DoNotStrip.java create mode 100644 java/com/facebook/yoga/annotations/DoNotStrip.kt diff --git a/java/com/facebook/yoga/annotations/DoNotStrip.java b/java/com/facebook/yoga/annotations/DoNotStrip.java deleted file mode 100644 index 574d3562..00000000 --- a/java/com/facebook/yoga/annotations/DoNotStrip.java +++ /dev/null @@ -1,18 +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.annotations; - -import java.lang.annotation.ElementType; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -import static java.lang.annotation.RetentionPolicy.CLASS; - -@Target({ ElementType.TYPE, ElementType.FIELD, ElementType.METHOD, ElementType.CONSTRUCTOR }) -@Retention(CLASS) -public @interface DoNotStrip { } diff --git a/java/com/facebook/yoga/annotations/DoNotStrip.kt b/java/com/facebook/yoga/annotations/DoNotStrip.kt new file mode 100644 index 00000000..c0890371 --- /dev/null +++ b/java/com/facebook/yoga/annotations/DoNotStrip.kt @@ -0,0 +1,18 @@ +/* + * 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.annotations + +@Target( + AnnotationTarget.CLASS, + AnnotationTarget.FIELD, + AnnotationTarget.FUNCTION, + AnnotationTarget.PROPERTY_GETTER, + AnnotationTarget.PROPERTY_SETTER, + AnnotationTarget.CONSTRUCTOR) +@Retention(AnnotationRetention.BINARY) +public annotation class DoNotStrip From bf1cbd29c068f071c41551e3abb3260476576cef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Wed, 13 Aug 2025 06:46:48 -0700 Subject: [PATCH 10/14] Migrate `YogaConfigFactory` to Kotlin (#1833) Summary: Migrate com.facebook.yoga.YogaConfigFactory to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1833 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897762 Pulled By: cortinico fbshipit-source-id: 9457b307204f2066a02690f96a88fce6755f915e --- .../yoga/{YogaConfigFactory.java => YogaConfigFactory.kt} | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) rename java/com/facebook/yoga/{YogaConfigFactory.java => YogaConfigFactory.kt} (56%) diff --git a/java/com/facebook/yoga/YogaConfigFactory.java b/java/com/facebook/yoga/YogaConfigFactory.kt similarity index 56% rename from java/com/facebook/yoga/YogaConfigFactory.java rename to java/com/facebook/yoga/YogaConfigFactory.kt index 631545fa..ddee4e60 100644 --- a/java/com/facebook/yoga/YogaConfigFactory.java +++ b/java/com/facebook/yoga/YogaConfigFactory.kt @@ -5,10 +5,8 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.yoga; +package com.facebook.yoga -public abstract class YogaConfigFactory { - public static YogaConfig create() { - return new YogaConfigJNIFinalizer(); - } +public object YogaConfigFactory { + @JvmStatic public fun create(): YogaConfig = YogaConfigJNIFinalizer() } From c582f7caa6e87bff1ae3dfafadfe38033b2dcaff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Wed, 13 Aug 2025 08:56:03 -0700 Subject: [PATCH 11/14] Migrate `YogaNative` to Kotlin (#1839) Summary: Migrate com.facebook.yoga.YogaNative to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1839 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897725 Pulled By: cortinico fbshipit-source-id: 6fc98565368d831b8698464fe26ad47f8fff6a74 --- java/com/facebook/yoga/YogaNative.java | 141 ----------- java/com/facebook/yoga/YogaNative.kt | 331 +++++++++++++++++++++++++ 2 files changed, 331 insertions(+), 141 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaNative.java create mode 100644 java/com/facebook/yoga/YogaNative.kt diff --git a/java/com/facebook/yoga/YogaNative.java b/java/com/facebook/yoga/YogaNative.java deleted file mode 100644 index 8d23257a..00000000 --- a/java/com/facebook/yoga/YogaNative.java +++ /dev/null @@ -1,141 +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; - -import com.facebook.yoga.annotations.DoNotStrip; -import com.facebook.soloader.SoLoader; - -@DoNotStrip -public class YogaNative { - static { - SoLoader.loadLibrary("yoga"); - } - - // JNI methods that use Vanilla JNI - // YGConfig related - static native long jni_YGConfigNewJNI(); - static native void jni_YGConfigFreeJNI(long nativePointer); - static native void jni_YGConfigSetExperimentalFeatureEnabledJNI(long nativePointer, int feature, boolean enabled); - static native void jni_YGConfigSetUseWebDefaultsJNI(long nativePointer, boolean useWebDefaults); - static native void jni_YGConfigSetPointScaleFactorJNI(long nativePointer, float pixelsInPoint); - static native void jni_YGConfigSetErrataJNI(long nativePointer, int errata); - static native int jni_YGConfigGetErrataJNI(long nativePointer); - static native void jni_YGConfigSetLoggerJNI(long nativePointer, YogaLogger logger); - - // YGNode related - static native long jni_YGNodeNewJNI(); - static native long jni_YGNodeNewWithConfigJNI(long configPointer); - static native void jni_YGNodeFinalizeJNI(long nativePointer); - static native void jni_YGNodeResetJNI(long nativePointer); - static native void jni_YGNodeInsertChildJNI(long nativePointer, long childPointer, int index); - static native void jni_YGNodeSwapChildJNI(long nativePointer, long childPointer, int index); - static native void jni_YGNodeSetIsReferenceBaselineJNI(long nativePointer, boolean isReferenceBaseline); - static native boolean jni_YGNodeIsReferenceBaselineJNI(long nativePointer); - static native void jni_YGNodeRemoveAllChildrenJNI(long nativePointer); - static native void jni_YGNodeRemoveChildJNI(long nativePointer, long childPointer); - static native void jni_YGNodeCalculateLayoutJNI(long nativePointer, float width, float height, long[] nativePointers, YogaNodeJNIBase[] nodes); - static native void jni_YGNodeMarkDirtyJNI(long nativePointer); - static native boolean jni_YGNodeIsDirtyJNI(long nativePointer); - static native void jni_YGNodeCopyStyleJNI(long dstNativePointer, long srcNativePointer); - static native int jni_YGNodeStyleGetDirectionJNI(long nativePointer); - static native void jni_YGNodeStyleSetDirectionJNI(long nativePointer, int direction); - static native int jni_YGNodeStyleGetFlexDirectionJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexDirectionJNI(long nativePointer, int flexDirection); - static native int jni_YGNodeStyleGetJustifyContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetJustifyContentJNI(long nativePointer, int justifyContent); - static native int jni_YGNodeStyleGetAlignItemsJNI(long nativePointer); - static native void jni_YGNodeStyleSetAlignItemsJNI(long nativePointer, int alignItems); - static native int jni_YGNodeStyleGetAlignSelfJNI(long nativePointer); - static native void jni_YGNodeStyleSetAlignSelfJNI(long nativePointer, int alignSelf); - static native int jni_YGNodeStyleGetAlignContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetAlignContentJNI(long nativePointer, int alignContent); - static native int jni_YGNodeStyleGetPositionTypeJNI(long nativePointer); - static native void jni_YGNodeStyleSetPositionTypeJNI(long nativePointer, int positionType); - static native int jni_YGNodeStyleGetBoxSizingJNI(long nativePointer); - static native void jni_YGNodeStyleSetBoxSizingJNI(long nativePointer, int boxSizing); - static native int jni_YGNodeStyleGetFlexWrapJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexWrapJNI(long nativePointer, int wrapType); - static native int jni_YGNodeStyleGetOverflowJNI(long nativePointer); - static native void jni_YGNodeStyleSetOverflowJNI(long nativePointer, int overflow); - static native int jni_YGNodeStyleGetDisplayJNI(long nativePointer); - static native void jni_YGNodeStyleSetDisplayJNI(long nativePointer, int display); - static native float jni_YGNodeStyleGetFlexJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexJNI(long nativePointer, float flex); - static native float jni_YGNodeStyleGetFlexGrowJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexGrowJNI(long nativePointer, float flexGrow); - static native float jni_YGNodeStyleGetFlexShrinkJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexShrinkJNI(long nativePointer, float flexShrink); - static native long jni_YGNodeStyleGetFlexBasisJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexBasisJNI(long nativePointer, float flexBasis); - static native void jni_YGNodeStyleSetFlexBasisPercentJNI(long nativePointer, float percent); - static native void jni_YGNodeStyleSetFlexBasisAutoJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexBasisMaxContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexBasisFitContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetFlexBasisStretchJNI(long nativePointer); - static native long jni_YGNodeStyleGetMarginJNI(long nativePointer, int edge); - static native void jni_YGNodeStyleSetMarginJNI(long nativePointer, int edge, float margin); - static native void jni_YGNodeStyleSetMarginPercentJNI(long nativePointer, int edge, float percent); - static native void jni_YGNodeStyleSetMarginAutoJNI(long nativePointer, int edge); - static native long jni_YGNodeStyleGetPaddingJNI(long nativePointer, int edge); - static native void jni_YGNodeStyleSetPaddingJNI(long nativePointer, int edge, float padding); - static native void jni_YGNodeStyleSetPaddingPercentJNI(long nativePointer, int edge, float percent); - static native float jni_YGNodeStyleGetBorderJNI(long nativePointer, int edge); - static native void jni_YGNodeStyleSetBorderJNI(long nativePointer, int edge, float border); - static native long jni_YGNodeStyleGetPositionJNI(long nativePointer, int edge); - static native void jni_YGNodeStyleSetPositionJNI(long nativePointer, int edge, float position); - static native void jni_YGNodeStyleSetPositionPercentJNI(long nativePointer, int edge, float percent); - static native void jni_YGNodeStyleSetPositionAutoJNI(long nativePointer, int edge); - static native long jni_YGNodeStyleGetWidthJNI(long nativePointer); - static native void jni_YGNodeStyleSetWidthJNI(long nativePointer, float width); - static native void jni_YGNodeStyleSetWidthPercentJNI(long nativePointer, float percent); - static native void jni_YGNodeStyleSetWidthAutoJNI(long nativePointer); - static native void jni_YGNodeStyleSetWidthMaxContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetWidthFitContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetWidthStretchJNI(long nativePointer); - static native long jni_YGNodeStyleGetHeightJNI(long nativePointer); - static native void jni_YGNodeStyleSetHeightJNI(long nativePointer, float height); - static native void jni_YGNodeStyleSetHeightPercentJNI(long nativePointer, float percent); - static native void jni_YGNodeStyleSetHeightAutoJNI(long nativePointer); - static native void jni_YGNodeStyleSetHeightMaxContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetHeightFitContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetHeightStretchJNI(long nativePointer); - static native long jni_YGNodeStyleGetMinWidthJNI(long nativePointer); - static native void jni_YGNodeStyleSetMinWidthJNI(long nativePointer, float minWidth); - static native void jni_YGNodeStyleSetMinWidthPercentJNI(long nativePointer, float percent); - static native void jni_YGNodeStyleSetMinWidthMaxContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMinWidthFitContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMinWidthStretchJNI(long nativePointer); - static native long jni_YGNodeStyleGetMinHeightJNI(long nativePointer); - static native void jni_YGNodeStyleSetMinHeightJNI(long nativePointer, float minHeight); - static native void jni_YGNodeStyleSetMinHeightPercentJNI(long nativePointer, float percent); - static native void jni_YGNodeStyleSetMinHeightMaxContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMinHeightFitContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMinHeightStretchJNI(long nativePointer); - static native long jni_YGNodeStyleGetMaxWidthJNI(long nativePointer); - static native void jni_YGNodeStyleSetMaxWidthJNI(long nativePointer, float maxWidth); - static native void jni_YGNodeStyleSetMaxWidthPercentJNI(long nativePointer, float percent); - static native void jni_YGNodeStyleSetMaxWidthMaxContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMaxWidthFitContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMaxWidthStretchJNI(long nativePointer); - static native long jni_YGNodeStyleGetMaxHeightJNI(long nativePointer); - static native void jni_YGNodeStyleSetMaxHeightJNI(long nativePointer, float maxheight); - static native void jni_YGNodeStyleSetMaxHeightPercentJNI(long nativePointer, float percent); - static native void jni_YGNodeStyleSetMaxHeightMaxContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMaxHeightFitContentJNI(long nativePointer); - static native void jni_YGNodeStyleSetMaxHeightStretchJNI(long nativePointer); - static native float jni_YGNodeStyleGetAspectRatioJNI(long nativePointer); - static native void jni_YGNodeStyleSetAspectRatioJNI(long nativePointer, float aspectRatio); - static native long jni_YGNodeStyleGetGapJNI(long nativePointer, int gutter); - static native void jni_YGNodeStyleSetGapJNI(long nativePointer, int gutter, float gapLength); - static native void jni_YGNodeStyleSetGapPercentJNI(long nativePointer, int gutter, float gapLength); - static native void jni_YGNodeSetHasMeasureFuncJNI(long nativePointer, boolean hasMeasureFunc); - static native void jni_YGNodeSetHasBaselineFuncJNI(long nativePointer, boolean hasMeasureFunc); - static native void jni_YGNodeSetStyleInputsJNI(long nativePointer, float[] styleInputsArray, int size); - static native long jni_YGNodeCloneJNI(long nativePointer); - static native void jni_YGNodeSetAlwaysFormsContainingBlockJNI(long nativePointer, boolean alwaysFormContainingBlock); -} diff --git a/java/com/facebook/yoga/YogaNative.kt b/java/com/facebook/yoga/YogaNative.kt new file mode 100644 index 00000000..518326d4 --- /dev/null +++ b/java/com/facebook/yoga/YogaNative.kt @@ -0,0 +1,331 @@ +/* + * 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 + +import com.facebook.soloader.SoLoader +import com.facebook.yoga.annotations.DoNotStrip + +@DoNotStrip +public object YogaNative { + init { + SoLoader.loadLibrary("yoga") + } + + // JNI methods that use Vanilla JNI + // YGConfig related + @JvmStatic public external fun jni_YGConfigNewJNI(): Long + + @JvmStatic public external fun jni_YGConfigFreeJNI(nativePointer: Long) + + @JvmStatic + public external fun jni_YGConfigSetExperimentalFeatureEnabledJNI( + nativePointer: Long, + feature: Int, + enabled: Boolean + ) + + @JvmStatic + public external fun jni_YGConfigSetUseWebDefaultsJNI(nativePointer: Long, useWebDefaults: Boolean) + + @JvmStatic + public external fun jni_YGConfigSetPointScaleFactorJNI(nativePointer: Long, pixelsInPoint: Float) + + @JvmStatic public external fun jni_YGConfigSetErrataJNI(nativePointer: Long, errata: Int) + + @JvmStatic public external fun jni_YGConfigGetErrataJNI(nativePointer: Long): Int + + @JvmStatic public external fun jni_YGConfigSetLoggerJNI(nativePointer: Long, logger: YogaLogger) + + // YGNode related + @JvmStatic public external fun jni_YGNodeNewJNI(): Long + + @JvmStatic public external fun jni_YGNodeNewWithConfigJNI(configPointer: Long): Long + + @JvmStatic public external fun jni_YGNodeFinalizeJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeResetJNI(nativePointer: Long) + + @JvmStatic + public external fun jni_YGNodeInsertChildJNI(nativePointer: Long, childPointer: Long, index: Int) + + @JvmStatic + public external fun jni_YGNodeSwapChildJNI(nativePointer: Long, childPointer: Long, index: Int) + + @JvmStatic + public external fun jni_YGNodeSetIsReferenceBaselineJNI( + nativePointer: Long, + isReferenceBaseline: Boolean + ) + + @JvmStatic public external fun jni_YGNodeIsReferenceBaselineJNI(nativePointer: Long): Boolean + + @JvmStatic public external fun jni_YGNodeRemoveAllChildrenJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeRemoveChildJNI(nativePointer: Long, childPointer: Long) + + @JvmStatic + public external fun jni_YGNodeCalculateLayoutJNI( + nativePointer: Long, + width: Float, + height: Float, + nativePointers: LongArray, + nodes: Array + ) + + @JvmStatic public external fun jni_YGNodeMarkDirtyJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeIsDirtyJNI(nativePointer: Long): Boolean + + @JvmStatic + public external fun jni_YGNodeCopyStyleJNI(dstNativePointer: Long, srcNativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetDirectionJNI(nativePointer: Long): Int + + @JvmStatic public external fun jni_YGNodeStyleSetDirectionJNI(nativePointer: Long, direction: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetFlexDirectionJNI(nativePointer: Long): Int + + @JvmStatic + public external fun jni_YGNodeStyleSetFlexDirectionJNI(nativePointer: Long, flexDirection: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetJustifyContentJNI(nativePointer: Long): Int + + @JvmStatic + public external fun jni_YGNodeStyleSetJustifyContentJNI(nativePointer: Long, justifyContent: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetAlignItemsJNI(nativePointer: Long): Int + + @JvmStatic + public external fun jni_YGNodeStyleSetAlignItemsJNI(nativePointer: Long, alignItems: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetAlignSelfJNI(nativePointer: Long): Int + + @JvmStatic public external fun jni_YGNodeStyleSetAlignSelfJNI(nativePointer: Long, alignSelf: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetAlignContentJNI(nativePointer: Long): Int + + @JvmStatic + public external fun jni_YGNodeStyleSetAlignContentJNI(nativePointer: Long, alignContent: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetPositionTypeJNI(nativePointer: Long): Int + + @JvmStatic + public external fun jni_YGNodeStyleSetPositionTypeJNI(nativePointer: Long, positionType: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetBoxSizingJNI(nativePointer: Long): Int + + @JvmStatic public external fun jni_YGNodeStyleSetBoxSizingJNI(nativePointer: Long, boxSizing: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetFlexWrapJNI(nativePointer: Long): Int + + @JvmStatic public external fun jni_YGNodeStyleSetFlexWrapJNI(nativePointer: Long, wrapType: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetOverflowJNI(nativePointer: Long): Int + + @JvmStatic public external fun jni_YGNodeStyleSetOverflowJNI(nativePointer: Long, overflow: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetDisplayJNI(nativePointer: Long): Int + + @JvmStatic public external fun jni_YGNodeStyleSetDisplayJNI(nativePointer: Long, display: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetFlexJNI(nativePointer: Long): Float + + @JvmStatic public external fun jni_YGNodeStyleSetFlexJNI(nativePointer: Long, flex: Float) + + @JvmStatic public external fun jni_YGNodeStyleGetFlexGrowJNI(nativePointer: Long): Float + + @JvmStatic public external fun jni_YGNodeStyleSetFlexGrowJNI(nativePointer: Long, flexGrow: Float) + + @JvmStatic public external fun jni_YGNodeStyleGetFlexShrinkJNI(nativePointer: Long): Float + + @JvmStatic + public external fun jni_YGNodeStyleSetFlexShrinkJNI(nativePointer: Long, flexShrink: Float) + + @JvmStatic public external fun jni_YGNodeStyleGetFlexBasisJNI(nativePointer: Long): Long + + @JvmStatic + public external fun jni_YGNodeStyleSetFlexBasisJNI(nativePointer: Long, flexBasis: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetFlexBasisPercentJNI(nativePointer: Long, percent: Float) + + @JvmStatic public external fun jni_YGNodeStyleSetFlexBasisAutoJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetFlexBasisMaxContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetFlexBasisFitContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetFlexBasisStretchJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetMarginJNI(nativePointer: Long, edge: Int): Long + + @JvmStatic + public external fun jni_YGNodeStyleSetMarginJNI(nativePointer: Long, edge: Int, margin: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetMarginPercentJNI( + nativePointer: Long, + edge: Int, + percent: Float + ) + + @JvmStatic public external fun jni_YGNodeStyleSetMarginAutoJNI(nativePointer: Long, edge: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetPaddingJNI(nativePointer: Long, edge: Int): Long + + @JvmStatic + public external fun jni_YGNodeStyleSetPaddingJNI(nativePointer: Long, edge: Int, padding: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetPaddingPercentJNI( + nativePointer: Long, + edge: Int, + percent: Float + ) + + @JvmStatic public external fun jni_YGNodeStyleGetBorderJNI(nativePointer: Long, edge: Int): Float + + @JvmStatic + public external fun jni_YGNodeStyleSetBorderJNI(nativePointer: Long, edge: Int, border: Float) + + @JvmStatic public external fun jni_YGNodeStyleGetPositionJNI(nativePointer: Long, edge: Int): Long + + @JvmStatic + public external fun jni_YGNodeStyleSetPositionJNI(nativePointer: Long, edge: Int, position: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetPositionPercentJNI( + nativePointer: Long, + edge: Int, + percent: Float + ) + + @JvmStatic public external fun jni_YGNodeStyleSetPositionAutoJNI(nativePointer: Long, edge: Int) + + @JvmStatic public external fun jni_YGNodeStyleGetWidthJNI(nativePointer: Long): Long + + @JvmStatic public external fun jni_YGNodeStyleSetWidthJNI(nativePointer: Long, width: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetWidthPercentJNI(nativePointer: Long, percent: Float) + + @JvmStatic public external fun jni_YGNodeStyleSetWidthAutoJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetWidthMaxContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetWidthFitContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetWidthStretchJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetHeightJNI(nativePointer: Long): Long + + @JvmStatic public external fun jni_YGNodeStyleSetHeightJNI(nativePointer: Long, height: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetHeightPercentJNI(nativePointer: Long, percent: Float) + + @JvmStatic public external fun jni_YGNodeStyleSetHeightAutoJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetHeightMaxContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetHeightFitContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetHeightStretchJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetMinWidthJNI(nativePointer: Long): Long + + @JvmStatic public external fun jni_YGNodeStyleSetMinWidthJNI(nativePointer: Long, minWidth: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetMinWidthPercentJNI(nativePointer: Long, percent: Float) + + @JvmStatic public external fun jni_YGNodeStyleSetMinWidthMaxContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMinWidthFitContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMinWidthStretchJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetMinHeightJNI(nativePointer: Long): Long + + @JvmStatic + public external fun jni_YGNodeStyleSetMinHeightJNI(nativePointer: Long, minHeight: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetMinHeightPercentJNI(nativePointer: Long, percent: Float) + + @JvmStatic public external fun jni_YGNodeStyleSetMinHeightMaxContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMinHeightFitContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMinHeightStretchJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetMaxWidthJNI(nativePointer: Long): Long + + @JvmStatic public external fun jni_YGNodeStyleSetMaxWidthJNI(nativePointer: Long, maxWidth: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetMaxWidthPercentJNI(nativePointer: Long, percent: Float) + + @JvmStatic public external fun jni_YGNodeStyleSetMaxWidthMaxContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMaxWidthFitContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMaxWidthStretchJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetMaxHeightJNI(nativePointer: Long): Long + + @JvmStatic + public external fun jni_YGNodeStyleSetMaxHeightJNI(nativePointer: Long, maxheight: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetMaxHeightPercentJNI(nativePointer: Long, percent: Float) + + @JvmStatic public external fun jni_YGNodeStyleSetMaxHeightMaxContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMaxHeightFitContentJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleSetMaxHeightStretchJNI(nativePointer: Long) + + @JvmStatic public external fun jni_YGNodeStyleGetAspectRatioJNI(nativePointer: Long): Float + + @JvmStatic + public external fun jni_YGNodeStyleSetAspectRatioJNI(nativePointer: Long, aspectRatio: Float) + + @JvmStatic public external fun jni_YGNodeStyleGetGapJNI(nativePointer: Long, gutter: Int): Long + + @JvmStatic + public external fun jni_YGNodeStyleSetGapJNI(nativePointer: Long, gutter: Int, gapLength: Float) + + @JvmStatic + public external fun jni_YGNodeStyleSetGapPercentJNI( + nativePointer: Long, + gutter: Int, + gapLength: Float + ) + + @JvmStatic + public external fun jni_YGNodeSetHasMeasureFuncJNI(nativePointer: Long, hasMeasureFunc: Boolean) + + @JvmStatic + public external fun jni_YGNodeSetHasBaselineFuncJNI(nativePointer: Long, hasMeasureFunc: Boolean) + + @JvmStatic + public external fun jni_YGNodeSetStyleInputsJNI( + nativePointer: Long, + styleInputsArray: FloatArray, + size: Int + ) + + @JvmStatic public external fun jni_YGNodeCloneJNI(nativePointer: Long): Long + + @JvmStatic + public external fun jni_YGNodeSetAlwaysFormsContainingBlockJNI( + nativePointer: Long, + alwaysFormContainingBlock: Boolean + ) +} From 93bea176358580017259ad6690f291d77229782d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Wed, 13 Aug 2025 16:45:06 -0700 Subject: [PATCH 12/14] Migrate `YogaValue` to Kotlin (#1838) Summary: Migrate com.facebook.yoga.YogaValue to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1838 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897668 Pulled By: cortinico fbshipit-source-id: dffe2b29087c35e4797f46dea756c51f841590d8 --- java/com/facebook/yoga/YogaValue.java | 80 --------------------------- java/com/facebook/yoga/YogaValue.kt | 66 ++++++++++++++++++++++ 2 files changed, 66 insertions(+), 80 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaValue.java create mode 100644 java/com/facebook/yoga/YogaValue.kt diff --git a/java/com/facebook/yoga/YogaValue.java b/java/com/facebook/yoga/YogaValue.java deleted file mode 100644 index 2a266b02..00000000 --- a/java/com/facebook/yoga/YogaValue.java +++ /dev/null @@ -1,80 +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 class YogaValue { - static final YogaValue UNDEFINED = new YogaValue(YogaConstants.UNDEFINED, YogaUnit.UNDEFINED); - static final YogaValue ZERO = new YogaValue(0, YogaUnit.POINT); - static final YogaValue AUTO = new YogaValue(YogaConstants.UNDEFINED, YogaUnit.AUTO); - - public final float value; - public final YogaUnit unit; - - public YogaValue(float value, YogaUnit unit) { - this.value = value; - this.unit = unit; - } - - YogaValue(float value, int unit) { - this(value, YogaUnit.fromInt(unit)); - } - - @Override - public boolean equals(Object other) { - if (other instanceof YogaValue) { - final YogaValue otherValue = (YogaValue) other; - if (unit == otherValue.unit) { - return unit == YogaUnit.UNDEFINED - || unit == YogaUnit.AUTO - || Float.compare(value, otherValue.value) == 0; - } - } - return false; - } - - @Override - public int hashCode() { - return Float.floatToIntBits(value) + unit.intValue(); - } - - @Override - public String toString() { - switch (unit) { - case UNDEFINED: - return "undefined"; - case POINT: - return Float.toString(value); - case PERCENT: - return value + "%"; - case AUTO: - return "auto"; - default: - throw new IllegalStateException(); - } - } - - public static YogaValue parse(String s) { - if (s == null) { - return null; - } - - if ("undefined".equals(s)) { - return UNDEFINED; - } - - if ("auto".equals(s)) { - return AUTO; - } - - if (s.endsWith("%")) { - return new YogaValue(Float.parseFloat(s.substring(0, s.length() - 1)), YogaUnit.PERCENT); - } - - return new YogaValue(Float.parseFloat(s), YogaUnit.POINT); - } -} diff --git a/java/com/facebook/yoga/YogaValue.kt b/java/com/facebook/yoga/YogaValue.kt new file mode 100644 index 00000000..ceaf6278 --- /dev/null +++ b/java/com/facebook/yoga/YogaValue.kt @@ -0,0 +1,66 @@ +/* + * 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 class YogaValue +public constructor(@JvmField public val value: Float, @JvmField public val unit: YogaUnit) { + internal constructor(value: Float, unit: Int) : this(value, YogaUnit.fromInt(unit)) + + override fun equals(other: Any?): Boolean { + if (other is YogaValue) { + val otherValue = other + if (unit == otherValue.unit) { + return unit == YogaUnit.UNDEFINED || + unit == YogaUnit.AUTO || + value.compareTo(otherValue.value) == 0 + } + } + return false + } + + override fun hashCode(): Int = java.lang.Float.floatToIntBits(value) + unit.intValue() + + override fun toString(): String = + when (unit) { + YogaUnit.UNDEFINED -> "undefined" + YogaUnit.POINT -> value.toString() + YogaUnit.PERCENT -> "$value%" + YogaUnit.AUTO -> "auto" + else -> throw IllegalStateException() + } + + public companion object { + @JvmField + public val UNDEFINED: YogaValue = YogaValue(YogaConstants.UNDEFINED, YogaUnit.UNDEFINED) + + @JvmField public val ZERO: YogaValue = YogaValue(0f, YogaUnit.POINT) + + @JvmField public val AUTO: YogaValue = YogaValue(YogaConstants.UNDEFINED, YogaUnit.AUTO) + + @JvmStatic + public fun parse(s: String?): YogaValue? { + if (s == null) { + return null + } + + if ("undefined" == s) { + return UNDEFINED + } + + if ("auto" == s) { + return AUTO + } + + if (s.endsWith("%")) { + return YogaValue(s.substring(0, s.length - 1).toFloat(), YogaUnit.PERCENT) + } + + return YogaValue(s.toFloat(), YogaUnit.POINT) + } + } +} From d1246f6f0d59fdbf2f2f2fbd6c355b50d6c41318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nivaldo=20Bondan=C3=A7a?= Date: Thu, 14 Aug 2025 07:24:42 -0700 Subject: [PATCH 13/14] Codemod format for trailing commas incoming change [5/n] (#1847) Summary: X-link: https://github.com/facebook/react-native/pull/53260 Pull Request resolved: https://github.com/facebook/yoga/pull/1847 Adding trailing commas. Reviewed By: cortinico Differential Revision: D80174965 fbshipit-source-id: 5438fa9ebce13525b1286dd30704138ef99703cb --- java/com/facebook/yoga/YogaMeasureFunction.kt | 2 +- java/com/facebook/yoga/annotations/DoNotStrip.kt | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/java/com/facebook/yoga/YogaMeasureFunction.kt b/java/com/facebook/yoga/YogaMeasureFunction.kt index 10b5cfc0..53109a08 100644 --- a/java/com/facebook/yoga/YogaMeasureFunction.kt +++ b/java/com/facebook/yoga/YogaMeasureFunction.kt @@ -14,6 +14,6 @@ public fun interface YogaMeasureFunction { width: Float, widthMode: YogaMeasureMode, height: Float, - heightMode: YogaMeasureMode + heightMode: YogaMeasureMode, ): Long } diff --git a/java/com/facebook/yoga/annotations/DoNotStrip.kt b/java/com/facebook/yoga/annotations/DoNotStrip.kt index c0890371..532bb060 100644 --- a/java/com/facebook/yoga/annotations/DoNotStrip.kt +++ b/java/com/facebook/yoga/annotations/DoNotStrip.kt @@ -13,6 +13,7 @@ package com.facebook.yoga.annotations AnnotationTarget.FUNCTION, AnnotationTarget.PROPERTY_GETTER, AnnotationTarget.PROPERTY_SETTER, - AnnotationTarget.CONSTRUCTOR) + AnnotationTarget.CONSTRUCTOR, +) @Retention(AnnotationRetention.BINARY) public annotation class DoNotStrip From 89fc1601515d8686112ec91c0068c7e09e6cc3a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateo=20Guzm=C3=A1n?= Date: Thu, 14 Aug 2025 07:29:26 -0700 Subject: [PATCH 14/14] Migrate `YogaConfig` to Kotlin (#1841) Summary: Migrate com.facebook.yoga.YogaConfig to Kotlin. Pull Request resolved: https://github.com/facebook/yoga/pull/1841 Test Plan: RN ```sh yarn android yarn test-android ``` Yoga ```sh ./gradlew :yoga:assembleDebug ``` Reviewed By: rshest Differential Revision: D79897694 Pulled By: cortinico fbshipit-source-id: 0eff36f47bbb8da6a91087f2ea69bc4e40a732ac --- java/com/facebook/yoga/YogaConfig.java | 29 ---------------------- java/com/facebook/yoga/YogaConfig.kt | 33 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 29 deletions(-) delete mode 100644 java/com/facebook/yoga/YogaConfig.java create mode 100644 java/com/facebook/yoga/YogaConfig.kt diff --git a/java/com/facebook/yoga/YogaConfig.java b/java/com/facebook/yoga/YogaConfig.java deleted file mode 100644 index c841acd7..00000000 --- a/java/com/facebook/yoga/YogaConfig.java +++ /dev/null @@ -1,29 +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 abstract class YogaConfig { - - public static int SPACING_TYPE = 1; - - public abstract void setExperimentalFeatureEnabled(YogaExperimentalFeature feature, boolean enabled); - - public abstract void setUseWebDefaults(boolean useWebDefaults); - - public abstract void setPointScaleFactor(float pixelsInPoint); - - public abstract void setErrata(YogaErrata errata); - - public abstract YogaErrata getErrata(); - - public abstract void setLogger(YogaLogger logger); - - public abstract YogaLogger getLogger(); - - protected abstract long getNativePointer(); -} diff --git a/java/com/facebook/yoga/YogaConfig.kt b/java/com/facebook/yoga/YogaConfig.kt new file mode 100644 index 00000000..cdf6cfaa --- /dev/null +++ b/java/com/facebook/yoga/YogaConfig.kt @@ -0,0 +1,33 @@ +/* + * 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 abstract class YogaConfig { + public abstract fun setExperimentalFeatureEnabled( + feature: YogaExperimentalFeature, + enabled: Boolean + ) + + public abstract fun setUseWebDefaults(useWebDefaults: Boolean) + + public abstract fun setPointScaleFactor(pixelsInPoint: Float) + + public abstract fun setErrata(errata: YogaErrata) + + public abstract fun getErrata(): YogaErrata + + public abstract fun setLogger(logger: YogaLogger) + + public abstract fun getLogger(): YogaLogger + + protected abstract fun getNativePointer(): Long + + public companion object { + public var SPACING_TYPE: Int = 1 + } +}