From 579d11ca9e321909c284a5ed97df29128fe63342 Mon Sep 17 00:00:00 2001 From: David Vacca Date: Mon, 12 Jun 2023 20:19:06 -0700 Subject: [PATCH] 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 --- .../facebook/react/bridgeless/ReactHost.java | 106 +++++++++--------- .../react/bridgeless/ReactHostTest.java | 2 +- 2 files changed, 54 insertions(+), 54 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactHost.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactHost.java index 0a6b5edfca0..1eee44cf0c7 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactHost.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/bridgeless/ReactHost.java @@ -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 preload() { + public Task start() { if (ReactFeatureFlags.enableBridgelessArchitectureNewCreateReloadDestroy) { - return new_preload(); + return newStart(); } - return old_preload(); + return oldStart(); } @ThreadConfined("ReactHost") - private @Nullable Task mPreloadTask = null; + private @Nullable Task mStartTask = null; - private Task old_preload() { - final String method = "old_preload()"; + private Task 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 new_preload() { - final String method = "new_preload()"; + private Task 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 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 waitThen_new_getOrCreateReactInstanceTask() { - return waitThen_new_getOrCreateReactInstanceTaskWithRetries(0, 4); + private Task waitThenCallNewGetOrCreateReactInstanceTask() { + return waitThenCallNewGetOrCreateReactInstanceTaskWithRetries(0, 4); } @ThreadConfined("ReactHost") - private Task waitThen_new_getOrCreateReactInstanceTaskWithRetries( + private Task 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 new_getOrCreateReactInstanceTask() { - final String method = "new_getOrCreateReactInstanceTask()"; + private Task newGetOrCreateReactInstanceTask() { + final String method = "newGetOrCreateReactInstanceTask()"; log(method); return mReactInstanceTaskRef.getOrCreate( @@ -852,8 +852,8 @@ public class ReactHost { }); } - private Task old_getOrCreateReactInstanceTask() { - final String method = "old_getOrCreateReactInstanceTask()"; + private Task 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 new_getOrCreateReloadTask(String reason) { - final String method = "new_getOrCreateReloadTask()"; + private Task 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 new_getOrCreateDestroyTask(final String reason, @Nullable Exception ex) { - final String method = "new_getOrCreateDestroyTask()"; + private Task 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 old_reload(String reason) { - final String method = "old_reload()"; + private Task 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; }); } } diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/bridgeless/ReactHostTest.java b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/bridgeless/ReactHostTest.java index 8c0218e07a2..21950e7c54c 100644 --- a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/bridgeless/ReactHostTest.java +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/bridgeless/ReactHostTest.java @@ -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();