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

Lazy initalize layout aniamtions in the Commit Hook #6586

Merged
Show file tree
Hide file tree
Changes from 3 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
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ namespace reanimated {

ReanimatedCommitHook::ReanimatedCommitHook(
const std::shared_ptr<PropsRegistry> &propsRegistry,
const std::shared_ptr<UIManager> &uiManager)
: propsRegistry_(propsRegistry), uiManager_(uiManager) {
const std::shared_ptr<UIManager> &uiManager,
const std::shared_ptr<LayoutAnimationsProxy> &layoutAnimationsProxy)
: propsRegistry_(propsRegistry),
uiManager_(uiManager),
layoutAnimationsProxy_(layoutAnimationsProxy) {
uiManager_->registerCommitHook(*this);
}

Expand All @@ -28,6 +31,20 @@ 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;
}
}

auto reaShadowNode =
std::reinterpret_pointer_cast<ReanimatedCommitShadowNode>(
newRootShadowNode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#ifdef RCT_NEW_ARCH_ENABLED

#include <reanimated/Fabric/PropsRegistry.h>
#include <reanimated/LayoutAnimations/LayoutAnimationsProxy.h>

#include <react/renderer/uimanager/UIManagerCommitHook.h>

Expand All @@ -15,7 +16,8 @@ class ReanimatedCommitHook : public UIManagerCommitHook {
public:
ReanimatedCommitHook(
const std::shared_ptr<PropsRegistry> &propsRegistry,
const std::shared_ptr<UIManager> &uiManager);
const std::shared_ptr<UIManager> &uiManager,
const std::shared_ptr<LayoutAnimationsProxy> &layoutAnimationsProxy);

~ReanimatedCommitHook() noexcept override;

Expand Down Expand Up @@ -44,6 +46,12 @@ class ReanimatedCommitHook : public UIManagerCommitHook {
std::shared_ptr<PropsRegistry> propsRegistry_;

std::shared_ptr<UIManager> uiManager_;

std::shared_ptr<LayoutAnimationsProxy> layoutAnimationsProxy_;

SurfaceId currentMaxSurfaceId_ = -1;

std::mutex mutex_;
bartlomiejbloniarz marked this conversation as resolved.
Show resolved Hide resolved
};

} // namespace reanimated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -852,15 +852,15 @@ void NativeReanimatedModule::initializeFabric(
const std::shared_ptr<UIManager> &uiManager) {
uiManager_ = uiManager;

initializeLayoutAnimations();
initializeLayoutAnimationsProxy();

mountHook_ =
std::make_shared<ReanimatedMountHook>(propsRegistry_, uiManager_);
commitHook_ =
std::make_shared<ReanimatedCommitHook>(propsRegistry_, uiManager_);
commitHook_ = std::make_shared<ReanimatedCommitHook>(
propsRegistry_, uiManager_, layoutAnimationsProxy_);
}

void NativeReanimatedModule::initializeLayoutAnimations() {
void NativeReanimatedModule::initializeLayoutAnimationsProxy() {
uiManager_->setAnimationDelegate(nullptr);
auto scheduler = reinterpret_cast<Scheduler *>(uiManager_->getDelegate());
auto componentDescriptorRegistry =
Expand All @@ -876,13 +876,9 @@ void NativeReanimatedModule::initializeLayoutAnimations() {
scheduler->getContextContainer(),
uiWorkletRuntime_->getJSIRuntime(),
uiScheduler_);
uiManager_->getShadowTreeRegistry().enumerate(
[this](const ShadowTree &shadowTree, bool &stop) {
shadowTree.getMountingCoordinator()->setMountingOverrideDelegate(
layoutAnimationsProxy_);
});
}
}

#endif // RCT_NEW_ARCH_ENABLED

jsi::Value NativeReanimatedModule::subscribeForKeyboardEvents(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class NativeReanimatedModule : public NativeReanimatedModuleSpec {

void initializeFabric(const std::shared_ptr<UIManager> &uiManager);

void initializeLayoutAnimations();
void initializeLayoutAnimationsProxy();

std::string obtainPropFromShadowNode(
jsi::Runtime &rt,
Expand Down
Loading