remove enable_shared_from_this from NativeAnimatedNodesManager (#51589)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/51589

changelog: [internal]

With D75140890, there is a guarantee that `startOnRenderCallback_` won't be called after the owning class is destroyed.

There shouldn't be any events flowing through Fabric when the RN instance is torn down. Passing this to eventEmitterListener_ should be safe.

This helps with C++ binary size a little bit.

Reviewed By: rshest

Differential Revision: D75148616

fbshipit-source-id: 5110736c2ddcff738fce395bd0b9844d44e8dcb2
This commit is contained in:
Samuel Susla
2025-05-25 04:20:59 -07:00
committed by Facebook GitHub Bot
parent 44ebf31f3b
commit bf974e8de1
2 changed files with 4 additions and 11 deletions
@@ -427,13 +427,11 @@ std::shared_ptr<EventEmitterListener>
NativeAnimatedNodesManager::ensureEventEmitterListener() noexcept {
if (!eventEmitterListener_) {
eventEmitterListener_ = std::make_shared<EventEmitterListener>(
[weakSelf = weak_from_this()](
[this](
Tag tag,
const std::string& eventName,
const EventPayload& payload) -> bool {
if (auto self = weakSelf.lock()) {
self->handleAnimatedEvent(tag, eventName, payload);
}
handleAnimatedEvent(tag, eventName, payload);
return false;
});
}
@@ -442,11 +440,7 @@ NativeAnimatedNodesManager::ensureEventEmitterListener() noexcept {
void NativeAnimatedNodesManager::startRenderCallbackIfNeeded() {
if (startOnRenderCallback_) {
startOnRenderCallback_([weakSelf = weak_from_this()]() {
if (auto self = weakSelf.lock()) {
self->onRender();
}
});
startOnRenderCallback_([this]() { onRender(); });
if (isOnRenderThread_) {
// Calling startOnRenderCallback_ will register a UI tick listener.
@@ -41,8 +41,7 @@ template <>
struct Bridging<EndResult>
: NativeAnimatedTurboModuleEndResultBridging<EndResult> {};
class NativeAnimatedNodesManager
: public std::enable_shared_from_this<NativeAnimatedNodesManager> {
class NativeAnimatedNodesManager {
public:
using DirectManipulationCallback =
std::function<void(Tag, const folly::dynamic&)>;