Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions packages/react-native/React/Fabric/RCTSurfacePresenter.mm
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ - (instancetype)initWithContextContainer:(std::shared_ptr<const ContextContainer
_mountingManager.contextContainer = contextContainer;
_mountingManager.delegate = self;

if (ReactNativeFeatureFlags::enableFabricCommitBranching()) {
if (ReactNativeFeatureFlags::enableFabricCommitBranchingMergeOnMainThread()) {
_mergeRunLoopObserverDelegate = std::make_shared<ReactRevisionMergeRunLoopObserverDelegate>(self);
_mergeRunLoopObserver = std::make_unique<const MainRunLoopObserver>(
RunLoopObserver::Activity::BeforeWaiting, _mergeRunLoopObserverDelegate);
Expand Down Expand Up @@ -350,7 +350,7 @@ - (void)schedulerShouldRenderTransactions:(std::shared_ptr<const MountingCoordin

- (void)schedulerShouldMergeReactRevision:(SurfaceId)surfaceId
{
if (RCTIsMainQueue()) {
if (RCTIsMainQueue() || !ReactNativeFeatureFlags::enableFabricCommitBranchingMergeOnMainThread()) {
[self _mergeReactRevisionForSurfaceId:surfaceId];
return;
}
Expand All @@ -369,7 +369,6 @@ - (void)schedulerShouldMergeReactRevision:(SurfaceId)surfaceId

- (void)_mergeReactRevisionForSurfaceId:(SurfaceId)surfaceId
{
RCTAssertMainQueue();
RCTScheduler *scheduler = [self scheduler];
if (!scheduler) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ public void doFrameGuarded(long frameTimeNanos) {

// Drain pending React revision merges first so that animations,
// preallocation, and mount items operate against the latest revision.
if (ReactNativeFeatureFlags.enableFabricCommitBranching()) {
if (ReactNativeFeatureFlags.enableFabricCommitBranchingMergeOnMainThread()) {
FabricUIManagerBinding binding = mBinding;
if (binding != null) {
Integer mergeSurfaceId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -767,17 +767,24 @@ void FabricUIManagerBinding::schedulerShouldRenderTransactions(

void FabricUIManagerBinding::schedulerShouldMergeReactRevision(
SurfaceId surfaceId) {
std::shared_lock lock(installMutex_);
auto mountingManager =
getMountingManager("schedulerShouldMergeReactRevision");
if (mountingManager) {
mountingManager->scheduleReactRevisionMerge(surfaceId);
if (ReactNativeFeatureFlags::enableFabricCommitBranchingMergeOnMainThread()) {
auto mountingManager =
getMountingManager("schedulerShouldMergeReactRevision");
if (mountingManager) {
mountingManager->scheduleReactRevisionMerge(surfaceId);
}
} else {
mergeReactRevision(surfaceId);
}
}

void FabricUIManagerBinding::mergeReactRevision(SurfaceId surfaceId) {
std::shared_lock lock(installMutex_);
scheduler_->getUIManager()->getShadowTreeRegistry().visit(
auto scheduler = getScheduler();
if (!scheduler) {
return;
}

scheduler->getUIManager()->getShadowTreeRegistry().visit(
surfaceId,
[](const ShadowTree& shadowTree) { shadowTree.mergeReactRevision(); });
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ void ShadowTree::mount(ShadowTreeRevision revision, bool mountSynchronously)
}

void ShadowTree::mergeReactRevision() const {
TraceSection s("ShadowTree::mergeReactRevision");
ShadowTreeRevision promotedRevision;
std::vector<ShadowTreeRevision> promotedRevisions;
// If props updates accumulation is guaranteed, we can merge the promoted
Expand Down Expand Up @@ -568,7 +569,7 @@ void ShadowTree::mergeReactRevision() const {
}
}

void ShadowTree::promoteReactRevision() const {
bool ShadowTree::promoteReactRevision() const {
// Promote only when props updates accumulation is guaranteed. Otherwise,
// queuedReactRevisions_ will be used instead.
if (isPropsUpdatesAccumulationGuaranteed()) {
Expand All @@ -579,7 +580,7 @@ void ShadowTree::promoteReactRevision() const {
// have more than one promotion in a row. In this case, all but the first
// one should no-op.
if (!currentReactRevision_.has_value()) {
return;
return false;
}
currentReactRevision = currentReactRevision_.value();
}
Expand All @@ -592,7 +593,7 @@ void ShadowTree::promoteReactRevision() const {
UniqueLock lock = uniqueRevisionLock(false);

if (queuedReactRevisions_.empty()) {
return;
return false;
}

// Move all queued revisions to the promoted revisions.
Expand All @@ -603,7 +604,7 @@ void ShadowTree::promoteReactRevision() const {
queuedReactRevisions_.clear();
}

delegate_.shadowTreeDidPromoteReactRevision(*this);
return true;
}

void ShadowTree::scheduleReactRevisionPromotion() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ class ShadowTree final {

/**
* Promotes the current React revision to be merged into the main branch of the
* ShadowTree.
* ShadowTree. Returns `true` if a revision was promoted.
*/
void promoteReactRevision() const;
bool promoteReactRevision() const;

/**
* Commits the currently promoted React revision to the "main" branch of the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ class ShadowTreeDelegate {
*/
virtual void shadowTreeDidFinishReactCommit(const ShadowTree &shadowTree) const = 0;

/*
* Called right after Shadow Tree promotes a React revision of the tree to
* be merged.
*/
virtual void shadowTreeDidPromoteReactRevision(const ShadowTree &shadowTree) const = 0;

/*
* Called right after a Shadow Tree commits a new tree, reporting the nodes
* whose layout changed in this commit.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@ class DummyShadowTreeDelegate : public ShadowTreeDelegate {

void shadowTreeDidFinishReactCommit(
const ShadowTree& /*shadowTree*/) const override {}

void shadowTreeDidPromoteReactRevision(
const ShadowTree& /*shadowTree*/) const override {}
};

} // namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ class DummyShadowTreeDelegate : public ShadowTreeDelegate {

void shadowTreeDidFinishReactCommit(
const ShadowTree& /*shadowTree*/) const override {}

void shadowTreeDidPromoteReactRevision(
const ShadowTree& /*shadowTree*/) const override {}
};

namespace {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -417,19 +417,24 @@ void Scheduler::uiManagerShouldRemoveEventListener(
}

void Scheduler::uiManagerDidFinishReactCommit(const ShadowTree& shadowTree) {
if (delegate_ == nullptr) {
return;
}

auto surfaceId = shadowTree.getSurfaceId();
runtimeScheduler_->scheduleRenderingUpdate(
surfaceId, [surfaceId, uiManager = uiManager_]() {
surfaceId, [surfaceId, uiManager = uiManager_, delegate = delegate_]() {
bool promoted = false;

uiManager->getShadowTreeRegistry().visit(
surfaceId,
[](const ShadowTree& tree) { tree.promoteReactRevision(); });
});
}
surfaceId, [&](const ShadowTree& tree) {
promoted = tree.promoteReactRevision();
});

void Scheduler::uiManagerDidPromoteReactRevision(const ShadowTree& shadowTree) {
if (delegate_ != nullptr) {
delegate_->schedulerShouldMergeReactRevision(shadowTree.getSurfaceId());
}
if (promoted) {
delegate->schedulerShouldMergeReactRevision(surfaceId);
}
});
}

void Scheduler::uiManagerDidStartSurface(const ShadowTree& shadowTree) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ class Scheduler final : public UIManagerDelegate {
void uiManagerShouldAddEventListener(std::shared_ptr<const EventListener> listener) final;
void uiManagerShouldRemoveEventListener(const std::shared_ptr<const EventListener> &listener) final;
void uiManagerDidFinishReactCommit(const ShadowTree &shadowTree) override;
void uiManagerDidPromoteReactRevision(const ShadowTree &shadowTree) override;
void uiManagerDidStartSurface(const ShadowTree &shadowTree) override;

#pragma mark - ContextContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,13 +673,6 @@ void UIManager::shadowTreeDidFinishReactCommit(
}
}

void UIManager::shadowTreeDidPromoteReactRevision(
const ShadowTree& shadowTree) const {
if (delegate_ != nullptr) {
delegate_->uiManagerDidPromoteReactRevision(shadowTree);
}
}

void UIManager::shadowTreeDidCommit(
const ShadowTree& shadowTree,
const RootShadowNode::Shared& rootShadowNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ class UIManager final : public ShadowTreeDelegate {

void shadowTreeDidFinishReactCommit(const ShadowTree &shadowTree) const override;

void shadowTreeDidPromoteReactRevision(const ShadowTree &shadowTree) const override;

void shadowTreeDidCommit(
const ShadowTree &shadowTree,
const RootShadowNode::Shared &rootShadowNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ class UIManagerDelegate {
*/
virtual void uiManagerDidFinishReactCommit(const ShadowTree &shadowTree) = 0;

/*
* Called after a React revision of the shadow tree is promoted to be merged.
*/
virtual void uiManagerDidPromoteReactRevision(const ShadowTree &shadowTree) = 0;

using OnSurfaceStartCallback = std::function<void(const ShadowTree &shadowTree)>;
virtual void uiManagerShouldAddOnSurfaceStartCallback(OnSurfaceStartCallback &&callback) = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ class FakeShadowTreeDelegate : public ShadowTreeDelegate {

void shadowTreeDidFinishReactCommit(
const ShadowTree& /*shadowTree*/) const override {}

void shadowTreeDidPromoteReactRevision(
const ShadowTree& /*shadowTree*/) const override {}
};

class LazyShadowTreeRevisionConsistencyManagerTest : public ::testing::Test {
Expand Down
6 changes: 1 addition & 5 deletions scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -4614,7 +4614,6 @@ class facebook::react::Scheduler : public facebook::react::UIManagerDelegate {
public virtual void uiManagerDidDispatchCommand(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& commandName, const folly::dynamic& args) override;
public virtual void uiManagerDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) override;
public virtual void uiManagerDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) override;
public virtual void uiManagerDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) override;
public virtual void uiManagerDidSendAccessibilityEvent(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& eventType) override;
public virtual void uiManagerDidSetIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) override;
public virtual void uiManagerDidSetViewSnapshot(facebook::react::Tag sourceTag, facebook::react::Tag targetTag, facebook::react::SurfaceId surfaceId) override;
Expand Down Expand Up @@ -4820,6 +4819,7 @@ enum facebook::react::ShadowNodeTraits::Trait : int32_t {

class facebook::react::ShadowTree {
public ShadowTree(facebook::react::SurfaceId surfaceId, const facebook::react::LayoutConstraints& layoutConstraints, const facebook::react::LayoutContext& layoutContext, const facebook::react::ShadowTreeDelegate& delegate, const facebook::react::ContextContainer& contextContainer);
public bool promoteReactRevision() const;
public facebook::react::CommitMode getCommitMode() const;
public facebook::react::CommitStatus commit(const facebook::react::ShadowTreeCommitTransaction& transaction, const facebook::react::ShadowTree::CommitOptions& commitOptions) const;
public facebook::react::CommitStatus tryCommit(const facebook::react::ShadowTreeCommitTransaction& transaction, const facebook::react::ShadowTree::CommitOptions& commitOptions) const;
Expand All @@ -4835,7 +4835,6 @@ class facebook::react::ShadowTree {
public void commitEmptyTree() const;
public void mergeReactRevision() const;
public void notifyDelegatesOfUpdates() const;
public void promoteReactRevision() const;
public void setCommitMode(facebook::react::CommitMode commitMode) const;
public ~ShadowTree();
}
Expand All @@ -4845,7 +4844,6 @@ class facebook::react::ShadowTreeDelegate {
public virtual void shadowTreeDidCommit(const facebook::react::ShadowTree&, const facebook::react::RootShadowNode::Shared&, const std::vector<const facebook::react::LayoutableShadowNode*>&) const;
public virtual void shadowTreeDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) const = 0;
public virtual void shadowTreeDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) const = 0;
public virtual void shadowTreeDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) const = 0;
public virtual ~ShadowTreeDelegate() noexcept = default;
}

Expand Down Expand Up @@ -5357,7 +5355,6 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
public virtual void shadowTreeDidCommit(const facebook::react::ShadowTree& shadowTree, const facebook::react::RootShadowNode::Shared& rootShadowNode, const std::vector<const facebook::react::LayoutableShadowNode*>& affectedLayoutableNodes) const noexcept override;
public virtual void shadowTreeDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) const override;
public virtual void shadowTreeDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) const override;
public virtual void shadowTreeDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) const override;
public void addEventListener(std::shared_ptr<const facebook::react::EventListener> listener);
public void addOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback);
public void animationTick() const;
Expand Down Expand Up @@ -5438,7 +5435,6 @@ class facebook::react::UIManagerDelegate {
public virtual void uiManagerDidDispatchCommand(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& commandName, const folly::dynamic& args) = 0;
public virtual void uiManagerDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) = 0;
public virtual void uiManagerDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) = 0;
public virtual void uiManagerDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) = 0;
public virtual void uiManagerDidSendAccessibilityEvent(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& eventType) = 0;
public virtual void uiManagerDidSetIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) = 0;
public virtual void uiManagerDidSetViewSnapshot(facebook::react::Tag sourceTag, facebook::react::Tag targetTag, facebook::react::SurfaceId surfaceId) = 0;
Expand Down
6 changes: 1 addition & 5 deletions scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api
Original file line number Diff line number Diff line change
Expand Up @@ -4430,7 +4430,6 @@ class facebook::react::Scheduler : public facebook::react::UIManagerDelegate {
public virtual void uiManagerDidDispatchCommand(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& commandName, const folly::dynamic& args) override;
public virtual void uiManagerDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) override;
public virtual void uiManagerDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) override;
public virtual void uiManagerDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) override;
public virtual void uiManagerDidSendAccessibilityEvent(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& eventType) override;
public virtual void uiManagerDidSetIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) override;
public virtual void uiManagerDidSetViewSnapshot(facebook::react::Tag sourceTag, facebook::react::Tag targetTag, facebook::react::SurfaceId surfaceId) override;
Expand Down Expand Up @@ -4630,6 +4629,7 @@ enum facebook::react::ShadowNodeTraits::Trait : int32_t {

class facebook::react::ShadowTree {
public ShadowTree(facebook::react::SurfaceId surfaceId, const facebook::react::LayoutConstraints& layoutConstraints, const facebook::react::LayoutContext& layoutContext, const facebook::react::ShadowTreeDelegate& delegate, const facebook::react::ContextContainer& contextContainer);
public bool promoteReactRevision() const;
public facebook::react::CommitMode getCommitMode() const;
public facebook::react::CommitStatus commit(const facebook::react::ShadowTreeCommitTransaction& transaction, const facebook::react::ShadowTree::CommitOptions& commitOptions) const;
public facebook::react::CommitStatus tryCommit(const facebook::react::ShadowTreeCommitTransaction& transaction, const facebook::react::ShadowTree::CommitOptions& commitOptions) const;
Expand All @@ -4645,7 +4645,6 @@ class facebook::react::ShadowTree {
public void commitEmptyTree() const;
public void mergeReactRevision() const;
public void notifyDelegatesOfUpdates() const;
public void promoteReactRevision() const;
public void setCommitMode(facebook::react::CommitMode commitMode) const;
public ~ShadowTree();
}
Expand All @@ -4655,7 +4654,6 @@ class facebook::react::ShadowTreeDelegate {
public virtual void shadowTreeDidCommit(const facebook::react::ShadowTree&, const facebook::react::RootShadowNode::Shared&, const std::vector<const facebook::react::LayoutableShadowNode*>&) const;
public virtual void shadowTreeDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) const = 0;
public virtual void shadowTreeDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) const = 0;
public virtual void shadowTreeDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) const = 0;
public virtual ~ShadowTreeDelegate() noexcept = default;
}

Expand Down Expand Up @@ -5167,7 +5165,6 @@ class facebook::react::UIManager : public facebook::react::ShadowTreeDelegate {
public virtual void shadowTreeDidCommit(const facebook::react::ShadowTree& shadowTree, const facebook::react::RootShadowNode::Shared& rootShadowNode, const std::vector<const facebook::react::LayoutableShadowNode*>& affectedLayoutableNodes) const noexcept override;
public virtual void shadowTreeDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) const override;
public virtual void shadowTreeDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) const override;
public virtual void shadowTreeDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) const override;
public void addEventListener(std::shared_ptr<const facebook::react::EventListener> listener);
public void addOnSurfaceStartCallback(facebook::react::UIManagerDelegate::OnSurfaceStartCallback&& callback);
public void animationTick() const;
Expand Down Expand Up @@ -5248,7 +5245,6 @@ class facebook::react::UIManagerDelegate {
public virtual void uiManagerDidDispatchCommand(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& commandName, const folly::dynamic& args) = 0;
public virtual void uiManagerDidFinishReactCommit(const facebook::react::ShadowTree& shadowTree) = 0;
public virtual void uiManagerDidFinishTransaction(std::shared_ptr<const facebook::react::MountingCoordinator> mountingCoordinator, bool mountSynchronously) = 0;
public virtual void uiManagerDidPromoteReactRevision(const facebook::react::ShadowTree& shadowTree) = 0;
public virtual void uiManagerDidSendAccessibilityEvent(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, const std::string& eventType) = 0;
public virtual void uiManagerDidSetIsJSResponder(const std::shared_ptr<const facebook::react::ShadowNode>& shadowNode, bool isJSResponder, bool blockNativeResponder) = 0;
public virtual void uiManagerDidSetViewSnapshot(facebook::react::Tag sourceTag, facebook::react::Tag targetTag, facebook::react::SurfaceId surfaceId) = 0;
Expand Down
Loading
Loading