From c2fb21b322130433f868086cf7addaed43064313 Mon Sep 17 00:00:00 2001 From: Tadeu Zagallo Date: Sun, 7 Jun 2015 08:42:31 -0700 Subject: [PATCH] [ReactNative] Properly pause frame update observers when idle Summary: @public `RCTDispatchEvent` and `RCTTiming` weren't being paused when there wasn't any work left to be done. Test Plan: Run the timers example - check everything still works as expected Test the ListView paging example - check scroll events are still fired as expected Launch UIExplorer, let it idle, and put a break point on `-[RCTBridge dispatchBlock:moduleID:]`, it should never fire. --- React/Base/RCTEventDispatcher.m | 3 +++ React/Modules/RCTTiming.m | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/React/Base/RCTEventDispatcher.m b/React/Base/RCTEventDispatcher.m index 2009df542..b5b2857f0 100644 --- a/React/Base/RCTEventDispatcher.m +++ b/React/Base/RCTEventDispatcher.m @@ -72,6 +72,7 @@ static NSNumber *RCTGetEventID(id event) } @synthesize bridge = _bridge; +@synthesize paused = _paused; RCT_EXPORT_MODULE() @@ -146,6 +147,7 @@ RCT_IMPORT_METHOD(RCTEventEmitter, receiveEvent); } _eventQueue[eventID] = event; + _paused = NO; [_eventQueueLock unlock]; } @@ -180,6 +182,7 @@ RCT_IMPORT_METHOD(RCTEventEmitter, receiveEvent); [_eventQueueLock lock]; eventQueue = _eventQueue; _eventQueue = [[NSMutableDictionary alloc] init]; + _paused = YES; [_eventQueueLock unlock]; for (id event in eventQueue.allValues) { diff --git a/React/Modules/RCTTiming.m b/React/Modules/RCTTiming.m index e21c9d16f..4f92cfb05 100644 --- a/React/Modules/RCTTiming.m +++ b/React/Modules/RCTTiming.m @@ -155,6 +155,10 @@ RCT_IMPORT_METHOD(RCTJSTimers, callTimers) if ([timersToCall count] > 0) { [_bridge enqueueJSCall:@"RCTJSTimers.callTimers" args:@[timersToCall]]; } + + if (_timers.count == 0) { + [self stopTimers]; + } } /**