From 6b1a899ef793882776941e4ae608cbc6121cfd07 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Thu, 28 Jan 2021 12:36:55 -0800 Subject: [PATCH] BackgroundExecutor: rename shouldCancel to shouldYield Summary: Changelog: [internal] Name `shouldCancel` is misleading. It implies the commit is cancelled and doesn't happen. `shouldYield` expresses the intent better, because the commit's changes do eventually reach mounting layer but the current commit is rather yielding to the next one. Reviewed By: mdvacca Differential Revision: D26126121 fbshipit-source-id: 18988f217cbc651f0010f6e2381682bdbaed8bd4 --- ReactCommon/react/renderer/mounting/ShadowTree.cpp | 4 ++-- ReactCommon/react/renderer/mounting/ShadowTree.h | 7 ++++--- ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp | 6 +++--- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/ReactCommon/react/renderer/mounting/ShadowTree.cpp b/ReactCommon/react/renderer/mounting/ShadowTree.cpp index 3a56b4631cc..fdfa5b990fd 100644 --- a/ReactCommon/react/renderer/mounting/ShadowTree.cpp +++ b/ReactCommon/react/renderer/mounting/ShadowTree.cpp @@ -332,7 +332,7 @@ CommitStatus ShadowTree::tryCommit( auto newRootShadowNode = transaction(*oldRevision.rootShadowNode); if (!newRootShadowNode || - (commitOptions.shouldCancel && commitOptions.shouldCancel())) { + (commitOptions.shouldYield && commitOptions.shouldYield())) { return CommitStatus::Cancelled; } @@ -372,7 +372,7 @@ CommitStatus ShadowTree::tryCommit( *this, oldRootShadowNode, newRootShadowNode); if (!newRootShadowNode || - (commitOptions.shouldCancel && commitOptions.shouldCancel())) { + (commitOptions.shouldYield && commitOptions.shouldYield())) { return CommitStatus::Cancelled; } diff --git a/ReactCommon/react/renderer/mounting/ShadowTree.h b/ReactCommon/react/renderer/mounting/ShadowTree.h index 8dd6dff7428..c459380e41e 100644 --- a/ReactCommon/react/renderer/mounting/ShadowTree.h +++ b/ReactCommon/react/renderer/mounting/ShadowTree.h @@ -55,9 +55,10 @@ class ShadowTree final { struct CommitOptions { bool enableStateReconciliation{false}; - // Lambda called inside `tryCommit`. If false is returned, commit is - // cancelled. - std::function shouldCancel; + + // Called during `tryCommit` phase. Returning true indicates current commit + // should yield to the next commit. + std::function shouldYield; }; /* diff --git a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp index 2e1367be594..3dc2495bf7f 100644 --- a/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp +++ b/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp @@ -458,15 +458,15 @@ jsi::Value UIManagerBinding::get( mostRecentSurfaceId = surfaceId; sharedUIManager->backgroundExecutor_( [=, eventCount = completeRootEventCounter.load()] { - auto shouldCancel = [=]() -> bool { + auto shouldYield = [=]() -> bool { // If `completeRootEventCounter` was incremented, another // `completeSurface` call has been scheduled and current - // `completeSurface` should be cancelled. + // `completeSurface` should yield to it. return completeRootEventCounter > eventCount && mostRecentSurfaceId == surfaceId; }; sharedUIManager->completeSurface( - surfaceId, shadowNodeList, {true, shouldCancel}); + surfaceId, shadowNodeList, {true, shouldYield}); }); return jsi::Value::undefined();