Files
react-native/ReactCommon/react/renderer/animations/LayoutAnimationCallbackWrapper.h
T
Samuel Susla d83c310144 Simplify Layout Animation callback handling
Summary:
changelog: [internal]

There was extra bookkeeping associated with lifetime of `LayoutAnimationCallbackWrapper`. We can just copy it into runtimeExecutor lambda to manage its life cycle and delete `jsi::Function` once it was called.

Reviewed By: RSNara

Differential Revision: D30728210

fbshipit-source-id: 6fc60ee83846cb73648f1c09e5aaf1ed04bd0817
2021-09-08 11:53:16 -07:00

35 lines
768 B
C++

/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <jsi/jsi.h>
#include <memory>
namespace facebook {
namespace react {
class LayoutAnimationCallbackWrapper {
public:
LayoutAnimationCallbackWrapper(jsi::Function &&callback)
: callback_(std::make_shared<jsi::Function>(std::move(callback))) {}
LayoutAnimationCallbackWrapper() : callback_(nullptr) {}
void call(jsi::Runtime &runtime) const {
if (callback_) {
callback_->call(runtime);
callback_.reset();
}
}
private:
mutable std::shared_ptr<jsi::Function> callback_;
};
} // namespace react
} // namespace facebook