Remove exported constants from RCTTimers to allow lazy initialization

Summary:
As per javache comments in #8734.

Also removes now useless feature detection check.

**Test plan**
Tested that rIC still works in UIExplorer example.
Closes https://github.com/facebook/react-native/pull/8795

Differential Revision: D3572566

Pulled By: javache

fbshipit-source-id: 261d13d8b03898313f8b4184d634c70f81a61b62
This commit is contained in:
Janic Duplessis
2016-07-15 13:57:19 -07:00
committed by Facebook Github Bot 4
parent f067811cd2
commit 80872ffccd
4 changed files with 10 additions and 23 deletions

View File

@@ -101,11 +101,6 @@ var JSTimers = {
* with time remaining in frame.
*/
requestIdleCallback: function(func) {
if (!RCTTiming.setSendIdleEvents) {
console.warn('requestIdleCallback is not currently supported on this platform');
return requestAnimationFrame(func);
}
if (JSTimersExecution.requestIdleCallbacks.length === 0) {
RCTTiming.setSendIdleEvents(true);
}

View File

@@ -17,6 +17,11 @@ const keyMirror = require('fbjs/lib/keyMirror');
const performanceNow = require('fbjs/lib/performanceNow');
const warning = require('fbjs/lib/warning');
// These timing contants should be kept in sync with the ones in native ios and
// android `RCTTiming` module.
const FRAME_DURATION = 1000 / 60;
const IDLE_CALLBACK_FRAME_DEADLINE = 1;
let hasEmittedTimeDriftWarning = false;
/**
@@ -81,13 +86,12 @@ const JSTimersExecution = {
const currentTime = performanceNow();
callback(currentTime);
} else if (type === JSTimersExecution.Type.requestIdleCallback) {
const { Timing } = require('NativeModules');
callback({
timeRemaining: function() {
// TODO: Optimisation: allow running for longer than one frame if
// there are no pending JS calls on the bridge from native. This
// would require a way to check the bridge queue synchronously.
return Math.max(0, Timing.frameDuration - (performanceNow() - frameTime));
return Math.max(0, FRAME_DURATION - (performanceNow() - frameTime));
},
});
} else {
@@ -134,7 +138,7 @@ const JSTimersExecution = {
callIdleCallbacks: function(frameTime) {
const { Timing } = require('NativeModules');
if (Timing.frameDuration - (performanceNow() - frameTime) < Timing.idleCallbackFrameDeadline) {
if (FRAME_DURATION - (performanceNow() - frameTime) < IDLE_CALLBACK_FRAME_DEADLINE) {
return;
}