-
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 classReactContext.ExceptionHandlerWrapper
-
Constructor Summary
Constructors Constructor Description ReactContext(Context base)
-
Method Summary
Modifier and Type Method Description voidinitializeWithInstance(CatalystInstance catalystInstance)Set and initialize CatalystInstance for this Context. synchronized voidinitializeMessageQueueThreads(ReactQueueConfiguration queueConfig)Initialize message queue threads using a ReactQueueConfiguration. voidresetPerfStats()voidsetNativeModuleCallExceptionHandler(@Nullable() NativeModuleCallExceptionHandler nativeModuleCallExceptionHandler)ObjectgetSystemService(String name)<T extends JavaScriptModule> TgetJSModule(Class<T> jsInterface)<T extends NativeModule> booleanhasNativeModule(Class<T> nativeModuleInterface)Collection<NativeModule>getNativeModules()<T extends NativeModule> TgetNativeModule(Class<T> nativeModuleInterface)CatalystInstancegetCatalystInstance()booleanhasActiveCatalystInstance()This API has been deprecated due to naming consideration, please use hasActiveReactInstance()instead booleanhasActiveReactInstance()booleanhasCatalystInstance()LifecycleStategetLifecycleState()voidaddLifecycleEventListener(LifecycleEventListener listener)voidremoveLifecycleEventListener(LifecycleEventListener listener)voidaddActivityEventListener(ActivityEventListener listener)voidremoveActivityEventListener(ActivityEventListener listener)voidaddWindowFocusChangeListener(WindowFocusChangeListener listener)voidremoveWindowFocusChangeListener(WindowFocusChangeListener listener)voidonHostResume(@Nullable() Activity activity)Should be called by the hosting Fragment in onResume voidonNewIntent(@Nullable() Activity activity, Intent intent)voidonHostPause()Should be called by the hosting Fragment in onPause voidonHostDestroy()Should be called by the hosting Fragment in onDestroy voiddestroy()Destroy this instance, making it unusable. voidonActivityResult(Activity activity, int requestCode, int resultCode, @Nullable() Intent data)Should be called by the hosting Fragment in onActivityResult voidonWindowFocusChange(boolean hasFocus)voidassertOnUiQueueThread()booleanisOnUiQueueThread()voidrunOnUiQueueThread(Runnable runnable)voidassertOnNativeModulesQueueThread()voidassertOnNativeModulesQueueThread(String message)booleanisOnNativeModulesQueueThread()voidrunOnNativeModulesQueueThread(Runnable runnable)voidassertOnJSQueueThread()booleanisOnJSQueueThread()booleanrunOnJSQueueThread(Runnable runnable)voidhandleException(Exception e)Passes the given exception to the current if one exists, rethrowingotherwise. NativeModuleCallExceptionHandlergetExceptionHandler()booleanhasCurrentActivity()booleanstartActivityForResult(Intent intent, int code, Bundle bundle)Same as startActivityForResult, this just redirects the call tothe current activity. ActivitygetCurrentActivity()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.booleanisBridgeless()JavaScriptContextHoldergetJavaScriptContextHolder()Get the C pointer (as a long) to the JavaScriptCore context associated with this instance. JSIModulegetJSIModule(JSIModuleType moduleType)StringgetSourceURL()Get the sourceURL for the JS bundle from the CatalystInstance. voidregisterSegment(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.
-
-
-
-