diff --git a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js index e751711a9..75b1e23be 100644 --- a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js +++ b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimers.js @@ -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); } diff --git a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js index cbb9bf804..146018771 100644 --- a/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js +++ b/Libraries/JavaScriptAppEngine/System/JSTimers/JSTimersExecution.js @@ -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; } diff --git a/React/Modules/RCTTiming.m b/React/Modules/RCTTiming.m index 6e5cea8d0..2ae7df17d 100644 --- a/React/Modules/RCTTiming.m +++ b/React/Modules/RCTTiming.m @@ -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]; diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java index 508141f12..e95bf245e 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/Timing.java @@ -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 getConstants() { - return MapBuilder.of( - "frameDuration", FRAME_DURATION_MS, - "idleCallbackFrameDeadline", IDLE_CALLBACK_FRAME_DEADLINE_MS); - } - @Override public void onExecutorDestroyed(ExecutorToken executorToken) { synchronized (mTimerGuard) {