Skip to content

Commit

Permalink
Revert D55505416: Pull react instance method impls out of ReactContext
Browse files Browse the repository at this point in the history
Differential Revision:
D55505416

Original commit changeset: ce1e3ab379eb

Original Phabricator Diff: D55505416

fbshipit-source-id: ae988ae3464f40923521922d4c3ac4a57846a3ef
  • Loading branch information
RSNara authored and facebook-github-bot committed Mar 31, 2024
1 parent 14fb1cc commit fa4bfde
Show file tree
Hide file tree
Showing 5 changed files with 181 additions and 341 deletions.
66 changes: 21 additions & 45 deletions packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -543,22 +543,6 @@ public abstract class com/facebook/react/bridge/BaseJavaModule : com/facebook/re

public final class com/facebook/react/bridge/BridgeReactContext : com/facebook/react/bridge/ReactApplicationContext {
public fun <init> (Landroid/content/Context;)V
public fun destroy ()V
public fun getCatalystInstance ()Lcom/facebook/react/bridge/CatalystInstance;
public fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getNativeModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/NativeModule;
public fun getNativeModules ()Ljava/util/Collection;
public fun getSourceURL ()Ljava/lang/String;
public fun handleException (Ljava/lang/Exception;)V
public fun hasActiveCatalystInstance ()Z
public fun hasActiveReactInstance ()Z
public fun hasCatalystInstance ()Z
public fun hasNativeModule (Ljava/lang/Class;)Z
public final fun initializeWithInstance (Lcom/facebook/react/bridge/CatalystInstance;)V
public fun isBridgeless ()Z
public fun registerSegment (ILjava/lang/String;Lcom/facebook/react/bridge/Callback;)V
}

public abstract interface class com/facebook/react/bridge/Callback {
Expand Down Expand Up @@ -1104,35 +1088,36 @@ public abstract class com/facebook/react/bridge/ReactContext : android/content/C
public fun assertOnNativeModulesQueueThread ()V
public fun assertOnNativeModulesQueueThread (Ljava/lang/String;)V
public fun assertOnUiQueueThread ()V
public abstract fun destroy ()V
public fun destroy ()V
public fun emitDeviceEvent (Ljava/lang/String;)V
public fun emitDeviceEvent (Ljava/lang/String;Ljava/lang/Object;)V
public abstract fun getCatalystInstance ()Lcom/facebook/react/bridge/CatalystInstance;
public fun getCatalystInstance ()Lcom/facebook/react/bridge/CatalystInstance;
public fun getCurrentActivity ()Landroid/app/Activity;
public fun getExceptionHandler ()Lcom/facebook/react/bridge/JSExceptionHandler;
public abstract fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public fun getJSExceptionHandler ()Lcom/facebook/react/bridge/JSExceptionHandler;
public fun getJSMessageQueueThread ()Lcom/facebook/react/bridge/queue/MessageQueueThread;
public abstract fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public abstract fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getLifecycleState ()Lcom/facebook/react/common/LifecycleState;
public abstract fun getNativeModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/NativeModule;
public abstract fun getNativeModules ()Ljava/util/Collection;
public fun getNativeModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/NativeModule;
public fun getNativeModules ()Ljava/util/Collection;
public fun getNativeModulesMessageQueueThread ()Lcom/facebook/react/bridge/queue/MessageQueueThread;
public abstract fun getSourceURL ()Ljava/lang/String;
public fun getSourceURL ()Ljava/lang/String;
public fun getSystemService (Ljava/lang/String;)Ljava/lang/Object;
public fun getUiMessageQueueThread ()Lcom/facebook/react/bridge/queue/MessageQueueThread;
public abstract fun handleException (Ljava/lang/Exception;)V
public abstract fun hasActiveCatalystInstance ()Z
public abstract fun hasActiveReactInstance ()Z
public abstract fun hasCatalystInstance ()Z
public fun handleException (Ljava/lang/Exception;)V
public fun hasActiveCatalystInstance ()Z
public fun hasActiveReactInstance ()Z
public fun hasCatalystInstance ()Z
public fun hasCurrentActivity ()Z
public abstract fun hasNativeModule (Ljava/lang/Class;)Z
protected fun initializeFromOther (Lcom/facebook/react/bridge/ReactContext;)V
public fun hasNativeModule (Ljava/lang/Class;)Z
protected fun initializeInteropModules ()V
protected fun initializeInteropModules (Lcom/facebook/react/bridge/ReactContext;)V
public fun initializeMessageQueueThreads (Lcom/facebook/react/bridge/queue/ReactQueueConfiguration;)V
public fun initializeWithInstance (Lcom/facebook/react/bridge/CatalystInstance;)V
public fun internal_registerInteropModule (Ljava/lang/Class;Ljava/lang/Object;)V
public abstract fun isBridgeless ()Z
public fun isBridgeless ()Z
public fun isOnJSQueueThread ()Z
public fun isOnNativeModulesQueueThread ()Z
public fun isOnUiQueueThread ()Z
Expand All @@ -1142,7 +1127,7 @@ public abstract class com/facebook/react/bridge/ReactContext : android/content/C
public fun onHostResume (Landroid/app/Activity;)V
public fun onNewIntent (Landroid/app/Activity;Landroid/content/Intent;)V
public fun onWindowFocusChange (Z)V
public abstract fun registerSegment (ILjava/lang/String;Lcom/facebook/react/bridge/Callback;)V
public fun registerSegment (ILjava/lang/String;Lcom/facebook/react/bridge/Callback;)V
public fun removeActivityEventListener (Lcom/facebook/react/bridge/ActivityEventListener;)V
public fun removeLifecycleEventListener (Lcom/facebook/react/bridge/LifecycleEventListener;)V
public fun removeWindowFocusChangeListener (Lcom/facebook/react/bridge/WindowFocusChangeListener;)V
Expand Down Expand Up @@ -4837,25 +4822,16 @@ public class com/facebook/react/uimanager/ThemedReactContext : com/facebook/reac
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Landroid/content/Context;)V
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Landroid/content/Context;Ljava/lang/String;)V
public fun <init> (Lcom/facebook/react/bridge/ReactApplicationContext;Landroid/content/Context;Ljava/lang/String;I)V
public fun destroy ()V
public fun getCatalystInstance ()Lcom/facebook/react/bridge/CatalystInstance;
public fun addLifecycleEventListener (Lcom/facebook/react/bridge/LifecycleEventListener;)V
public fun getCurrentActivity ()Landroid/app/Activity;
public fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getModuleName ()Ljava/lang/String;
public fun getNativeModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/NativeModule;
public fun getNativeModules ()Ljava/util/Collection;
public fun getReactApplicationContext ()Lcom/facebook/react/bridge/ReactApplicationContext;
public fun getSourceURL ()Ljava/lang/String;
public fun getSurfaceID ()Ljava/lang/String;
public fun getSurfaceId ()I
public fun handleException (Ljava/lang/Exception;)V
public fun hasActiveCatalystInstance ()Z
public fun hasActiveReactInstance ()Z
public fun hasCatalystInstance ()Z
public fun hasNativeModule (Ljava/lang/Class;)Z
public fun hasCurrentActivity ()Z
public fun isBridgeless ()Z
public fun registerSegment (ILjava/lang/String;Lcom/facebook/react/bridge/Callback;)V
public fun removeLifecycleEventListener (Lcom/facebook/react/bridge/LifecycleEventListener;)V
}

public class com/facebook/react/uimanager/TouchTargetHelper {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,194 +8,13 @@
package com.facebook.react.bridge

import android.content.Context
import com.facebook.common.logging.FLog
import com.facebook.react.bridge.queue.ReactQueueConfiguration
import com.facebook.react.common.ReactConstants
import com.facebook.react.common.annotations.DeprecatedInNewArchitecture
import com.facebook.react.common.annotations.FrameworkAPI
import com.facebook.react.common.annotations.UnstableReactNativeAPI

/**
* This is the bridge-specific concrete subclass of ReactContext. ReactContext has many methods that
* delegate to the react instance. This subclass implements those methods, by delegating to the
* delegate to the react instance. This subclass will implement those methods, by delegating to the
* CatalystInstance. If you need to create a ReactContext within an "bridge context", please create
* BridgeReactContext.
*/
@DeprecatedInNewArchitecture
public class BridgeReactContext(base: Context) : ReactApplicationContext(base) {
@Volatile private var destroyed = false
private var catalystInstance: CatalystInstance? = null

public fun initializeWithInstance(otherCatalystInstance: CatalystInstance?): Unit {
if (otherCatalystInstance == null) {
throw IllegalArgumentException("CatalystInstance cannot be null.")
}
if (catalystInstance != null) {
throw IllegalStateException("ReactContext has been already initialized")
}
if (destroyed) {
ReactSoftExceptionLogger.logSoftException(
TAG, IllegalStateException("Cannot initialize ReactContext after it has been destroyed."))
}

catalystInstance = otherCatalystInstance

val queueConfig: ReactQueueConfiguration = otherCatalystInstance.reactQueueConfiguration
initializeMessageQueueThreads(queueConfig)
initializeInteropModules()
}

public override fun <T : JavaScriptModule?> getJSModule(jsInterface: Class<T>?): T? {
val instance =
catalystInstance
?: throw IllegalStateException(
if (destroyed) LATE_JS_ACCESS_EXCEPTION_MESSAGE
else EARLY_JS_ACCESS_EXCEPTION_MESSAGE)

val interopModuleRegistry = mInteropModuleRegistry
if (interopModuleRegistry != null &&
interopModuleRegistry.shouldReturnInteropModule(jsInterface)) {
return interopModuleRegistry.getInteropModule(jsInterface)
}

return instance.getJSModule(jsInterface)
}

public override fun <T : NativeModule?> hasNativeModule(
nativeModuleInterface: Class<T>?
): Boolean {
val instance =
catalystInstance
?: throw IllegalStateException(
if (destroyed) LATE_NATIVE_MODULE_EXCEPTION_MESSAGE
else EARLY_NATIVE_MODULE_EXCEPTION_MESSAGE)
return instance.hasNativeModule(nativeModuleInterface)
}

public override fun getNativeModules(): MutableCollection<NativeModule> {
val instance =
catalystInstance
?: throw IllegalStateException(
if (destroyed) LATE_NATIVE_MODULE_EXCEPTION_MESSAGE
else EARLY_NATIVE_MODULE_EXCEPTION_MESSAGE)
return instance.nativeModules
}

public override fun <T : NativeModule?> getNativeModule(nativeModuleInterface: Class<T>?): T? {
val instance =
catalystInstance
?: throw IllegalStateException(
if (destroyed) LATE_NATIVE_MODULE_EXCEPTION_MESSAGE
else EARLY_NATIVE_MODULE_EXCEPTION_MESSAGE)
return instance.getNativeModule(nativeModuleInterface)
}

@FrameworkAPI
@UnstableReactNativeAPI
public override fun getRuntimeExecutor(): RuntimeExecutor? {
val instance =
catalystInstance
?: throw IllegalStateException(
if (destroyed) LATE_RUNTIME_EXECUTOR_ACCESS_EXCEPTION_MESSAGE
else EARLY_RUNTIME_EXECUTOR_ACCESS_EXCEPTION_MESSAGE)

return instance.getRuntimeExecutor()
}

public override fun getCatalystInstance(): CatalystInstance {
return catalystInstance!!
}

@Deprecated(
"This API is unsupported in the New Architecture.", ReplaceWith("hasActiveReactInstance()"))
public override fun hasActiveCatalystInstance(): Boolean {
return hasActiveReactInstance()
}

public override fun hasActiveReactInstance(): Boolean {
val instance = catalystInstance
return instance != null && !instance.isDestroyed
}

public override fun hasCatalystInstance(): Boolean {
return catalystInstance != null
}

public override fun destroy(): Unit {
UiThreadUtil.assertOnUiThread()

destroyed = true
catalystInstance?.destroy()
}

public override fun handleException(e: Exception?): Unit {
val jsExceptionHandler: JSExceptionHandler? = jsExceptionHandler

if (hasActiveReactInstance() && jsExceptionHandler != null) {
jsExceptionHandler.handleException(e)
} else {
FLog.e(
ReactConstants.TAG,
"Unable to handle Exception - catalystInstanceVariableExists: " +
(catalystInstance != null) +
" - isCatalystInstanceAlive: " +
hasActiveReactInstance() +
" - hasExceptionHandler: " +
(jsExceptionHandler != null),
e)
throw IllegalStateException(e)
}
}

public override fun isBridgeless(): Boolean {
return false
}

public override fun getJavaScriptContextHolder(): JavaScriptContextHolder? {
return catalystInstance?.javaScriptContextHolder
}

public override fun getFabricUIManager(): UIManager? {
val instance =
catalystInstance
?: throw IllegalStateException(
if (destroyed) LATE_FABRIC_UI_MANAGER_ACCESS_EXCEPTION_MESSAGE
else EARLY_FABRIC_UI_MANAGER_ACCESS_EXCEPTION_MESSAGE)

return instance.fabricUIManager ?: instance.getJSIModule(JSIModuleType.UIManager) as? UIManager
}

public override fun getSourceURL(): String? {
return catalystInstance?.sourceURL
}

public override fun registerSegment(segmentId: Int, path: String?, callback: Callback?): Unit {
catalystInstance!!.registerSegment(segmentId, path)
callback!!.invoke()
}

private companion object {
private const val TAG = "BridgeReactContext"

private const val EARLY_JS_ACCESS_EXCEPTION_MESSAGE =
("Tried to access a JS module before the React instance was fully set up. Calls to " +
"ReactContext#getJSModule should only happen once initialize() has been called on your " +
"native module.")
private const val LATE_JS_ACCESS_EXCEPTION_MESSAGE =
"Tried to access a JS module after the React instance was destroyed."
private const val EARLY_NATIVE_MODULE_EXCEPTION_MESSAGE =
"Trying to call native module before CatalystInstance has been set!"
private const val LATE_NATIVE_MODULE_EXCEPTION_MESSAGE =
"Trying to call native module after CatalystInstance has been destroyed!"

private const val EARLY_RUNTIME_EXECUTOR_ACCESS_EXCEPTION_MESSAGE =
"Tried to access a RuntimeExecutor before CatalystInstance has been set!"
private const val LATE_RUNTIME_EXECUTOR_ACCESS_EXCEPTION_MESSAGE =
"Tried to access a RuntimeExecutor after CatalystInstance has been destroyed!"

private const val LATE_FABRIC_UI_MANAGER_ACCESS_EXCEPTION_MESSAGE =
"Tried to access a FabricUIManager after CatalystInstance has been destroyed!"
private const val EARLY_FABRIC_UI_MANAGER_ACCESS_EXCEPTION_MESSAGE =
"Tried to access a FabricUIManager after CatalystInstance before it has been set!"
}
}
public class BridgeReactContext(base: Context) : ReactApplicationContext(base) {}
Loading

0 comments on commit fa4bfde

Please sign in to comment.