make main component name nullable

Summary: Sometimes the main component name is not known at activity construction time and depends on e.g. reading shared preferences. To support this use case, make `(Fragment)ReactActivity#getMainComponentName()` nullable and return `null` by default. In this case, the app will not be loaded in `onCreate` by default and the user has to call `loadApp` manually once the component name is known.

Reviewed By: andreicoman11

Differential Revision: D3722517

fbshipit-source-id: 062eed158798606e4160f1c142b23fd98ca618c8
This commit is contained in:
Felix Oghina
2016-08-16 07:33:50 -07:00
committed by Facebook Github Bot 8
parent 2f78852411
commit af2bb20893
3 changed files with 34 additions and 7 deletions

View File

@@ -9,6 +9,8 @@
package com.facebook.react;
import javax.annotation.Nullable;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@@ -35,7 +37,9 @@ public abstract class ReactActivity extends Activity
* This is used to schedule rendering of the component.
* e.g. "MoviesApp"
*/
protected abstract String getMainComponentName();
protected @Nullable String getMainComponentName() {
return null;
}
/**
* Called at construction time, override if you have a custom delegate implementation.
@@ -120,4 +124,8 @@ public abstract class ReactActivity extends Activity
protected final ReactInstanceManager getReactInstanceManager() {
return mDelegate.getReactInstanceManager();
}
protected final void loadApp(String appKey) {
mDelegate.loadApp(appKey);
}
}