[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.
This commit is contained in:
Tadeu Zagallo 2015-06-07 08:42:31 -07:00
parent 8ee9bfe944
commit c2fb21b322
2 changed files with 7 additions and 0 deletions

View File

@ -72,6 +72,7 @@ static NSNumber *RCTGetEventID(id<RCTEvent> 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<RCTEvent> event in eventQueue.allValues) {

View File

@ -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];
}
}
/**