From 4a119c4c3ac9bf4b234e2942a27a6efd68a801cc Mon Sep 17 00:00:00 2001 From: David Vacca Date: Tue, 5 Nov 2024 21:44:38 -0800 Subject: [PATCH] Migrate ReactVirtualTextViewManager to kotlin and reduce visibility tointernal (#47402) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/47402 Migrate ReactVirtualTextViewManager to kotlin and reduce visibility tointernal changelog: [Android][Breaking] Reduce visibility of ReactVirtualTextViewManager to internal Reviewed By: cortinico Differential Revision: D65462051 fbshipit-source-id: fa6daef4e557d527d594616ca032ebf0180cbba2 --- .../ReactAndroid/api/ReactAndroid.api | 10 ---- .../ReactAndroid/gradle.properties | 6 +-- .../text/ReactVirtualTextViewManager.java | 47 ------------------- .../views/text/ReactVirtualTextViewManager.kt | 38 +++++++++++++++ .../ReactUnimplementedView.kt | 4 +- 5 files changed, 41 insertions(+), 64 deletions(-) delete mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.java create mode 100644 packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.kt diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 539a04cebdfe29..9d39acc376cbbd 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -7527,16 +7527,6 @@ public class com/facebook/react/views/text/ReactVirtualTextShadowNode : com/face public fun isVirtual ()Z } -public class com/facebook/react/views/text/ReactVirtualTextViewManager : com/facebook/react/uimanager/BaseViewManager { - public fun ()V - public synthetic fun createShadowNodeInstance ()Lcom/facebook/react/uimanager/ReactShadowNode; - public fun createShadowNodeInstance ()Lcom/facebook/react/views/text/ReactVirtualTextShadowNode; - public fun createViewInstance (Lcom/facebook/react/uimanager/ThemedReactContext;)Landroid/view/View; - public fun getName ()Ljava/lang/String; - public fun getShadowNodeClass ()Ljava/lang/Class; - public fun updateExtraData (Landroid/view/View;Ljava/lang/Object;)V -} - public class com/facebook/react/views/text/TextAttributeProps { public static final field TA_KEY_ACCESSIBILITY_ROLE S public static final field TA_KEY_ALIGNMENT S diff --git a/packages/react-native/ReactAndroid/gradle.properties b/packages/react-native/ReactAndroid/gradle.properties index 6748b2bfd5cde4..c4947b2bd07a58 100644 --- a/packages/react-native/ReactAndroid/gradle.properties +++ b/packages/react-native/ReactAndroid/gradle.properties @@ -11,11 +11,7 @@ react.internal.disableJavaVersionAlignment=true # We ignore: # - BuildConfig classes because they are generated and not part of the public API -# - PropsSetter classes because they are generated by the Annotation processor which is not used in OSS -binaryCompatibilityValidator.ignoredClasses=com.facebook.react.BuildConfig,\ - com.facebook.react.views.safeareaview.ReactSafeAreaViewManager$$PropsSetter,\ - com.facebook.react.views.unimplementedview.ReactUnimplementedViewManager$$PropsSetter,\ - com.facebook.react.views.safeareaview.ReactSafeAreaViewShadowNode$$PropsSetter +binaryCompatibilityValidator.ignoredClasses=com.facebook.react.BuildConfig binaryCompatibilityValidator.ignoredPackages=com.facebook.debug,\ com.facebook.fbreact,\ diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.java deleted file mode 100644 index 421a9e8c7b4257..00000000000000 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.java +++ /dev/null @@ -1,47 +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 com.facebook.react.common.annotations.VisibleForTesting; -import com.facebook.react.module.annotations.ReactModule; -import com.facebook.react.uimanager.BaseViewManager; -import com.facebook.react.uimanager.ThemedReactContext; - -/** - * Manages raw text nodes. Since they are used only as a virtual nodes any type of native view - * operation will throw an {@link IllegalStateException} - */ -@ReactModule(name = ReactVirtualTextViewManager.REACT_CLASS) -public class ReactVirtualTextViewManager extends BaseViewManager { - - @VisibleForTesting public static final String REACT_CLASS = "RCTVirtualText"; - - @Override - public String getName() { - return REACT_CLASS; - } - - @Override - public View createViewInstance(ThemedReactContext context) { - throw new IllegalStateException("Attempt to create a native view for RCTVirtualText"); - } - - @Override - public void updateExtraData(View view, Object extraData) {} - - @Override - public Class getShadowNodeClass() { - return ReactVirtualTextShadowNode.class; - } - - @Override - public ReactVirtualTextShadowNode createShadowNodeInstance() { - return new ReactVirtualTextShadowNode(); - } -} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.kt new file mode 100644 index 00000000000000..1ee05de1789188 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/text/ReactVirtualTextViewManager.kt @@ -0,0 +1,38 @@ +/* + * 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.BaseViewManager +import com.facebook.react.uimanager.ThemedReactContext + +/** + * Manages raw text nodes. Since they are used only as a virtual nodes any type of native view + * operation will throw an [IllegalStateException] + */ +@ReactModule(name = ReactVirtualTextViewManager.REACT_CLASS) +internal class ReactVirtualTextViewManager : BaseViewManager() { + + public override fun getName(): String = REACT_CLASS + + protected override fun createViewInstance(context: ThemedReactContext): View { + throw IllegalStateException("Attempt to create a native view for RCTVirtualText") + } + + public override fun updateExtraData(view: View, extraData: Any): Unit {} + + public override fun getShadowNodeClass(): Class = + ReactVirtualTextShadowNode::class.java + + override fun createShadowNodeInstance(): ReactVirtualTextShadowNode = ReactVirtualTextShadowNode() + + internal companion object { + public const val REACT_CLASS: String = "RCTVirtualText" + } +} diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/unimplementedview/ReactUnimplementedView.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/unimplementedview/ReactUnimplementedView.kt index 60e58d86e9ca07..1f9d2f58625cc2 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/unimplementedview/ReactUnimplementedView.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/unimplementedview/ReactUnimplementedView.kt @@ -13,7 +13,7 @@ import android.view.Gravity import android.widget.LinearLayout import androidx.appcompat.widget.AppCompatTextView -public class ReactUnimplementedView(context: Context) : LinearLayout(context) { +internal class ReactUnimplementedView(context: Context) : LinearLayout(context) { private val textView: AppCompatTextView @@ -31,7 +31,7 @@ public class ReactUnimplementedView(context: Context) : LinearLayout(context) { addView(textView) } - public fun setName(name: String) { + internal fun setName(name: String) { textView.setText("'$name' is not Fabric compatible yet.") } }