Skip to content

Commit 0949207

Browse files
cortinicofacebook-github-bot
authored andcommitted
Migrate to Kotlin - ReactInstanceDevHelper (#50517)
Summary: Pull Request resolved: #50517 This diff migrates the following file to Kotlin - ReactInstanceDevHelper as part of our ongoing effort of migrating the codebase to Kotlin Changelog: [Android] [Changed] - Migrate to Kotlin - ReactInstanceDevHelper. Some users implementing this class in Kotlin could have breakages. As this is a devtools/frameworks API we're not marking this as breaking. Reviewed By: javache Differential Revision: D72555226 fbshipit-source-id: e7e5523c56de8697def0a509c03e9fe89c6d5839
1 parent 0f53429 commit 0949207

File tree

5 files changed

+64
-59
lines changed

5 files changed

+64
-59
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ public void destroyRootView(View rootView) {
374374
}
375375

376376
@Override
377-
public void reload(String s) {
377+
public void reload(String reason) {
378378
// no-op not implemented for Bridge Mode
379379
}
380380

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/DevSupportManagerBase.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import com.facebook.react.R;
3939
import com.facebook.react.bridge.DefaultJSExceptionHandler;
4040
import com.facebook.react.bridge.JSBundleLoader;
41+
import com.facebook.react.bridge.JavaScriptExecutorFactory;
4142
import com.facebook.react.bridge.ReactContext;
4243
import com.facebook.react.bridge.ReactMarker;
4344
import com.facebook.react.bridge.ReactMarkerConstants;
@@ -540,7 +541,13 @@ public View getView(int position, @Nullable View convertView, ViewGroup parent)
540541

541542
private @Nullable String getJSExecutorDescription() {
542543
try {
543-
return getReactInstanceDevHelper().getJavaScriptExecutorFactory().toString();
544+
JavaScriptExecutorFactory factory =
545+
getReactInstanceDevHelper().getJavaScriptExecutorFactory();
546+
if (factory != null) {
547+
return factory.toString();
548+
} else {
549+
return null;
550+
}
544551
} catch (IllegalStateException e) {
545552
return null;
546553
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/devsupport/ReactInstanceDevHelper.java

Lines changed: 0 additions & 47 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
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.devsupport
9+
10+
import android.app.Activity
11+
import android.view.View
12+
import com.facebook.react.bridge.JSBundleLoader
13+
import com.facebook.react.bridge.JavaScriptExecutorFactory
14+
import com.facebook.react.bridge.ReactContext
15+
import com.facebook.react.devsupport.interfaces.DevSupportManager
16+
import com.facebook.react.interfaces.TaskInterface
17+
18+
/**
19+
* Interface used by [DevSupportManager] for accessing some fields and methods of [ReactHost] for
20+
* the purpose of displaying and handling developer menu options.
21+
*/
22+
public interface ReactInstanceDevHelper {
23+
24+
/** Get reference to top level [Activity] attached to react context */
25+
public val currentActivity: Activity?
26+
27+
public val javaScriptExecutorFactory: JavaScriptExecutorFactory
28+
29+
public val currentReactContext: ReactContext?
30+
31+
/** Notify react instance manager about new JS bundle version downloaded from the server. */
32+
public fun onJSBundleLoadedFromServer()
33+
34+
/** Request to toggle the react element inspector. */
35+
public fun toggleElementInspector()
36+
37+
public fun createRootView(appKey: String): View?
38+
39+
public fun destroyRootView(rootView: View)
40+
41+
public fun reload(reason: String)
42+
43+
public fun loadBundle(bundleLoader: JSBundleLoader): TaskInterface<Boolean>
44+
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImplDevHelper.kt

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,15 @@ import com.facebook.react.modules.core.DeviceEventManagerModule
2626
internal class ReactHostImplDevHelper(private val delegate: ReactHostImpl) :
2727
ReactInstanceDevHelper {
2828

29+
override val currentActivity: Activity?
30+
get() = delegate.lastUsedActivity
31+
32+
override val javaScriptExecutorFactory: JavaScriptExecutorFactory
33+
get() = throw IllegalStateException("Not implemented for bridgeless mode")
34+
35+
override val currentReactContext: ReactContext?
36+
get() = delegate.currentReactContext
37+
2938
override fun onJSBundleLoadedFromServer() {
3039
// Not implemented, only referenced by BridgeDevSupportManager
3140
}
@@ -37,12 +46,6 @@ internal class ReactHostImplDevHelper(private val delegate: ReactHostImpl) :
3746
?.emit("toggleElementInspector", null)
3847
}
3948

40-
override fun getCurrentActivity(): Activity? = delegate.lastUsedActivity
41-
42-
override fun getJavaScriptExecutorFactory(): JavaScriptExecutorFactory {
43-
throw IllegalStateException("Not implemented for bridgeless mode")
44-
}
45-
4649
override fun createRootView(appKey: String): View? {
4750
val currentActivity = currentActivity
4851
if (currentActivity != null && !delegate.isSurfaceWithModuleNameAttached(appKey)) {
@@ -59,12 +62,10 @@ internal class ReactHostImplDevHelper(private val delegate: ReactHostImpl) :
5962
// Not implemented, only referenced by BridgeDevSupportManager
6063
}
6164

62-
override fun reload(s: String) {
63-
delegate.reload(s)
65+
override fun reload(reason: String) {
66+
delegate.reload(reason)
6467
}
6568

6669
override fun loadBundle(bundleLoader: JSBundleLoader): TaskInterface<Boolean> =
6770
delegate.loadBundle(bundleLoader)
68-
69-
override fun getCurrentReactContext(): ReactContext? = delegate.currentReactContext
7071
}

0 commit comments

Comments
 (0)