mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Add a field + getter for instanceKey to ReactContext
Summary: Adding a new String field for `instanceKey` to ReactContext, which is set via a new constructor on ReactApplicationContext. Also adding getters to ReactContext and ThemedReactContext so that it's accessible from any instance/subclass of ReactContext. This will only be used in bridgeless mode. Reviewed By: mdvacca Differential Revision: D18316556 fbshipit-source-id: 9757da72fde4ba36034c1e129326461fed496229
This commit is contained in:
committed by
Facebook Github Bot
parent
f77abc583c
commit
6598292ede
@@ -20,4 +20,15 @@ public class ReactApplicationContext extends ReactContext {
|
||||
public ReactApplicationContext(Context context) {
|
||||
super(context.getApplicationContext());
|
||||
}
|
||||
|
||||
/**
|
||||
* A constructor that takes a unique string identifier for the React instance. For bridgeless mode
|
||||
* only - do not use.
|
||||
*
|
||||
* <p>TODO T43898341 Make this package-private once we've consolidated the classes that need this
|
||||
* in this package
|
||||
*/
|
||||
public ReactApplicationContext(Context context, String instanceKey) {
|
||||
super(context.getApplicationContext(), instanceKey);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,9 +53,20 @@ public class ReactContext extends ContextWrapper {
|
||||
private @Nullable NativeModuleCallExceptionHandler mNativeModuleCallExceptionHandler;
|
||||
private @Nullable NativeModuleCallExceptionHandler mExceptionHandlerWrapper;
|
||||
private @Nullable WeakReference<Activity> mCurrentActivity;
|
||||
private final @Nullable String mInstanceKey;
|
||||
|
||||
public ReactContext(Context base) {
|
||||
super(base);
|
||||
mInstanceKey = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* A constructor that takes a unique string identifier for the React instance. For bridgeless mode
|
||||
* only - do not use.
|
||||
*/
|
||||
/* package */ ReactContext(Context base, String instanceKey) {
|
||||
super(base);
|
||||
mInstanceKey = instanceKey;
|
||||
}
|
||||
|
||||
/** Set and initialize CatalystInstance for this Context. This should be called exactly once. */
|
||||
@@ -408,4 +419,14 @@ public class ReactContext extends ContextWrapper {
|
||||
public JavaScriptContextHolder getJavaScriptContextHolder() {
|
||||
return mCatalystInstance.getJavaScriptContextHolder();
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO T43898341 Make this package-private once we've consolidated the classes that need this in
|
||||
* this package
|
||||
*
|
||||
* @return The key for the associated React instance
|
||||
*/
|
||||
public @Nullable String getInstanceKey() {
|
||||
return mInstanceKey;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,4 +53,10 @@ public class ThemedReactContext extends ReactContext {
|
||||
public @Nullable Activity getCurrentActivity() {
|
||||
return mReactApplicationContext.getCurrentActivity();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getInstanceKey() {
|
||||
return mReactApplicationContext.getInstanceKey();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user