From 7f2529de7bc9ab1617eaf571e950d0717c3102a6 Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 9 Jan 2024 19:07:01 -0800 Subject: [PATCH] Refactor: ReactHost: Remove new prefix from task creation methods (#42169) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/42169 Changelog: [Internal] Reviewed By: mdvacca Differential Revision: D52495531 fbshipit-source-id: 2651b462a0dba437c8652fefd38421f2d826935a --- .../facebook/react/runtime/ReactHostImpl.java | 50 +++++++++---------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java index 75aacd7e0d59c2..cd929cc3b50d24 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/runtime/ReactHostImpl.java @@ -200,7 +200,7 @@ public LifecycleState getLifecycleState() { */ @Override public TaskInterface start() { - return Task.call(this::newGetOrCreateStartTask, mBGExecutor).continueWithTask(Task::getResult); + return Task.call(this::getOrCreateStartTask, mBGExecutor).continueWithTask(Task::getResult); } /** Initialize and run a React Native surface in a background without mounting real views. */ @@ -442,17 +442,17 @@ public TaskInterface reload(String reason) { log(method, "Waiting for destroy to finish, before reloading React Native."); reloadTask = mDestroyTask - .continueWithTask(task -> newGetOrCreateReloadTask(reason), mBGExecutor) + .continueWithTask(task -> getOrCreateReloadTask(reason), mBGExecutor) .makeVoid(); } else { - reloadTask = newGetOrCreateReloadTask(reason).makeVoid(); + reloadTask = getOrCreateReloadTask(reason).makeVoid(); } return reloadTask.continueWithTask( task -> { if (task.isFaulted()) { mReactHostDelegate.handleInstanceException(task.getError()); - return newGetOrCreateDestroyTask("Reload failed", task.getError()); + return getOrCreateDestroyTask("Reload failed", task.getError()); } return task; @@ -483,9 +483,9 @@ public TaskInterface destroy(String reason, @Nullable Exception ex) { method, "Reloading React Native. Waiting for reload to finish before destroying React Native."); return mReloadTask.continueWithTask( - task -> newGetOrCreateDestroyTask(reason, ex), mBGExecutor); + task -> getOrCreateDestroyTask(reason, ex), mBGExecutor); } - return newGetOrCreateDestroyTask(reason, ex); + return getOrCreateDestroyTask(reason, ex); }, mBGExecutor) .continueWithTask(Task::getResult); @@ -706,19 +706,19 @@ public void removeBeforeDestroyListener(@NonNull Function0 onBeforeDestroy private @Nullable Task mStartTask = null; @ThreadConfined("ReactHost") - private Task newGetOrCreateStartTask() { + private Task getOrCreateStartTask() { + final String method = "getOrCreateStartTask()"; if (mStartTask == null) { - final String method = "newGetOrCreateStartTask()"; log(method, "Schedule"); mStartTask = - waitThenCallNewGetOrCreateReactInstanceTask() + waitThenCallGetOrCreateReactInstanceTask() .continueWithTask( (task) -> { if (task.isFaulted()) { mReactHostDelegate.handleInstanceException(task.getError()); // Wait for destroy to finish - return newGetOrCreateDestroyTask( - "newGetOrCreateStartTask() failure: " + task.getError().getMessage(), + return getOrCreateDestroyTask( + "getOrCreateStartTask() failure: " + task.getError().getMessage(), task.getError()) .continueWithTask(destroyTask -> Task.forError(task.getError())) .makeVoid(); @@ -818,19 +818,19 @@ private BridgelessReactContext getOrCreateReactContext() { * destroying, will wait until destroy is finished, before creating. */ private Task getOrCreateReactInstance() { - return Task.call(this::waitThenCallNewGetOrCreateReactInstanceTask, mBGExecutor) + return Task.call(this::waitThenCallGetOrCreateReactInstanceTask, mBGExecutor) .continueWithTask(Task::getResult); } @ThreadConfined("ReactHost") - private Task waitThenCallNewGetOrCreateReactInstanceTask() { - return waitThenCallNewGetOrCreateReactInstanceTaskWithRetries(0, 4); + private Task waitThenCallGetOrCreateReactInstanceTask() { + return waitThenCallGetOrCreateReactInstanceTaskWithRetries(0, 4); } @ThreadConfined("ReactHost") - private Task waitThenCallNewGetOrCreateReactInstanceTaskWithRetries( + private Task waitThenCallGetOrCreateReactInstanceTaskWithRetries( int tryNum, int maxTries) { - final String method = "waitThenCallNewGetOrCreateReactInstanceTaskWithRetries"; + final String method = "waitThenCallGetOrCreateReactInstanceTaskWithRetries"; if (mReloadTask != null) { log(method, "React Native is reloading. Return reload task."); return mReloadTask; @@ -846,7 +846,7 @@ private Task waitThenCallNewGetOrCreateReactInstanceTaskWithRetri + tryNum + ")."); return mDestroyTask.onSuccessTask( - (task) -> waitThenCallNewGetOrCreateReactInstanceTaskWithRetries(tryNum + 1, maxTries), + (task) -> waitThenCallGetOrCreateReactInstanceTaskWithRetries(tryNum + 1, maxTries), mBGExecutor); } @@ -855,12 +855,12 @@ private Task waitThenCallNewGetOrCreateReactInstanceTaskWithRetri "React Native is tearing down. Not wait for teardown to finish: reached max retries."); } - return newGetOrCreateReactInstanceTask(); + return getOrCreateReactInstanceTask(); } @ThreadConfined("ReactHost") - private Task newGetOrCreateReactInstanceTask() { - final String method = "newGetOrCreateReactInstanceTask()"; + private Task getOrCreateReactInstanceTask() { + final String method = "getOrCreateReactInstanceTask()"; log(method); return mReactInstanceTaskRef.getOrCreate( @@ -1150,8 +1150,8 @@ private ReactInstanceTaskUnwrapper createReactInstanceUnwraper( * ReactInstance task work throws an exception. */ @ThreadConfined("ReactHost") - private Task newGetOrCreateReloadTask(String reason) { - final String method = "newGetOrCreateReloadTask()"; + private Task getOrCreateReloadTask(String reason) { + final String method = "getOrCreateReloadTask()"; log(method); // Log how React Native is destroyed @@ -1262,7 +1262,7 @@ private Task newGetOrCreateReloadTask(String reason) { mStartTask = null; // Kickstart a new ReactInstance create - return newGetOrCreateReactInstanceTask(); + return getOrCreateReactInstanceTask(); }, mBGExecutor) .continueWithTask( @@ -1322,8 +1322,8 @@ private Task newGetOrCreateReloadTask(String reason) { * ReactInstance task work throws an exception. */ @ThreadConfined("ReactHost") - private Task newGetOrCreateDestroyTask(final String reason, @Nullable Exception ex) { - final String method = "newGetOrCreateDestroyTask()"; + private Task getOrCreateDestroyTask(final String reason, @Nullable Exception ex) { + final String method = "getOrCreateDestroyTask()"; log(method); // Log how React Native is destroyed