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] 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()) +}