Rename String surfaceID to surfaceName/moduleName, add int surfaceId to ThemedReactContext

Summary:
There's a field called `surfaceID` in a couple of classes that isn't the same as the integer `surfaceId` in Fabric.

For consistency, I've deprecated a couple of them, or renamed when appropriate.

In addition, now we're passing the actual integer surfaceId into the ThemedReactContext. This means that every single View created in Fabric gets annotated with the surfaceId it's in. Currently this isn't used, but the idea is that now each View has a mapping back to its surface, which could be used to simplify / optimize operations with SurfaceMountingManager. In particular, we might be able to use this in the future to optimize animations and/or event emitters.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D26021571

fbshipit-source-id: b7db7de123db07fa928a6f815be86bdbb030e62c
This commit is contained in:
Joshua Gross 2021-01-22 19:29:00 -08:00 коммит произвёл Facebook GitHub Bot
Родитель e7783ff9ad
Коммит 8357b39908
5 изменённых файлов: 47 добавлений и 14 удалений

Просмотреть файл

@ -188,7 +188,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
ThemedReactContext reactContext =
new ThemedReactContext(
mReactApplicationContext, rootView.getContext(), reactRootView.getSurfaceID());
mReactApplicationContext, rootView.getContext(), reactRootView.getSurfaceID(), rootTag);
mMountingManager.startSurface(rootTag, rootView, reactContext);
String moduleName = reactRootView.getJSModuleName();
if (ENABLE_FABRIC_LOGS) {
@ -220,7 +220,7 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
Context context = rootView.getContext();
ThemedReactContext reactContext =
new ThemedReactContext(mReactApplicationContext, context, moduleName);
new ThemedReactContext(mReactApplicationContext, context, moduleName, rootTag);
if (ENABLE_FABRIC_LOGS) {
FLog.d(TAG, "Starting surface for module: %s and reactTag: %d", moduleName, rootTag);
}

Просмотреть файл

@ -27,20 +27,32 @@ import com.facebook.react.bridge.ReactContext;
public class ThemedReactContext extends ReactContext {
private final ReactApplicationContext mReactApplicationContext;
@Nullable private final String mSurfaceID;
@Nullable private final String mModuleName;
private final int mSurfaceId;
@Deprecated
public ThemedReactContext(ReactApplicationContext reactApplicationContext, Context base) {
this(reactApplicationContext, base, null);
this(reactApplicationContext, base, null, -1);
}
@Deprecated
public ThemedReactContext(
ReactApplicationContext reactApplicationContext, Context base, @Nullable String moduleName) {
this(reactApplicationContext, base, moduleName, -1);
}
public ThemedReactContext(
ReactApplicationContext reactApplicationContext, Context base, @Nullable String surfaceID) {
ReactApplicationContext reactApplicationContext,
Context base,
@Nullable String moduleName,
int surfaceId) {
super(base);
if (reactApplicationContext.hasCatalystInstance()) {
initializeWithInstance(reactApplicationContext.getCatalystInstance());
}
mReactApplicationContext = reactApplicationContext;
mSurfaceID = surfaceID;
mModuleName = moduleName;
mSurfaceId = surfaceId;
}
@Override
@ -64,11 +76,27 @@ public class ThemedReactContext extends ReactContext {
}
/**
* @return a {@link String} that represents the ID of the js application that is being rendered
* with this {@link ThemedReactContext}
* This is misnamed but has some uses out in the wild. It will be deleted in a future release of
* RN.
*
* @return a {@link String} that represents the module name of the js application that is being
* rendered with this {@link ThemedReactContext}
*/
@Deprecated
public @Nullable String getSurfaceID() {
return mSurfaceID;
return mModuleName;
}
/**
* @return a {@link String} that represents the module name of the js application that is being
* rendered with this {@link ThemedReactContext}
*/
public @Nullable String getModuleName() {
return mModuleName;
}
public int getSurfaceId() {
return mSurfaceId;
}
public ReactApplicationContext getReactApplicationContext() {

Просмотреть файл

@ -451,9 +451,14 @@ public class UIManagerModule extends ReactContextBaseJavaModule
Systrace.beginSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "UIManagerModule.addRootView");
final int tag = ReactRootViewTagGenerator.getNextRootViewTag();
final ReactApplicationContext reactApplicationContext = getReactApplicationContext();
// We pass in a surfaceId of -1 here - it is used only in Fabric.
final ThemedReactContext themedRootContext =
new ThemedReactContext(
reactApplicationContext, rootView.getContext(), ((ReactRoot) rootView).getSurfaceID());
reactApplicationContext,
rootView.getContext(),
((ReactRoot) rootView).getSurfaceID(),
-1);
mUIImplementation.registerRootView(rootView, tag, themedRootContext);
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);

Просмотреть файл

@ -20,9 +20,9 @@ public interface ReactCallerContextFactory {
/**
* This method will be called at the time {@link ReactImageManager} creates {@link ReactImageView}
*
* @param surfaceID {@link String} used to log the name of the surface
* @param surfaceName {@link String} used to log the name of the surface
* @return an {@link Object} that represents the CallerContext.
*/
@Nullable
Object getOrCreateCallerContext(@Nullable String surfaceID, @Nullable String analyticTag);
Object getOrCreateCallerContext(@Nullable String surfaceName, @Nullable String analyticTag);
}

Просмотреть файл

@ -107,7 +107,7 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
public ReactImageView createViewInstance(ThemedReactContext context) {
Object callerContext =
mCallerContextFactory != null
? mCallerContextFactory.getOrCreateCallerContext(context.getSurfaceID(), null)
? mCallerContextFactory.getOrCreateCallerContext(context.getModuleName(), null)
: getCallerContext();
return new ReactImageView(
context, getDraweeControllerBuilder(), mGlobalImageLoadListener, callerContext);
@ -129,7 +129,7 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
if (mCallerContextFactory != null) {
view.updateCallerContext(
mCallerContextFactory.getOrCreateCallerContext(
((ThemedReactContext) view.getContext()).getSurfaceID(), analyticTag));
((ThemedReactContext) view.getContext()).getModuleName(), analyticTag));
}
}