diff --git a/Libraries/NativeAnimation/RCTNativeAnimatedModule.m b/Libraries/NativeAnimation/RCTNativeAnimatedModule.m index 5f7a17303f3..53e67eb7745 100644 --- a/Libraries/NativeAnimation/RCTNativeAnimatedModule.m +++ b/Libraries/NativeAnimation/RCTNativeAnimatedModule.m @@ -20,6 +20,11 @@ typedef void (^AnimatedOperation)(RCTNativeAnimatedNodesManager *nodesManager); RCT_EXPORT_MODULE(); +- (void)invalidate +{ + [_nodesManager stopAnimationLoop]; +} + - (void)dealloc { [self.bridge.eventDispatcher removeDispatchObserver:self]; diff --git a/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h b/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h index 25c4bcb8f26..1330aad49de 100644 --- a/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h +++ b/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.h @@ -60,6 +60,8 @@ - (void)stopAnimation:(nonnull NSNumber *)animationId; +- (void)stopAnimationLoop; + // events - (void)addAnimatedEventToView:(nonnull NSNumber *)viewTag diff --git a/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m b/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m index dc6e8337327..c1dc22fabf5 100644 --- a/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m +++ b/Libraries/NativeAnimation/RCTNativeAnimatedNodesManager.m @@ -321,7 +321,14 @@ - (void)stopAnimationLoopIfNeeded { - if (_displayLink && _activeAnimations.count == 0) { + if (_activeAnimations.count == 0) { + [self stopAnimationLoop]; + } +} + +- (void)stopAnimationLoop +{ + if (_displayLink) { [_displayLink invalidate]; _displayLink = nil; }