Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: make it possible to add multiple mountingOverrideDelegates #44927

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
2 changes: 1 addition & 1 deletion packages/react-native/React/Fabric/RCTScheduler.mm
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ - (const ComponentDescriptor *)findComponentDescriptorByHandle_DO_NOT_USE_THIS_I

- (void)setupAnimationDriver:(const facebook::react::SurfaceHandler &)surfaceHandler
{
surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(_animationDriver);
surfaceHandler.getMountingCoordinator()->addMountingOverrideDelegate(_animationDriver);
}

- (void)onAnimationStarted
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void Binding::startSurface(

surfaceHandler.start();

surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
surfaceHandler.getMountingCoordinator()->addMountingOverrideDelegate(
animationDriver_);

{
Expand Down Expand Up @@ -197,7 +197,7 @@ void Binding::startSurfaceWithConstraints(

surfaceHandler.start();

surfaceHandler.getMountingCoordinator()->setMountingOverrideDelegate(
surfaceHandler.getMountingCoordinator()->addMountingOverrideDelegate(
animationDriver_);

{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,31 +104,34 @@ std::optional<MountingTransaction> MountingCoordinator::pullTransaction()
}

// Override case
auto mountingOverrideDelegate = mountingOverrideDelegate_.lock();
auto shouldOverridePullTransaction = mountingOverrideDelegate &&
mountingOverrideDelegate->shouldOverridePullTransaction();

if (shouldOverridePullTransaction) {
SystraceSection section2("MountingCoordinator::overridePullTransaction");

auto mutations = ShadowViewMutation::List{};
auto telemetry = TransactionTelemetry{};

if (transaction.has_value()) {
mutations = transaction->getMutations();
telemetry = transaction->getTelemetry();
} else {
number_++;
telemetry.willLayout();
telemetry.didLayout();
telemetry.willCommit();
telemetry.didCommit();
telemetry.willDiff();
telemetry.didDiff();
for(const auto &delegate : mountingOverrideDelegates_)
{
auto mountingOverrideDelegate = delegate.lock();
auto shouldOverridePullTransaction = mountingOverrideDelegate &&
mountingOverrideDelegate->shouldOverridePullTransaction();

if (shouldOverridePullTransaction) {
SystraceSection section2("MountingCoordinator::overridePullTransaction");

auto mutations = ShadowViewMutation::List{};
auto telemetry = TransactionTelemetry{};

if (transaction.has_value()) {
mutations = transaction->getMutations();
telemetry = transaction->getTelemetry();
} else {
number_++;
telemetry.willLayout();
telemetry.didLayout();
telemetry.willCommit();
telemetry.didCommit();
telemetry.willDiff();
telemetry.didDiff();
}

transaction = mountingOverrideDelegate->pullTransaction(
surfaceId_, number_, telemetry, std::move(mutations));
}

transaction = mountingOverrideDelegate->pullTransaction(
surfaceId_, number_, telemetry, std::move(mutations));
}

#ifdef RN_SHADOW_TREE_INTROSPECTION
Expand Down Expand Up @@ -200,10 +203,10 @@ ShadowTreeRevision MountingCoordinator::getBaseRevision() const {
return baseRevision_;
}

void MountingCoordinator::setMountingOverrideDelegate(
void MountingCoordinator::addMountingOverrideDelegate(
std::weak_ptr<const MountingOverrideDelegate> delegate) const {
std::scoped_lock lock(mutex_);
mountingOverrideDelegate_ = std::move(delegate);
mountingOverrideDelegates_.insert(mountingOverrideDelegates_.end(), std::move(delegate));
}

} // namespace facebook::react
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class MountingCoordinator final {
void updateBaseRevision(const ShadowTreeRevision& baseRevision) const;
void resetLatestRevision() const;

void setMountingOverrideDelegate(
void addMountingOverrideDelegate(
std::weak_ptr<const MountingOverrideDelegate> delegate) const;

/*
Expand Down Expand Up @@ -119,8 +119,8 @@ class MountingCoordinator final {
mutable std::optional<ShadowTreeRevision> lastRevision_{};
mutable MountingTransaction::Number number_{0};
mutable std::condition_variable signal_;
mutable std::weak_ptr<const MountingOverrideDelegate>
mountingOverrideDelegate_;
mutable std::vector<std::weak_ptr<const MountingOverrideDelegate>>
mountingOverrideDelegates_;

TelemetryController telemetryController_;

Expand Down