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;
}

View File

@ -16,6 +16,8 @@
#import "RCTUtils.h"
static const NSTimeInterval kMinimumSleepInterval = 1;
// These timing contants should be kept in sync with the ones in `JSTimersExecution.js`.
// The duration of a frame. This assumes that we want to run at 60 fps.
static const NSTimeInterval kFrameDuration = 1.0 / 60.0;
// The minimum time left in a frame to trigger the idle callback.
@ -138,14 +140,6 @@ RCT_EXPORT_MODULE()
return RCTJSThread;
}
- (NSDictionary *)constantsToExport
{
return @{
@"frameDuration": @(kFrameDuration * 1000),
@"idleCallbackFrameDeadline": @(kIdleCallbackFrameDeadline * 1000),
};
}
- (void)invalidate
{
[self stopTimers];

View File

@ -45,6 +45,7 @@ import javax.annotation.Nullable;
public final class Timing extends ReactContextBaseJavaModule implements LifecycleEventListener,
OnExecutorUnregisteredListener {
// These timing contants should be kept in sync with the ones in `JSTimersExecution.js`.
// The minimum time in milliseconds left in the frame to call idle callbacks.
private static final float IDLE_CALLBACK_FRAME_DEADLINE_MS = 1.f;
// The total duration of a frame in milliseconds, this assumes that devices run at 60 fps.
@ -309,13 +310,6 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl
return true;
}
@Override
public Map<String, Object> getConstants() {
return MapBuilder.<String, Object>of(
"frameDuration", FRAME_DURATION_MS,
"idleCallbackFrameDeadline", IDLE_CALLBACK_FRAME_DEADLINE_MS);
}
@Override
public void onExecutorDestroyed(ExecutorToken executorToken) {
synchronized (mTimerGuard) {