RN: Simplify Context Creation (Android)

Summary:
Every call site is either already using `createReactContextInBackground` correctly or guarding the invocation using `hasStartedCreatingInitialContext`. This is an unnecessary and overly complex dance that can be simplified.

This revision simplifies the use of `createReactContextInBackground` by integrating the check. This is not a breaking change.

Reviewed By: zackargyle, mdvacca

Differential Revision: D15566632

fbshipit-source-id: 7b50285c9ac6776d1297d2c9c53dff208851b722
This commit is contained in:
Tim Yung 2019-05-30 18:47:10 -07:00 коммит произвёл Facebook Github Bot
Родитель 060a3ea3bf
Коммит 739651afa1
3 изменённых файлов: 7 добавлений и 17 удалений

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

@ -108,9 +108,7 @@ public abstract class HeadlessJsTaskService extends Service implements HeadlessJ
reactInstanceManager.removeReactInstanceEventListener(this);
}
});
if (!reactInstanceManager.hasStartedCreatingInitialContext()) {
reactInstanceManager.createReactContextInBackground();
}
reactInstanceManager.createReactContextInBackground();
} else {
invokeStartTask(reactContext, taskConfig);
}

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

@ -325,23 +325,17 @@ public class ReactInstanceManager {
/**
* Trigger react context initialization asynchronously in a background async task. This enables
* applications to pre-load the application JS, and execute global code before
* {@link ReactRootView} is available and measured. This should only be called the first time the
* application is set up, which is enforced to keep developers from accidentally creating their
* application multiple times without realizing it.
* {@link ReactRootView} is available and measured.
*
* Called from UI thread.
*/
@ThreadConfined(UI)
public void createReactContextInBackground() {
Log.d(ReactConstants.TAG, "ReactInstanceManager.createReactContextInBackground()");
Assertions.assertCondition(
!mHasStartedCreatingInitialContext,
"createReactContextInBackground should only be called when creating the react " +
"application for the first time. When reloading JS, e.g. from a new file, explicitly" +
"use recreateReactContextInBackground");
mHasStartedCreatingInitialContext = true;
recreateReactContextInBackgroundInner();
if (!mHasStartedCreatingInitialContext) {
mHasStartedCreatingInitialContext = true;
recreateReactContextInBackgroundInner();
}
}
/**

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

@ -394,9 +394,7 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
// TODO initialize surface here
}
if (!mReactInstanceManager.hasStartedCreatingInitialContext()) {
mReactInstanceManager.createReactContextInBackground();
}
mReactInstanceManager.createReactContextInBackground();
attachToReactInstanceManager();