Skip to content

Commit 0b14a19

Browse files
sbuggayfacebook-github-bot
authored andcommitted
Migrate ReactRoot to Kotlin (#53238)
Summary: Pull Request resolved: #53238 Changelog: [Android][Changed] - Migrated ReactRoot to Kotlin Reviewed By: cortinico Differential Revision: D80074359 fbshipit-source-id: 273f5bfc2826f59f2bb1521b8dbd95c48e5eb0c4
1 parent 3774f75 commit 0b14a19

File tree

5 files changed

+75
-78
lines changed

5 files changed

+75
-78
lines changed

packages/react-native/ReactAndroid/api/ReactAndroid.api

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3806,6 +3806,7 @@ public abstract interface class com/facebook/react/uimanager/ReactPointerEventsV
38063806
}
38073807

38083808
public abstract interface class com/facebook/react/uimanager/ReactRoot {
3809+
public static final field Companion Lcom/facebook/react/uimanager/ReactRoot$Companion;
38093810
public static final field STATE_STARTED I
38103811
public static final field STATE_STOPPED I
38113812
public abstract fun getAppProperties ()Landroid/os/Bundle;
@@ -3823,6 +3824,11 @@ public abstract interface class com/facebook/react/uimanager/ReactRoot {
38233824
public abstract fun setShouldLogContentAppeared (Z)V
38243825
}
38253826

3827+
public final class com/facebook/react/uimanager/ReactRoot$Companion {
3828+
public static final field STATE_STARTED I
3829+
public static final field STATE_STOPPED I
3830+
}
3831+
38263832
public abstract interface class com/facebook/react/uimanager/ReactShadowNode {
38273833
public abstract fun addChildAt (Lcom/facebook/react/uimanager/ReactShadowNode;I)V
38283834
public abstract fun addNativeChildAt (Lcom/facebook/react/uimanager/ReactShadowNode;I)V

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/ReactRoot.java

Lines changed: 0 additions & 76 deletions
This file was deleted.
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
package com.facebook.react.uimanager
9+
10+
import android.os.Bundle
11+
import android.view.ViewGroup
12+
import com.facebook.react.uimanager.common.UIManagerType
13+
import java.util.concurrent.atomic.AtomicInteger
14+
15+
/** Interface for the root native view of a React native application */
16+
public interface ReactRoot {
17+
18+
public companion object {
19+
/** This constant represents that ReactRoot hasn't started yet or it has been destroyed. */
20+
public const val STATE_STOPPED: Int = 0
21+
22+
/** This constant represents that ReactRoot has started. */
23+
public const val STATE_STARTED: Int = 1
24+
}
25+
26+
/** Return cached launch properties for app */
27+
public fun getAppProperties(): Bundle?
28+
29+
public fun getJSModuleName(): String
30+
31+
/** Fabric or Default UI Manager, see [UIManagerType] */
32+
@UIManagerType public fun getUIManagerType(): Int
33+
34+
public fun getRootViewTag(): Int
35+
36+
public fun setRootViewTag(rootViewTag: Int)
37+
38+
/** Calls into JS to start the React application. */
39+
public fun runApplication()
40+
41+
/** Handler for stages [com.facebook.react.surface.ReactStage] */
42+
public fun onStage(@ReactStage stage: Int)
43+
44+
/** Return native view for root */
45+
public fun getRootViewGroup(): ViewGroup
46+
47+
/** @return Cached values for widthMeasureSpec. */
48+
public fun getWidthMeasureSpec(): Int
49+
50+
/** @return Cached values for and heightMeasureSpec. */
51+
public fun getHeightMeasureSpec(): Int
52+
53+
/** Sets a flag that determines whether to log that content appeared on next view added. */
54+
public fun setShouldLogContentAppeared(shouldLogContentAppeared: Boolean)
55+
56+
/**
57+
* @return a [String] that represents the root js application that is being rendered with this
58+
* [ReactRoot]
59+
* @deprecated We recommend to not use this method as it is will be replaced in the near future.
60+
*/
61+
@Deprecated("We recommend to not use this method as it is will be replaced in the near future.")
62+
public fun getSurfaceID(): String?
63+
64+
/** @return an [AtomicInteger] that represents the state of the ReactRoot object. */
65+
public fun getState(): AtomicInteger
66+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/UIManagerHelper.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,8 @@ public object UIManagerHelper {
194194
public fun getSurfaceId(view: View): Int {
195195
if (view is ReactRoot) {
196196
val rootView = view as ReactRoot
197-
return if (rootView.uiManagerType == UIManagerType.FABRIC) rootView.rootViewTag else -1
197+
return if (rootView.getUIManagerType() == UIManagerType.FABRIC) rootView.getRootViewTag()
198+
else -1
198199
}
199200

200201
val reactTag = view.id

packages/react-native/ReactAndroid/src/test/java/com/facebook/react/RootViewTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ class RootViewTest {
9898
val rootViewId = 11
9999
val rootView = ReactRootView(reactContext)
100100
rootView.id = rootViewId
101-
rootView.rootViewTag = rootViewId
101+
rootView.setRootViewTag(rootViewId)
102102
rootView.startReactApplication(instanceManager, "")
103103
rootView.simulateAttachForTesting()
104104
val ts = SystemClock.currentTimeMillis()

0 commit comments

Comments
 (0)