From 6f59627903e67a4cad4b63bdbf237516e78f11a4 Mon Sep 17 00:00:00 2001 From: Fabrizio Cucci Date: Tue, 12 Nov 2024 08:30:35 -0800 Subject: [PATCH] Migrate com.facebook.react.views.text.ReactRawTextManager to Kotlin (#47571) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47571 As per title. Changelog: [Internal] Reviewed By: tdn120 Differential Revision: D65600851 fbshipit-source-id: cd88beca23f5d7b1036354457e67d0d530e62a95 --- .../ReactAndroid/api/ReactAndroid.api | 4 +- .../react/views/text/ReactRawTextManager.java | 55 ------------------- .../react/views/text/ReactRawTextManager.kt | 45 +++++++++++++++ 3 files changed, 47 insertions(+), 57 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index d6ead3d65e6..dc6775b82b7 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7276,7 +7276,8 @@ public final class com/facebook/react/views/text/ReactFontManager$Companion { public final fun getInstance ()Lcom/facebook/react/views/text/ReactFontManager; } -public class com/facebook/react/views/text/ReactRawTextManager : com/facebook/react/uimanager/ViewManager { +public final class com/facebook/react/views/text/ReactRawTextManager : com/facebook/react/uimanager/ViewManager { + public static final field REACT_CLASS Ljava/lang/String; public fun ()V public synthetic fun createShadowNodeInstance ()Lcom/facebook/react/uimanager/ReactShadowNode; public fun createShadowNodeInstance ()Lcom/facebook/react/views/text/ReactRawTextShadowNode; @@ -7284,7 +7285,6 @@ public class com/facebook/react/views/text/ReactRawTextManager : com/facebook/re public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Lcom/facebook/react/views/text/ReactTextView; public fun getName ()Ljava/lang/String; public fun getShadowNodeClass ()Ljava/lang/Class; - protected fun prepareToRecycleView (Lcom/facebook/react/uimanager/ThemedReactContext;Landroid/view/View;)Landroid/view/View; public fun updateExtraData (Landroid/view/View;Ljava/lang/Object;)V } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java deleted file mode 100644 index 4c2a87352f4..00000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.java +++ /dev/null @@ -1,55 +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.text; - -import android.view.View; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import com.facebook.react.common.annotations.VisibleForTesting; -import com.facebook.react.module.annotations.ReactModule; -import com.facebook.react.uimanager.ThemedReactContext; -import com.facebook.react.uimanager.ViewManager; - -/** - * Manages raw text nodes (aka {@code textContent} in terms of DOM). Since they are used only as a - * virtual nodes, any type of native view operation will throw an {@link IllegalStateException}. - */ -@ReactModule(name = ReactRawTextManager.REACT_CLASS) -public class ReactRawTextManager extends ViewManager { - - @VisibleForTesting public static final String REACT_CLASS = "RCTRawText"; - - @Override - public String getName() { - return REACT_CLASS; - } - - @Override - public ReactTextView createViewInstance(ThemedReactContext context) { - throw new IllegalStateException("Attempt to create a native view for RCTRawText"); - } - - @Override - protected @Nullable View prepareToRecycleView( - @NonNull ThemedReactContext reactContext, @NonNull View view) { - throw new IllegalStateException("Attempt to recycle a native view for RCTRawText"); - } - - @Override - public void updateExtraData(View view, Object extraData) {} - - @Override - public Class getShadowNodeClass() { - return ReactRawTextShadowNode.class; - } - - @Override - public ReactRawTextShadowNode createShadowNodeInstance() { - return new ReactRawTextShadowNode(); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.kt new file mode 100644 index 00000000000..215069d69cb --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactRawTextManager.kt @@ -0,0 +1,45 @@ +/* + * 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.text + +import android.view.View +import com.facebook.react.module.annotations.ReactModule +import com.facebook.react.uimanager.ThemedReactContext +import com.facebook.react.uimanager.ViewManager + +/** + * Manages raw text nodes (aka `textContent` in terms of DOM). Since they are used only as a virtual + * nodes, any type of native view operation will throw an [IllegalStateException]. + */ +@ReactModule(name = ReactRawTextManager.REACT_CLASS) +public class ReactRawTextManager : ViewManager() { + + override public fun getName(): String { + return REACT_CLASS + } + + override public fun createViewInstance(context: ThemedReactContext): ReactTextView = + throw IllegalStateException("Attempt to create a native view for RCTRawText") + + override protected fun prepareToRecycleView(reactContext: ThemedReactContext, view: View): View? = + throw IllegalStateException("Attempt to recycle a native view for RCTRawText") + + override public fun updateExtraData(view: View, extraData: Any): Unit = Unit + + override public fun getShadowNodeClass(): Class { + return ReactRawTextShadowNode::class.java + } + + override public fun createShadowNodeInstance(): ReactRawTextShadowNode { + return ReactRawTextShadowNode() + } + + internal companion object { + public const val REACT_CLASS: String = "RCTRawText" + } +}