[ReactNative] Use a single DisplayLink held by the bridge

This commit is contained in:
Tadeu Zagallo
2015-04-15 07:07:19 -07:00
parent 4f8b2825a0
commit 75e4e124fa
9 changed files with 176 additions and 59 deletions

View File

@@ -58,7 +58,6 @@
@implementation RCTTiming
{
RCTSparseArray *_timers;
id _updateTimer;
}
@synthesize bridge = _bridge;
@@ -113,32 +112,21 @@ RCT_IMPORT_METHOD(RCTJSTimers, callTimers)
- (void)stopTimers
{
[_updateTimer invalidate];
_updateTimer = nil;
[_bridge removeFrameUpdateObserver:self];
}
- (void)startTimers
{
RCTAssertMainThread();
if (![self isValid] || _updateTimer != nil || _timers.count == 0) {
if (![self isValid] || _timers.count == 0) {
return;
}
_updateTimer = [CADisplayLink displayLinkWithTarget:self selector:@selector(update)];
if (_updateTimer) {
[_updateTimer addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
} else {
RCTLogWarn(@"Failed to create a display link (probably on buildbot) - using an NSTimer for AppEngine instead.");
_updateTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 60)
target:self
selector:@selector(update)
userInfo:nil
repeats:YES];
}
[_bridge addFrameUpdateObserver:self];
}
- (void)update
- (void)didUpdateFrame:(RCTFrameUpdate *)update
{
RCTAssertMainThread();