mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Rename ReactHost.preload -> ReactHost.start (#37694)
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/37694 Rename ReactHost.preload -> ReactHost.start to adhere to stable api bypass-github-export-checks changelog: [internal] internal Reviewed By: RSNara Differential Revision: D46294685 fbshipit-source-id: 683683a557c28759db8925e0c0dd6629463511eb
This commit is contained in:
committed by
Facebook GitHub Bot
parent
001e182f08
commit
579d11ca9e
+53
-53
@@ -196,30 +196,30 @@ public class ReactHost {
|
||||
* errors occur during initialization, and will be cancelled if ReactHost.destroy() is called
|
||||
* before it completes.
|
||||
*/
|
||||
public Task<Void> preload() {
|
||||
public Task<Void> start() {
|
||||
if (ReactFeatureFlags.enableBridgelessArchitectureNewCreateReloadDestroy) {
|
||||
return new_preload();
|
||||
return newStart();
|
||||
}
|
||||
|
||||
return old_preload();
|
||||
return oldStart();
|
||||
}
|
||||
|
||||
@ThreadConfined("ReactHost")
|
||||
private @Nullable Task<Void> mPreloadTask = null;
|
||||
private @Nullable Task<Void> mStartTask = null;
|
||||
|
||||
private Task<Void> old_preload() {
|
||||
final String method = "old_preload()";
|
||||
private Task<Void> oldStart() {
|
||||
final String method = "oldPreload()";
|
||||
return Task.call(
|
||||
() -> {
|
||||
if (mPreloadTask == null) {
|
||||
if (mStartTask == null) {
|
||||
log(method, "Schedule");
|
||||
mPreloadTask =
|
||||
mStartTask =
|
||||
getOrCreateReactInstanceTask()
|
||||
.continueWithTask(
|
||||
task -> {
|
||||
if (task.isFaulted()) {
|
||||
destroy(
|
||||
"old_preload() failure: " + task.getError().getMessage(),
|
||||
"oldPreload() failure: " + task.getError().getMessage(),
|
||||
task.getError());
|
||||
mReactHostDelegate.handleInstanceException(task.getError());
|
||||
}
|
||||
@@ -229,27 +229,27 @@ public class ReactHost {
|
||||
mBGExecutor)
|
||||
.makeVoid();
|
||||
}
|
||||
return mPreloadTask;
|
||||
return mStartTask;
|
||||
},
|
||||
mBGExecutor)
|
||||
.continueWithTask(Task::getResult);
|
||||
}
|
||||
|
||||
private Task<Void> new_preload() {
|
||||
final String method = "new_preload()";
|
||||
private Task<Void> newStart() {
|
||||
final String method = "newPreload()";
|
||||
return Task.call(
|
||||
() -> {
|
||||
if (mPreloadTask == null) {
|
||||
if (mStartTask == null) {
|
||||
log(method, "Schedule");
|
||||
mPreloadTask =
|
||||
waitThen_new_getOrCreateReactInstanceTask()
|
||||
mStartTask =
|
||||
waitThenCallNewGetOrCreateReactInstanceTask()
|
||||
.continueWithTask(
|
||||
(task) -> {
|
||||
if (task.isFaulted()) {
|
||||
mReactHostDelegate.handleInstanceException(task.getError());
|
||||
// Wait for destroy to finish
|
||||
return new_getOrCreateDestroyTask(
|
||||
"new_preload() failure: " + task.getError().getMessage(),
|
||||
return newGetOrCreateDestroyTask(
|
||||
"newPreload() failure: " + task.getError().getMessage(),
|
||||
task.getError())
|
||||
.continueWithTask(destroyTask -> Task.forError(task.getError()))
|
||||
.makeVoid();
|
||||
@@ -258,7 +258,7 @@ public class ReactHost {
|
||||
},
|
||||
mBGExecutor);
|
||||
}
|
||||
return mPreloadTask;
|
||||
return mStartTask;
|
||||
},
|
||||
mBGExecutor)
|
||||
.continueWithTask(Task::getResult);
|
||||
@@ -714,22 +714,22 @@ public class ReactHost {
|
||||
*/
|
||||
private Task<ReactInstance> getOrCreateReactInstanceTask() {
|
||||
if (ReactFeatureFlags.enableBridgelessArchitectureNewCreateReloadDestroy) {
|
||||
return Task.call(this::waitThen_new_getOrCreateReactInstanceTask, mBGExecutor)
|
||||
return Task.call(this::waitThenCallNewGetOrCreateReactInstanceTask, mBGExecutor)
|
||||
.continueWithTask(Task::getResult);
|
||||
}
|
||||
|
||||
return old_getOrCreateReactInstanceTask();
|
||||
return oldGetOrCreateReactInstanceTask();
|
||||
}
|
||||
|
||||
@ThreadConfined("ReactHost")
|
||||
private Task<ReactInstance> waitThen_new_getOrCreateReactInstanceTask() {
|
||||
return waitThen_new_getOrCreateReactInstanceTaskWithRetries(0, 4);
|
||||
private Task<ReactInstance> waitThenCallNewGetOrCreateReactInstanceTask() {
|
||||
return waitThenCallNewGetOrCreateReactInstanceTaskWithRetries(0, 4);
|
||||
}
|
||||
|
||||
@ThreadConfined("ReactHost")
|
||||
private Task<ReactInstance> waitThen_new_getOrCreateReactInstanceTaskWithRetries(
|
||||
private Task<ReactInstance> waitThenCallNewGetOrCreateReactInstanceTaskWithRetries(
|
||||
int tryNum, int maxTries) {
|
||||
final String method = "waitThen_new_getOrCreateReactInstanceTaskWithRetries";
|
||||
final String method = "waitThenCallNewGetOrCreateReactInstanceTaskWithRetries";
|
||||
if (mReloadTask != null) {
|
||||
log(method, "React Native is reloading. Return reload task.");
|
||||
return mReloadTask;
|
||||
@@ -745,7 +745,7 @@ public class ReactHost {
|
||||
+ tryNum
|
||||
+ ").");
|
||||
return mDestroyTask.onSuccessTask(
|
||||
(task) -> waitThen_new_getOrCreateReactInstanceTaskWithRetries(tryNum + 1, maxTries),
|
||||
(task) -> waitThenCallNewGetOrCreateReactInstanceTaskWithRetries(tryNum + 1, maxTries),
|
||||
mBGExecutor);
|
||||
}
|
||||
|
||||
@@ -754,12 +754,12 @@ public class ReactHost {
|
||||
"React Native is tearing down. Not wait for teardown to finish: reached max retries.");
|
||||
}
|
||||
|
||||
return new_getOrCreateReactInstanceTask();
|
||||
return newGetOrCreateReactInstanceTask();
|
||||
}
|
||||
|
||||
@ThreadConfined("ReactHost")
|
||||
private Task<ReactInstance> new_getOrCreateReactInstanceTask() {
|
||||
final String method = "new_getOrCreateReactInstanceTask()";
|
||||
private Task<ReactInstance> newGetOrCreateReactInstanceTask() {
|
||||
final String method = "newGetOrCreateReactInstanceTask()";
|
||||
log(method);
|
||||
|
||||
return mReactInstanceTaskRef.getOrCreate(
|
||||
@@ -852,8 +852,8 @@ public class ReactHost {
|
||||
});
|
||||
}
|
||||
|
||||
private Task<ReactInstance> old_getOrCreateReactInstanceTask() {
|
||||
final String method = "old_getOrCreateReactInstanceTask()";
|
||||
private Task<ReactInstance> oldGetOrCreateReactInstanceTask() {
|
||||
final String method = "oldGetOrCreateReactInstanceTask()";
|
||||
log(method);
|
||||
|
||||
return mReactInstanceTaskRef.getOrCreate(
|
||||
@@ -1031,17 +1031,17 @@ public class ReactHost {
|
||||
method,
|
||||
"Destroying React Native. Waiting for destroy to finish, before reloading React Native.");
|
||||
return mDestroyTask
|
||||
.continueWithTask(task -> new_getOrCreateReloadTask(reason), mBGExecutor)
|
||||
.continueWithTask(task -> newGetOrCreateReloadTask(reason), mBGExecutor)
|
||||
.makeVoid();
|
||||
}
|
||||
|
||||
return new_getOrCreateReloadTask(reason).makeVoid();
|
||||
return newGetOrCreateReloadTask(reason).makeVoid();
|
||||
},
|
||||
mBGExecutor)
|
||||
.continueWithTask(Task::getResult);
|
||||
}
|
||||
|
||||
return old_reload(reason);
|
||||
return oldReload(reason);
|
||||
}
|
||||
|
||||
@ThreadConfined("ReactHost")
|
||||
@@ -1056,8 +1056,8 @@ public class ReactHost {
|
||||
* ReactInstance task work throws an exception.
|
||||
*/
|
||||
@ThreadConfined("ReactHost")
|
||||
private Task<ReactInstance> new_getOrCreateReloadTask(String reason) {
|
||||
final String method = "new_getOrCreateReloadTask()";
|
||||
private Task<ReactInstance> newGetOrCreateReloadTask(String reason) {
|
||||
final String method = "newGetOrCreateReloadTask()";
|
||||
log(method);
|
||||
|
||||
// Log how React Native is destroyed
|
||||
@@ -1159,10 +1159,10 @@ public class ReactHost {
|
||||
mReactInstanceTaskRef.reset();
|
||||
|
||||
log(method, "Resetting preload task ref");
|
||||
mPreloadTask = null;
|
||||
mStartTask = null;
|
||||
|
||||
// Kickstart a new ReactInstance create
|
||||
return new_getOrCreateReactInstanceTask();
|
||||
return newGetOrCreateReactInstanceTask();
|
||||
},
|
||||
mBGExecutor)
|
||||
.onSuccess(
|
||||
@@ -1227,15 +1227,15 @@ public class ReactHost {
|
||||
method,
|
||||
"Reloading React Native. Waiting for reload to finish before destroying React Native.");
|
||||
return mReloadTask.continueWithTask(
|
||||
task -> new_getOrCreateDestroyTask(reason, ex), mBGExecutor);
|
||||
task -> newGetOrCreateDestroyTask(reason, ex), mBGExecutor);
|
||||
}
|
||||
return new_getOrCreateDestroyTask(reason, ex);
|
||||
return newGetOrCreateDestroyTask(reason, ex);
|
||||
},
|
||||
mBGExecutor)
|
||||
.continueWithTask(Task::getResult);
|
||||
}
|
||||
|
||||
old_destroy(reason, ex);
|
||||
oldDestroy(reason, ex);
|
||||
return Task.forResult(nullsafeFIXME(null, "Empty Destroy Task"));
|
||||
}
|
||||
|
||||
@@ -1251,8 +1251,8 @@ public class ReactHost {
|
||||
* ReactInstance task work throws an exception.
|
||||
*/
|
||||
@ThreadConfined("ReactHost")
|
||||
private Task<Void> new_getOrCreateDestroyTask(final String reason, @Nullable Exception ex) {
|
||||
final String method = "new_getOrCreateDestroyTask()";
|
||||
private Task<Void> newGetOrCreateDestroyTask(final String reason, @Nullable Exception ex) {
|
||||
final String method = "newGetOrCreateDestroyTask()";
|
||||
log(method);
|
||||
|
||||
// Log how React Native is destroyed
|
||||
@@ -1335,7 +1335,7 @@ public class ReactHost {
|
||||
mReactInstanceTaskRef.reset();
|
||||
|
||||
log(method, "Resetting Preload task ref");
|
||||
mPreloadTask = null;
|
||||
mStartTask = null;
|
||||
|
||||
log(method, "Resetting destroy task ref");
|
||||
mDestroyTask = null;
|
||||
@@ -1348,8 +1348,8 @@ public class ReactHost {
|
||||
}
|
||||
|
||||
/** Destroy and recreate the ReactInstance and context. */
|
||||
private Task<Void> old_reload(String reason) {
|
||||
final String method = "old_reload()";
|
||||
private Task<Void> oldReload(String reason) {
|
||||
final String method = "oldReload()";
|
||||
log(method);
|
||||
|
||||
// Log how React Native is destroyed
|
||||
@@ -1358,7 +1358,7 @@ public class ReactHost {
|
||||
|
||||
synchronized (mReactInstanceTaskRef) {
|
||||
mMemoryPressureRouter.removeMemoryPressureListener(mMemoryPressureListener);
|
||||
old_destroyReactInstanceAndContext(method, reason);
|
||||
oldDestroyReactInstanceAndContext(method, reason);
|
||||
|
||||
return callAfterGetOrCreateReactInstance(
|
||||
method,
|
||||
@@ -1375,8 +1375,8 @@ public class ReactHost {
|
||||
}
|
||||
|
||||
/** Destroy the specified instance and context. */
|
||||
private void old_destroy(String reason, @Nullable Exception ex) {
|
||||
final String method = "old_destroy()";
|
||||
private void oldDestroy(String reason, @Nullable Exception ex) {
|
||||
final String method = "oldDestroy()";
|
||||
log(method);
|
||||
|
||||
// Log how React Native is destroyed
|
||||
@@ -1391,7 +1391,7 @@ public class ReactHost {
|
||||
mMemoryPressureRouter.destroy(reactContext);
|
||||
}
|
||||
|
||||
old_destroyReactInstanceAndContext(method, reason);
|
||||
oldDestroyReactInstanceAndContext(method, reason);
|
||||
|
||||
// Remove all attached surfaces
|
||||
log(method, "Clearing attached surfaces");
|
||||
@@ -1409,8 +1409,8 @@ public class ReactHost {
|
||||
}
|
||||
}
|
||||
|
||||
private void old_destroyReactInstanceAndContext(final String callingMethod, final String reason) {
|
||||
final String method = "old_destroyReactInstanceAndContext(" + callingMethod + ")";
|
||||
private void oldDestroyReactInstanceAndContext(final String callingMethod, final String reason) {
|
||||
final String method = "oldDestroyReactInstanceAndContext(" + callingMethod + ")";
|
||||
log(method);
|
||||
|
||||
synchronized (mReactInstanceTaskRef) {
|
||||
@@ -1454,7 +1454,7 @@ public class ReactHost {
|
||||
|
||||
// Re-enable preloads
|
||||
log(method, "Resetting Preload task ref");
|
||||
mPreloadTask = null;
|
||||
mStartTask = null;
|
||||
});
|
||||
} else {
|
||||
raiseSoftException(
|
||||
@@ -1469,7 +1469,7 @@ public class ReactHost {
|
||||
mBGExecutor.execute(
|
||||
() -> {
|
||||
log(method, "Resetting Preload task ref");
|
||||
mPreloadTask = null;
|
||||
mStartTask = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -119,7 +119,7 @@ public class ReactHostTest {
|
||||
|
||||
assertThat(mReactHost.isInstanceInitialized()).isFalse();
|
||||
|
||||
mReactHost.preload().waitForCompletion();
|
||||
mReactHost.start().waitForCompletion();
|
||||
|
||||
assertThat(mReactHost.isInstanceInitialized()).isTrue();
|
||||
assertThat(mReactHost.getCurrentReactContext()).isNotNull();
|
||||
|
||||
Reference in New Issue
Block a user