From b500dec2fa2a12dc1344a45f36406e0e3c577ba6 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:05:36 -0700 Subject: [PATCH 1/8] Kotlinify LayoutCreateAnimation (#43740) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43740 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Differential Revision: https://internalfb.com/D55588908 --- ...CreateAnimation.java => LayoutCreateAnimation.kt} | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/{LayoutCreateAnimation.java => LayoutCreateAnimation.kt} (58%) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutCreateAnimation.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutCreateAnimation.kt similarity index 58% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutCreateAnimation.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutCreateAnimation.kt index f103cc69ac0c..4392b552ea71 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutCreateAnimation.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutCreateAnimation.kt @@ -5,19 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.uimanager.layoutanimation; - -import com.facebook.infer.annotation.Nullsafe; +package com.facebook.react.uimanager.layoutanimation /** * Class responsible for handling layout view creation animation, applied to view whenever a valid * config was supplied for the layout animation of CREATE type. */ -/* package */ @Nullsafe(Nullsafe.Mode.LOCAL) -class LayoutCreateAnimation extends BaseLayoutAnimation { +internal class LayoutCreateAnimation : BaseLayoutAnimation() { - @Override - boolean isReverse() { - return false; - } + override fun isReverse(): Boolean = false } From 6d1fdb0281405cc97cbaafec35ea1088b3c79dff Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:05:36 -0700 Subject: [PATCH 2/8] Kotlinify LayoutDeleteAnimation (#43741) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43741 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Differential Revision: https://internalfb.com/D55589024 --- ...DeleteAnimation.java => LayoutDeleteAnimation.kt} | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/{LayoutDeleteAnimation.java => LayoutDeleteAnimation.kt} (58%) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutDeleteAnimation.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutDeleteAnimation.kt similarity index 58% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutDeleteAnimation.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutDeleteAnimation.kt index 1550cb642534..83221a93aed8 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutDeleteAnimation.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/layoutanimation/LayoutDeleteAnimation.kt @@ -5,19 +5,13 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.uimanager.layoutanimation; - -import com.facebook.infer.annotation.Nullsafe; +package com.facebook.react.uimanager.layoutanimation /** * Class responsible for handling layout view deletion animation, applied to view whenever a valid * config was supplied for the layout animation of DELETE type. */ -/* package */ @Nullsafe(Nullsafe.Mode.LOCAL) -class LayoutDeleteAnimation extends BaseLayoutAnimation { +internal class LayoutDeleteAnimation : BaseLayoutAnimation() { - @Override - boolean isReverse() { - return true; - } + override fun isReverse(): Boolean = true } From 373e8961a129504628c84072c794b443980967be Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:05:36 -0700 Subject: [PATCH 3/8] Kotlinify InspectorFlags Differential Revision: D55637558 --- .../ReactAndroid/api/ReactAndroid.api | 7 +++-- .../react/devsupport/InspectorFlags.java | 28 ------------------- .../react/devsupport/InspectorFlags.kt | 22 +++++++++++++++ 3 files changed, 26 insertions(+), 31 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 3e83c253a622..2263cd1b71b7 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -2164,9 +2164,10 @@ public abstract interface class com/facebook/react/devsupport/HMRClient : com/fa public abstract fun setup (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;IZ)V } -public class com/facebook/react/devsupport/InspectorFlags { - public static fun getEnableCxxInspectorPackagerConnection ()Z - public static fun getEnableModernCDPRegistry ()Z +public final class com/facebook/react/devsupport/InspectorFlags { + public static final field INSTANCE Lcom/facebook/react/devsupport/InspectorFlags; + public static final fun getEnableCxxInspectorPackagerConnection ()Z + public static final fun getEnableModernCDPRegistry ()Z } public class com/facebook/react/devsupport/InspectorPackagerConnection : com/facebook/react/devsupport/IInspectorPackagerConnection { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.java deleted file mode 100644 index 05480fb58bf4..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.java +++ /dev/null @@ -1,28 +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.react.devsupport; - -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.proguard.annotations.DoNotStrip; - -/** JNI wrapper for `jsinspector_modern::InspectorFlags`. */ -@Nullsafe(Nullsafe.Mode.LOCAL) -@DoNotStrip -public class InspectorFlags { - static { - DevSupportSoLoader.staticInit(); - } - - @DoNotStrip - public static native boolean getEnableModernCDPRegistry(); - - @DoNotStrip - public static native boolean getEnableCxxInspectorPackagerConnection(); - - private InspectorFlags() {} -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.kt new file mode 100644 index 000000000000..9b01f09c679d --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/InspectorFlags.kt @@ -0,0 +1,22 @@ +/* + * 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.react.devsupport + +import com.facebook.proguard.annotations.DoNotStrip + +/** JNI wrapper for `jsinspector_modern::InspectorFlags`. */ +@DoNotStrip +public object InspectorFlags { + init { + DevSupportSoLoader.staticInit() + } + + @DoNotStrip @JvmStatic public external fun getEnableModernCDPRegistry(): Boolean + + @DoNotStrip @JvmStatic public external fun getEnableCxxInspectorPackagerConnection(): Boolean +} From 6d13404a93d1d28f9308419a3f7b863d1ca559b7 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:05:36 -0700 Subject: [PATCH 4/8] Kotlinify ReactConstants Differential Revision: D55632715 --- .../react-native/ReactAndroid/api/ReactAndroid.api | 4 ++-- .../common/{ReactConstants.java => ReactConstants.kt} | 11 ++++------- 2 files changed, 6 insertions(+), 9 deletions(-) rename packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/{ReactConstants.java => ReactConstants.kt} (70%) diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 2263cd1b71b7..ee18ac616e92 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1727,10 +1727,10 @@ public final class com/facebook/react/common/MapBuilder$Builder { public fun put (Ljava/lang/Object;Ljava/lang/Object;)Lcom/facebook/react/common/MapBuilder$Builder; } -public class com/facebook/react/common/ReactConstants { +public final class com/facebook/react/common/ReactConstants { + public static final field INSTANCE Lcom/facebook/react/common/ReactConstants; public static final field TAG Ljava/lang/String; public static final field UNSET I - public fun ()V } public class com/facebook/react/common/ShakeDetector : android/hardware/SensorEventListener { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ReactConstants.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ReactConstants.kt similarity index 70% rename from packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ReactConstants.java rename to packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ReactConstants.kt index 98fa3b0ad0fa..265b840d957e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ReactConstants.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/common/ReactConstants.kt @@ -5,14 +5,11 @@ * LICENSE file in the root directory of this source tree. */ -package com.facebook.react.common; +package com.facebook.react.common -import com.facebook.infer.annotation.Nullsafe; +public object ReactConstants { -@Nullsafe(Nullsafe.Mode.LOCAL) -public class ReactConstants { - - public static final String TAG = "ReactNative"; + public const val TAG: String = "ReactNative" /** * Some types have built-in support for representing a "missing" or "unset" value, for example NaN @@ -20,5 +17,5 @@ public class ReactConstants { * have such a special value. When an integer represent an inherently non-negative value, we use a * special negative value to mark it as "unset". */ - public static final int UNSET = -1; + public const val UNSET: Int = -1 } From cf618a31e61eb9934e706d1f70e957747c0e3bb1 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:05:36 -0700 Subject: [PATCH 5/8] Kotlinify ReactInvalidPropertyException Differential Revision: D55633375 --- .../ReactAndroid/api/ReactAndroid.api | 2 +- .../ReactInvalidPropertyException.java | 24 ------------------- .../ReactInvalidPropertyException.kt | 16 +++++++++++++ 3 files changed, 17 insertions(+), 25 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index ee18ac616e92..c9f64e4b169a 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -4418,7 +4418,7 @@ public abstract interface class com/facebook/react/uimanager/ReactCompoundViewGr public abstract fun interceptsTouchEvent (FF)Z } -public class com/facebook/react/uimanager/ReactInvalidPropertyException : java/lang/RuntimeException { +public final class com/facebook/react/uimanager/ReactInvalidPropertyException : java/lang/RuntimeException { public fun (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.java deleted file mode 100644 index 63bdc3fa6377..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.java +++ /dev/null @@ -1,24 +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.react.uimanager; - -import com.facebook.infer.annotation.Nullsafe; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public class ReactInvalidPropertyException extends RuntimeException { - - public ReactInvalidPropertyException(String property, String value, String expectedValues) { - super( - "Invalid React property `" - + property - + "` with value `" - + value - + "`, expected " - + expectedValues); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.kt new file mode 100644 index 000000000000..4ae599fad30e --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactInvalidPropertyException.kt @@ -0,0 +1,16 @@ +/* + * 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.react.uimanager + +public class ReactInvalidPropertyException( + property: String, + value: String, + expectedValues: String +) : + RuntimeException( + "Invalid React property `$property` with value `$value`, expected $expectedValues") From 739f55714cc0316cb472b744bbedee1c6d74aa77 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:05:36 -0700 Subject: [PATCH 6/8] Kotlinify ReactYogaConfigProvider (#43773) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43773 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Differential Revision: https://internalfb.com/D55638955 --- .../ReactAndroid/api/ReactAndroid.api | 6 ++-- .../uimanager/ReactYogaConfigProvider.java | 28 ------------------- .../uimanager/ReactYogaConfigProvider.kt | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+), 31 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index c9f64e4b169a..335e1157d544 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -4750,9 +4750,9 @@ public class com/facebook/react/uimanager/ReactStylesDiffMap { public fun toString ()Ljava/lang/String; } -public class com/facebook/react/uimanager/ReactYogaConfigProvider { - public fun ()V - public static fun get ()Lcom/facebook/yoga/YogaConfig; +public final class com/facebook/react/uimanager/ReactYogaConfigProvider { + public static final field INSTANCE Lcom/facebook/react/uimanager/ReactYogaConfigProvider; + public static final fun get ()Lcom/facebook/yoga/YogaConfig; } public abstract interface class com/facebook/react/uimanager/ReactZIndexedViewGroup { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.java deleted file mode 100644 index 67c80d2c80f8..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.java +++ /dev/null @@ -1,28 +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.react.uimanager; - -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.yoga.YogaConfig; -import com.facebook.yoga.YogaConfigFactory; -import com.facebook.yoga.YogaErrata; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public class ReactYogaConfigProvider { - - private static YogaConfig YOGA_CONFIG; - - public static YogaConfig get() { - if (YOGA_CONFIG == null) { - YOGA_CONFIG = YogaConfigFactory.create(); - YOGA_CONFIG.setPointScaleFactor(0f); - YOGA_CONFIG.setErrata(YogaErrata.ALL); - } - return YOGA_CONFIG; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.kt new file mode 100644 index 000000000000..bcfdbc81b2cf --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactYogaConfigProvider.kt @@ -0,0 +1,28 @@ +/* + * 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.react.uimanager + +import com.facebook.yoga.YogaConfig +import com.facebook.yoga.YogaConfigFactory +import com.facebook.yoga.YogaErrata + +public object ReactYogaConfigProvider { + + private val yogaConfig: YogaConfig by + lazy(LazyThreadSafetyMode.NONE) { + val config = YogaConfigFactory.create() + config.setPointScaleFactor(0f) + config.setErrata(YogaErrata.ALL) + config + } + + @JvmStatic + public fun get(): YogaConfig { + return yogaConfig + } +} From 6d0e428f1508303d31e3735a718ee503560c03ba Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:05:36 -0700 Subject: [PATCH 7/8] Kotlinify ReactRootViewTagGenerator Differential Revision: D55637406 --- .../ReactAndroid/api/ReactAndroid.api | 6 ++--- .../uimanager/ReactRootViewTagGenerator.java | 27 ------------------- .../uimanager/ReactRootViewTagGenerator.kt | 22 +++++++++++++++ 3 files changed, 25 insertions(+), 30 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 335e1157d544..acdd42d8033e 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -4453,9 +4453,9 @@ public abstract interface class com/facebook/react/uimanager/ReactRoot { public abstract fun setShouldLogContentAppeared (Z)V } -public class com/facebook/react/uimanager/ReactRootViewTagGenerator { - public fun ()V - public static fun getNextRootViewTag ()I +public final class com/facebook/react/uimanager/ReactRootViewTagGenerator { + public static final field INSTANCE Lcom/facebook/react/uimanager/ReactRootViewTagGenerator; + public static final fun getNextRootViewTag ()I } public abstract interface class com/facebook/react/uimanager/ReactShadowNode { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.java deleted file mode 100644 index 6c128e202ec3..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.java +++ /dev/null @@ -1,27 +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.react.uimanager; - -import com.facebook.infer.annotation.Nullsafe; - -/** Incremental counter for React Root View tag. */ -@Nullsafe(Nullsafe.Mode.LOCAL) -public class ReactRootViewTagGenerator { - - // Keep in sync with ReactIOSTagHandles JS module - see that file for an explanation on why the - // increment here is 10. - private static final int ROOT_VIEW_TAG_INCREMENT = 10; - - private static int sNextRootViewTag = 1; - - public static synchronized int getNextRootViewTag() { - final int tag = sNextRootViewTag; - sNextRootViewTag += ROOT_VIEW_TAG_INCREMENT; - return tag; - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.kt new file mode 100644 index 000000000000..20081d8b0cce --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRootViewTagGenerator.kt @@ -0,0 +1,22 @@ +/* + * 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.react.uimanager + +/** Incremental counter for React Root View tag. */ +public object ReactRootViewTagGenerator { + + // Keep in sync with ReactIOSTagHandles JS module - see that file for an explanation on why the + // increment here is 10. + private const val ROOT_VIEW_TAG_INCREMENT = 10 + private var nextRootViewTag = 1 + + @JvmStatic + @Synchronized + public fun getNextRootViewTag(): Int = + nextRootViewTag.also { nextRootViewTag += ROOT_VIEW_TAG_INCREMENT } +} From dac44aa99082c35b144c6224ada060cd20df77c5 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 2 Apr 2024 10:06:14 -0700 Subject: [PATCH 8/8] Kotlinify MeasureUtil (#43769) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/43769 Changelog: [Internal] As part of the Sustainability Week (see [post](https://fb.workplace.com/groups/251759413609061/permalink/742797531171911/)). Reviewed By: cortinico Differential Revision: D55636884 --- .../ReactAndroid/api/ReactAndroid.api | 6 ++--- .../react/views/view/MeasureUtil.java | 26 ------------------- .../facebook/react/views/view/MeasureUtil.kt | 24 +++++++++++++++++ 3 files changed, 27 insertions(+), 29 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index acdd42d8033e..1cc1492a1548 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7513,9 +7513,9 @@ public class com/facebook/react/views/view/ColorUtil { public static fun normalize (DDDD)I } -public class com/facebook/react/views/view/MeasureUtil { - public fun ()V - public static fun getMeasureSpec (FLcom/facebook/yoga/YogaMeasureMode;)I +public final class com/facebook/react/views/view/MeasureUtil { + public static final field INSTANCE Lcom/facebook/react/views/view/MeasureUtil; + public static final fun getMeasureSpec (FLcom/facebook/yoga/YogaMeasureMode;)I } public abstract class com/facebook/react/views/view/ReactClippingViewManager : com/facebook/react/uimanager/ViewGroupManager { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java deleted file mode 100644 index 7d3fe5afdff0..000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.java +++ /dev/null @@ -1,26 +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.react.views.view; - -import android.view.View; -import com.facebook.infer.annotation.Nullsafe; -import com.facebook.yoga.YogaMeasureMode; - -@Nullsafe(Nullsafe.Mode.LOCAL) -public class MeasureUtil { - - public static int getMeasureSpec(float size, YogaMeasureMode mode) { - if (mode == YogaMeasureMode.EXACTLY) { - return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.EXACTLY); - } else if (mode == YogaMeasureMode.AT_MOST) { - return View.MeasureSpec.makeMeasureSpec((int) size, View.MeasureSpec.AT_MOST); - } else { - return View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); - } - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.kt new file mode 100644 index 000000000000..1aaf806a2d49 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/view/MeasureUtil.kt @@ -0,0 +1,24 @@ +/* + * 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.react.views.view + +import android.view.View +import com.facebook.yoga.YogaMeasureMode + +public object MeasureUtil { + + @JvmStatic + public fun getMeasureSpec(size: Float, mode: YogaMeasureMode): Int = + when (mode) { + YogaMeasureMode.EXACTLY -> + View.MeasureSpec.makeMeasureSpec(size.toInt(), View.MeasureSpec.EXACTLY) + YogaMeasureMode.AT_MOST -> + View.MeasureSpec.makeMeasureSpec(size.toInt(), View.MeasureSpec.AT_MOST) + else -> View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED) + } +}