From 488faaaddb265a2a52faad3721130236e413ef37 Mon Sep 17 00:00:00 2001 From: Riccardo Cipolleschi Date: Tue, 30 Jul 2024 13:06:15 -0700 Subject: [PATCH] Back out "Remove `_shouldEmitEvent` guardrails" Summary: Backout of this [commit]() as the previous one was making some E2E fail and need to investigate further. ## Changelog: [Internal] - Add back `_shouldEmitEvent` guardrails Reviewed By: mdvacca, arushikesarwani94 Differential Revision: D60467145 fbshipit-source-id: a703022aa74ca0ed0fed05b59da68918eb2001e1 --- .../RCTNativeAnimatedTurboModule.mm | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/packages/react-native/Libraries/NativeAnimation/RCTNativeAnimatedTurboModule.mm b/packages/react-native/Libraries/NativeAnimation/RCTNativeAnimatedTurboModule.mm index a3f8d1583cf..4d16e500925 100644 --- a/packages/react-native/Libraries/NativeAnimation/RCTNativeAnimatedTurboModule.mm +++ b/packages/react-native/Libraries/NativeAnimation/RCTNativeAnimatedTurboModule.mm @@ -27,6 +27,9 @@ typedef void (^AnimatedOperation)(RCTNativeAnimatedNodesManager *nodesManager); NSMutableArray *_preOperations; NSSet *_userDrivenAnimationEndedEvents; + + // TODO: Remove this when https://github.com/facebook/react-native/pull/45457 lands + BOOL _shouldEmitEvent; } RCT_EXPORT_MODULE(); @@ -42,6 +45,7 @@ RCT_EXPORT_MODULE(); _operations = [NSMutableArray new]; _preOperations = [NSMutableArray new]; _userDrivenAnimationEndedEvents = [NSSet setWithArray:@[ @"onScrollEnded" ]]; + _shouldEmitEvent = NO; } return self; } @@ -375,8 +379,27 @@ RCT_EXPORT_METHOD(queueAndExecuteBatchedOperations : (NSArray *)operationsAndArg [self sendEventWithName:@"onAnimatedValueUpdate" body:@{@"tag" : node.nodeTag, @"value" : @(value)}]; } +// TODO: Remove this when https://github.com/facebook/react-native/pull/45457 lands +- (void)startObserving +{ + [super startObserving]; + _shouldEmitEvent = YES; +} + +- (void)stopObserving +{ + [super stopObserving]; + _shouldEmitEvent = NO; +} + +// ---- + - (void)userDrivenAnimationEnded:(NSArray *)nodes { + if (!_shouldEmitEvent) { + return; + } + [self sendEventWithName:@"onUserDrivenAnimationEnded" body:@{@"tags" : nodes}]; }