Skip to content

Commit

Permalink
Fix MountingOverrideDelegate initialization (#6841)
Browse files Browse the repository at this point in the history
## Summary

Currently we use the `setMountingOverrideDelegate` function to pass
`LayoutAnimationProxy` to every surface, when we find out that a new
surface was created. However, the `setMountingOverrideDelegate` function
actually doesn't override the `MountingOverrideDelegate` - it stores all
of them. This would lead to us processing the same transaction multiple
times, so now we skip each already configured surface.
## Test plan
  • Loading branch information
bartlomiejbloniarz authored Dec 20, 2024
1 parent b7077c7 commit 76ead7c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,31 @@ ReanimatedCommitHook::~ReanimatedCommitHook() noexcept {
uiManager_->unregisterCommitHook(*this);
}

void ReanimatedCommitHook::maybeInitializeLayoutAnimations(
SurfaceId surfaceId) {
auto lock = std::unique_lock<std::mutex>(mutex_);
if (surfaceId > currentMaxSurfaceId_) {
// when a new surfaceId is observed we call setMountingOverrideDelegate
// for all yet unseen surfaces
uiManager_->getShadowTreeRegistry().enumerate(
[this](const ShadowTree &shadowTree, bool &stop) {
if (shadowTree.getSurfaceId() <= currentMaxSurfaceId_) {
// the set function actually adds our delegate to a list, so we
// shouldn't invoke it twice for the same surface
return;
}
shadowTree.getMountingCoordinator()->setMountingOverrideDelegate(
layoutAnimationsProxy_);
});
currentMaxSurfaceId_ = surfaceId;
}
}

RootShadowNode::Unshared ReanimatedCommitHook::shadowTreeWillCommit(
ShadowTree const &,
RootShadowNode::Shared const &,
RootShadowNode::Unshared const &newRootShadowNode) noexcept {
auto surfaceId = newRootShadowNode->getSurfaceId();

{
auto lock = std::unique_lock<std::mutex>(mutex_);
if (surfaceId > currentMaxSurfaceId_) {
uiManager_->getShadowTreeRegistry().enumerate(
[this](const ShadowTree &shadowTree, bool &stop) {
shadowTree.getMountingCoordinator()->setMountingOverrideDelegate(
layoutAnimationsProxy_);
});
currentMaxSurfaceId_ = surfaceId;
}
}
maybeInitializeLayoutAnimations(newRootShadowNode->getSurfaceId());

auto reaShadowNode =
std::reinterpret_pointer_cast<ReanimatedCommitShadowNode>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class ReanimatedCommitHook : public UIManagerCommitHook {

void commitHookWasUnregistered(UIManager const &) noexcept override {}

void maybeInitializeLayoutAnimations(SurfaceId surfaceId);

RootShadowNode::Unshared shadowTreeWillCommit(
ShadowTree const &shadowTree,
RootShadowNode::Shared const &oldRootShadowNode,
Expand Down

0 comments on commit 76ead7c

Please sign in to comment.