Use startSurface on Android

Summary:
Right now calling FabricUIManager.addRootView() doesn't actually start running the application on Android. This diff:

1. Removes the #ifndef so that we actually call UIManagerBinding.startSurface() on Android
2. Passes through the JS module name from addRootView so we can render the surface (falls back to an empty string if not provided, which is the current behavior)
3. Adds an option for starting the surface using `RN$SurfaceRegistry` instead of `AppRegistry`, if that global property has been defined in JS. This is used for Venice (bridgeless RN)

Reviewed By: shergin

Differential Revision: D15366200

fbshipit-source-id: 4a506a589108905d4852b9723aac6fb0fad2d86e
This commit is contained in:
Emily Janzer
2019-05-23 13:47:30 -07:00
committed by Facebook Github Bot
parent d742c7be36
commit f23da3aeb0
6 changed files with 36 additions and 17 deletions
@@ -128,13 +128,18 @@ public class FabricUIManager implements UIManager, LifecycleEventListener {
@Override
public <T extends View> int addRootView(
final T rootView, final WritableMap initialProps, final @Nullable String initialUITemplate) {
final T rootView, final WritableMap initialProps, final @Nullable String initialUITemplate) {
return addRootView(rootView, null, initialProps, initialUITemplate);
}
public <T extends View> int addRootView(
final T rootView, final @Nullable String moduleName, final WritableMap initialProps, final @Nullable String initialUITemplate) {
final int rootTag = ReactRootViewTagGenerator.getNextRootViewTag();
ThemedReactContext reactContext =
new ThemedReactContext(mReactApplicationContext, rootView.getContext());
mMountingManager.addRootView(rootTag, rootView);
mReactContextForRootTag.put(rootTag, reactContext);
mBinding.startSurface(rootTag, (NativeMap) initialProps);
mBinding.startSurface(rootTag, moduleName == null ? "" : moduleName, (NativeMap) initialProps);
if (initialUITemplate != null) {
mBinding.renderTemplateToSurface(rootTag, initialUITemplate);
}
@@ -40,7 +40,7 @@ public class Binding {
ComponentFactoryDelegate componentsRegistry,
Object reactNativeConfig);
public native void startSurface(int surfaceId, NativeMap initialProps);
public native void startSurface(int surfaceId, String moduleName, NativeMap initialProps);
public native void renderTemplateToSurface(int surfaceId, String uiTemplate);
@@ -45,9 +45,13 @@ jni::local_ref<Binding::jhybriddata> Binding::initHybrid(
return makeCxxInstance();
}
void Binding::startSurface(jint surfaceId, NativeMap *initialProps) {
void Binding::startSurface(
jint surfaceId,
jni::alias_ref<jstring> moduleName,
NativeMap *initialProps) {
if (scheduler_) {
scheduler_->startSurface(surfaceId, "", initialProps->consume());
scheduler_->startSurface(
surfaceId, moduleName->toStdString(), initialProps->consume());
}
}
@@ -50,7 +50,10 @@ class Binding : public jni::HybridClass<Binding>, public SchedulerDelegate {
ComponentFactoryDelegate *componentsRegistry,
jni::alias_ref<jobject> reactNativeConfig);
void startSurface(jint surfaceId, NativeMap *initialProps);
void startSurface(
jint surfaceId,
jni::alias_ref<jstring> moduleName,
NativeMap *initialProps);
void renderTemplateToSurface(jint surfaceId, jstring uiTemplate);