@@ -309,6 +309,15 @@ - (NSString *)moduleConfig
309309 config[moduleData.name] = moduleData.config ;
310310 if ([moduleData.instance conformsToProtocol: @protocol (RCTFrameUpdateObserver)]) {
311311 [_frameUpdateObservers addObject: moduleData];
312+
313+ id <RCTFrameUpdateObserver> observer = (id <RCTFrameUpdateObserver>)moduleData.instance ;
314+ __weak typeof (self) weakSelf = self;
315+ __weak typeof (_javaScriptExecutor) weakJavaScriptExecutor = _javaScriptExecutor;
316+ observer.pauseCallback = ^{
317+ [weakJavaScriptExecutor executeBlockOnJavaScriptQueue: ^{
318+ [weakSelf updateJSDisplayLinkState ];
319+ }];
320+ };
312321 }
313322 }
314323
@@ -317,6 +326,23 @@ - (NSString *)moduleConfig
317326 }, NULL );
318327}
319328
329+ - (void )updateJSDisplayLinkState
330+ {
331+ RCTAssertJSThread ();
332+
333+ BOOL pauseDisplayLink = ![_scheduledCallbacks count ] && ![_scheduledCalls count ];
334+ if (pauseDisplayLink) {
335+ for (RCTModuleData *moduleData in _frameUpdateObservers) {
336+ id <RCTFrameUpdateObserver> observer = (id <RCTFrameUpdateObserver>)moduleData.instance ;
337+ if (!observer.paused ) {
338+ pauseDisplayLink = NO ;
339+ break ;
340+ }
341+ }
342+ }
343+ _jsDisplayLink.paused = pauseDisplayLink;
344+ }
345+
320346- (void )injectJSONConfiguration : (NSString *)configJSON
321347 onComplete : (void (^)(NSError *))onComplete
322348{
@@ -620,6 +646,7 @@ - (void)_invokeAndProcessModule:(NSString *)module method:(NSString *)method arg
620646 } else {
621647 [strongSelf->_scheduledCalls addObject: call];
622648 }
649+ [strongSelf updateJSDisplayLinkState ];
623650
624651 RCTProfileEndEvent (0 , @" objc_call" , call);
625652 }];
@@ -804,7 +831,7 @@ - (void)_jsThreadUpdate:(CADisplayLink *)displayLink
804831 RCTFrameUpdate *frameUpdate = [[RCTFrameUpdate alloc ] initWithDisplayLink: displayLink];
805832 for (RCTModuleData *moduleData in _frameUpdateObservers) {
806833 id <RCTFrameUpdateObserver> observer = (id <RCTFrameUpdateObserver>)moduleData.instance ;
807- if (![observer respondsToSelector: @selector ( isPaused )] || ! observer.paused ) {
834+ if (!observer.paused ) {
808835 RCT_IF_DEV (NSString *name = [NSString stringWithFormat: @" [%@ didUpdateFrame:%f ]" , observer, displayLink.timestamp];)
809836 RCTProfileBeginFlowEvent ();
810837
@@ -833,6 +860,7 @@ - (void)_jsThreadUpdate:(CADisplayLink *)displayLink
833860 [self _actuallyInvokeAndProcessModule: @" BatchedBridge"
834861 method: @" processBatch"
835862 arguments: @[[calls valueForKey: @" js_args" ]]];
863+ [self updateJSDisplayLinkState ];
836864 }
837865
838866 RCTProfileEndEvent (0 , @" objc_call" , nil );
0 commit comments