-
public class ReactContext extends ContextWrapper
Abstract ContextWrapper for Android application or activity Context and
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public class
ReactContext.ExceptionHandlerWrapper
-
Constructor Summary
Constructors Constructor Description ReactContext(Context base)
-
Method Summary
Modifier and Type Method Description void
initializeWithInstance(CatalystInstance catalystInstance)
Set and initialize CatalystInstance for this Context. synchronized void
initializeMessageQueueThreads(ReactQueueConfiguration queueConfig)
Initialize message queue threads using a ReactQueueConfiguration. void
resetPerfStats()
void
setNativeModuleCallExceptionHandler(@Nullable() NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler)
Object
getSystemService(String name)
<T extends JavaScriptModule> T
getJSModule(Class<T> jsInterface)
<T extends NativeModule> boolean
hasNativeModule(Class<T> nativeModuleInterface)
Collection<NativeModule>
getNativeModules()
<T extends NativeModule> T
getNativeModule(Class<T> nativeModuleInterface)
CatalystInstance
getCatalystInstance()
boolean
hasActiveCatalystInstance()
This API has been deprecated due to naming consideration, please use hasActiveReactInstance()instead boolean
hasActiveReactInstance()
boolean
hasCatalystInstance()
LifecycleState
getLifecycleState()
void
addLifecycleEventListener(LifecycleEventListener listener)
void
removeLifecycleEventListener(LifecycleEventListener listener)
void
addActivityEventListener(ActivityEventListener listener)
void
removeActivityEventListener(ActivityEventListener listener)
void
addWindowFocusChangeListener(WindowFocusChangeListener listener)
void
removeWindowFocusChangeListener(WindowFocusChangeListener listener)
void
onHostResume(@Nullable() Activity activity)
Should be called by the hosting Fragment in onResume void
onNewIntent(@Nullable() Activity activity, Intent intent)
void
onHostPause()
Should be called by the hosting Fragment in onPause void
onHostDestroy()
Should be called by the hosting Fragment in onDestroy void
destroy()
Destroy this instance, making it unusable. void
onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable() Intent data)
Should be called by the hosting Fragment in onActivityResult void
onWindowFocusChange(boolean hasFocus)
void
assertOnUiQueueThread()
boolean
isOnUiQueueThread()
void
runOnUiQueueThread(Runnable runnable)
void
assertOnNativeModulesQueueThread()
void
assertOnNativeModulesQueueThread(String message)
boolean
isOnNativeModulesQueueThread()
void
runOnNativeModulesQueueThread(Runnable runnable)
void
assertOnJSQueueThread()
boolean
isOnJSQueueThread()
boolean
runOnJSQueueThread(Runnable runnable)
void
handleException(Exception e)
Passes the given exception to the current if one exists, rethrowingotherwise. NativeModuleCallExceptionHandler
getExceptionHandler()
boolean
hasCurrentActivity()
boolean
startActivityForResult(Intent intent, int code, Bundle bundle)
Same as startActivityForResult, this just redirects the call tothe current activity. Activity
getCurrentActivity()
Get the activity to which this context is currently attached, or {@code null}
if not attached.DO NOT HOLD LONG-LIVED REFERENCES TO THE OBJECT RETURNED BY THIS METHOD, AS THIS WILL CAUSEMEMORY LEAKS.boolean
isBridgeless()
JavaScriptContextHolder
getJavaScriptContextHolder()
Get the C pointer (as a long) to the JavaScriptCore context associated with this instance. JSIModule
getJSIModule(JSIModuleType moduleType)
String
getSourceURL()
Get the sourceURL for the JS bundle from the CatalystInstance. void
registerSegment(int segmentId, String path, Callback callback)
Register a JS segment after loading it from cache or server, make sure mCatalystInstance isproperly initialised and not null before calling. -
Methods inherited from class android.content.ContextWrapper
bindIsolatedService, bindService, bindServiceAsUser, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingOrSelfUriPermissions, checkCallingPermission, checkCallingUriPermission, checkCallingUriPermissions, checkPermission, checkSelfPermission, checkUriPermission, checkUriPermissions, clearWallpaper, createAttributionContext, createConfigurationContext, createContext, createContextForSplit, createDeviceProtectedStorageContext, createDisplayContext, createPackageContext, createWindowContext, databaseList, deleteDatabase, deleteFile, deleteSharedPreferences, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getAttributionSource, getAttributionTag, getBaseContext, getCacheDir, getClassLoader, getCodeCacheDir, getContentResolver, getDataDir, getDatabasePath, getDir, getDisplay, getExternalCacheDir, getExternalCacheDirs, getExternalFilesDir, getExternalFilesDirs, getExternalMediaDirs, getFileStreamPath, getFilesDir, getMainExecutor, getMainLooper, getNoBackupFilesDir, getObbDir, getObbDirs, getOpPackageName, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getParams, getResources, getSharedPreferences, getSystemService, getSystemServiceName, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isDeviceProtectedStorage, isRestricted, isUiContext, moveDatabaseFrom, moveSharedPreferencesFrom, openFileInput, openFileOutput, openOrCreateDatabase, peekWallpaper, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, startActivities, startActivity, startForegroundService, startInstrumentation, startIntentSender, startService, stopService, unbindService, unregisterReceiver, updateServiceGroup
-
Methods inherited from class android.content.Context
getColor, getColorStateList, getDrawable, getString, getSystemService, getText, obtainStyledAttributes, registerComponentCallbacks, sendBroadcastWithMultiplePermissions, unregisterComponentCallbacks
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
ReactContext
ReactContext(Context base)
-
-
Method Detail
-
initializeWithInstance
void initializeWithInstance(CatalystInstance catalystInstance)
Set and initialize CatalystInstance for this Context. This should be called exactly once.
-
initializeMessageQueueThreads
synchronized void initializeMessageQueueThreads(ReactQueueConfiguration queueConfig)
Initialize message queue threads using a ReactQueueConfiguration.
-
resetPerfStats
void resetPerfStats()
-
setNativeModuleCallExceptionHandler
void setNativeModuleCallExceptionHandler(@Nullable() NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler)
-
getSystemService
Object getSystemService(String name)
-
getJSModule
<T extends JavaScriptModule> T getJSModule(Class<T> jsInterface)
-
hasNativeModule
<T extends NativeModule> boolean hasNativeModule(Class<T> nativeModuleInterface)
-
getNativeModules
Collection<NativeModule> getNativeModules()
-
getNativeModule
@Nullable() <T extends NativeModule> T getNativeModule(Class<T> nativeModuleInterface)
-
getCatalystInstance
CatalystInstance getCatalystInstance()
-
hasActiveCatalystInstance
@Deprecated() boolean hasActiveCatalystInstance()
This API has been deprecated due to naming consideration, please use hasActiveReactInstance()instead
-
hasActiveReactInstance
boolean hasActiveReactInstance()
-
hasCatalystInstance
boolean hasCatalystInstance()
-
getLifecycleState
LifecycleState getLifecycleState()
-
addLifecycleEventListener
void addLifecycleEventListener(LifecycleEventListener listener)
-
removeLifecycleEventListener
void removeLifecycleEventListener(LifecycleEventListener listener)
-
addActivityEventListener
void addActivityEventListener(ActivityEventListener listener)
-
removeActivityEventListener
void removeActivityEventListener(ActivityEventListener listener)
-
addWindowFocusChangeListener
void addWindowFocusChangeListener(WindowFocusChangeListener listener)
-
removeWindowFocusChangeListener
void removeWindowFocusChangeListener(WindowFocusChangeListener listener)
-
onHostResume
void onHostResume(@Nullable() Activity activity)
Should be called by the hosting Fragment in onResume
-
onNewIntent
void onNewIntent(@Nullable() Activity activity, Intent intent)
-
onHostPause
void onHostPause()
Should be called by the hosting Fragment in onPause
-
onHostDestroy
void onHostDestroy()
Should be called by the hosting Fragment in onDestroy
-
destroy
void destroy()
Destroy this instance, making it unusable.
-
onActivityResult
void onActivityResult(Activity activity, int requestCode, int resultCode, @Nullable() Intent data)
Should be called by the hosting Fragment in onActivityResult
-
onWindowFocusChange
void onWindowFocusChange(boolean hasFocus)
-
assertOnUiQueueThread
void assertOnUiQueueThread()
-
isOnUiQueueThread
boolean isOnUiQueueThread()
-
runOnUiQueueThread
void runOnUiQueueThread(Runnable runnable)
-
assertOnNativeModulesQueueThread
void assertOnNativeModulesQueueThread()
-
assertOnNativeModulesQueueThread
void assertOnNativeModulesQueueThread(String message)
-
isOnNativeModulesQueueThread
boolean isOnNativeModulesQueueThread()
-
runOnNativeModulesQueueThread
void runOnNativeModulesQueueThread(Runnable runnable)
-
assertOnJSQueueThread
void assertOnJSQueueThread()
-
isOnJSQueueThread
boolean isOnJSQueueThread()
-
runOnJSQueueThread
boolean runOnJSQueueThread(Runnable runnable)
-
handleException
void handleException(Exception e)
Passes the given exception to the current if one exists, rethrowingotherwise.
-
getExceptionHandler
NativeModuleCallExceptionHandler getExceptionHandler()
-
hasCurrentActivity
boolean hasCurrentActivity()
-
startActivityForResult
boolean startActivityForResult(Intent intent, int code, Bundle bundle)
Same as startActivityForResult, this just redirects the call tothe current activity. Returns whether the activity was started, as this might fail if this wascalled before the context is in the right state.
-
getCurrentActivity
@Nullable() Activity getCurrentActivity()
Get the activity to which this context is currently attached, or
{@code null}
if not attached.DO NOT HOLD LONG-LIVED REFERENCES TO THE OBJECT RETURNED BY THIS METHOD, AS THIS WILL CAUSEMEMORY LEAKS.
-
isBridgeless
boolean isBridgeless()
-
getJavaScriptContextHolder
JavaScriptContextHolder getJavaScriptContextHolder()
Get the C pointer (as a long) to the JavaScriptCore context associated with this instance. Usethe following pattern to ensure that the JS context is not cleared while you are using it:JavaScriptContextHolder jsContext = reactContext.getJavaScriptContextHolder()synchronized(jsContext) { nativeThingNeedingJsContext(jsContext.get()); }
-
getJSIModule
@Nullable() JSIModule getJSIModule(JSIModuleType moduleType)
-
getSourceURL
@Nullable() String getSourceURL()
Get the sourceURL for the JS bundle from the CatalystInstance. This method is needed forcompatibility with bridgeless mode, which has no CatalystInstance.
-
registerSegment
void registerSegment(int segmentId, String path, Callback callback)
Register a JS segment after loading it from cache or server, make sure mCatalystInstance isproperly initialised and not null before calling.
-
-
-
-