mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-05-17 19:33:12 +08:00
Update native references to JSTimers
Reviewed By: AaaChiuuu Differential Revision: D5294997 fbshipit-source-id: 3003d56f744af0c35b1ffef7bdd71617d4f948c3
This commit is contained in:
committed by
Facebook Github Bot
parent
0ae11f12f3
commit
d795fa1b2c
@@ -112,7 +112,7 @@ ExceptionsManager.installConsoleErrorReporter();
|
||||
// TODO: Move these around to solve the cycle in a cleaner way
|
||||
const BatchedBridge = require('BatchedBridge');
|
||||
BatchedBridge.registerLazyCallableModule('Systrace', () => require('Systrace'));
|
||||
BatchedBridge.registerLazyCallableModule('JSTimersExecution', () => require('JSTimers'));
|
||||
BatchedBridge.registerLazyCallableModule('JSTimers', () => require('JSTimers'));
|
||||
BatchedBridge.registerLazyCallableModule('HeapCapture', () => require('HeapCapture'));
|
||||
BatchedBridge.registerLazyCallableModule('SamplingProfiler', () => require('SamplingProfiler'));
|
||||
BatchedBridge.registerLazyCallableModule('RCTLog', () => require('RCTLog'));
|
||||
|
||||
@@ -837,7 +837,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
||||
{
|
||||
RCTAssertJSThread();
|
||||
[_javaScriptExecutor executeAsyncBlockOnJavaScriptQueue:^{
|
||||
[self _actuallyInvokeAndProcessModule:@"JSTimersExecution"
|
||||
[self _actuallyInvokeAndProcessModule:@"JSTimers"
|
||||
method:@"callTimers"
|
||||
arguments:@[@[timer]]];
|
||||
}];
|
||||
|
||||
@@ -1054,7 +1054,7 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithBundleURL:(__unused NSURL *)bundleUR
|
||||
RCTAssertJSThread();
|
||||
|
||||
if (_reactInstance) {
|
||||
_reactInstance->callJSFunction("JSTimersExecution", "callTimers",
|
||||
_reactInstance->callJSFunction("JSTimers", "callTimers",
|
||||
folly::dynamic::array(folly::dynamic::array([timer doubleValue])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
static const NSTimeInterval kMinimumSleepInterval = 1;
|
||||
|
||||
// These timing contants should be kept in sync with the ones in `JSTimersExecution.js`.
|
||||
// These timing contants should be kept in sync with the ones in `JSTimers.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.
|
||||
@@ -197,7 +197,7 @@ RCT_EXPORT_MODULE()
|
||||
NSArray<NSNumber *> *sortedTimers = [[timersToCall sortedArrayUsingComparator:^(_RCTTimer *a, _RCTTimer *b) {
|
||||
return [a.target compare:b.target];
|
||||
}] valueForKey:@"callbackID"];
|
||||
[_bridge enqueueJSCall:@"JSTimersExecution"
|
||||
[_bridge enqueueJSCall:@"JSTimers"
|
||||
method:@"callTimers"
|
||||
args:@[sortedTimers]
|
||||
completion:NULL];
|
||||
@@ -217,7 +217,7 @@ RCT_EXPORT_MODULE()
|
||||
if (kFrameDuration - frameElapsed >= kIdleCallbackFrameDeadline) {
|
||||
NSTimeInterval currentTimestamp = [[NSDate date] timeIntervalSince1970];
|
||||
NSNumber *absoluteFrameStartMS = @((currentTimestamp - frameElapsed) * 1000);
|
||||
[_bridge enqueueJSCall:@"JSTimersExecution"
|
||||
[_bridge enqueueJSCall:@"JSTimers"
|
||||
method:@"callIdleCallbacks"
|
||||
args:@[absoluteFrameStartMS]
|
||||
completion:NULL];
|
||||
|
||||
@@ -12,7 +12,7 @@ package com.facebook.react.modules.core;
|
||||
import com.facebook.react.bridge.JavaScriptModule;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
|
||||
public interface JSTimersExecution extends JavaScriptModule {
|
||||
public interface JSTimers extends JavaScriptModule {
|
||||
void callTimers(WritableArray timerIDs);
|
||||
void callIdleCallbacks(double frameTime);
|
||||
void emitTimeDriftWarning(String warningMessage);
|
||||
@@ -39,7 +39,7 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl
|
||||
|
||||
protected static final String NAME = "Timing";
|
||||
|
||||
// These timing contants should be kept in sync with the ones in `JSTimersExecution.js`.
|
||||
// These timing contants should be kept in sync with the ones in `JSTimers.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.
|
||||
@@ -99,7 +99,7 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl
|
||||
}
|
||||
|
||||
if (mTimersToCall != null) {
|
||||
getReactApplicationContext().getJSModule(JSTimersExecution.class).callTimers(mTimersToCall);
|
||||
getReactApplicationContext().getJSModule(JSTimers.class).callTimers(mTimersToCall);
|
||||
mTimersToCall = null;
|
||||
}
|
||||
|
||||
@@ -157,7 +157,7 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl
|
||||
}
|
||||
|
||||
if (sendIdleEvents) {
|
||||
getReactApplicationContext().getJSModule(JSTimersExecution.class)
|
||||
getReactApplicationContext().getJSModule(JSTimers.class)
|
||||
.callIdleCallbacks(absoluteFrameStartTime);
|
||||
}
|
||||
|
||||
@@ -337,7 +337,7 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl
|
||||
if (mDevSupportManager.getDevSupportEnabled()) {
|
||||
long driftTime = Math.abs(remoteTime - deviceTime);
|
||||
if (driftTime > 60000) {
|
||||
getReactApplicationContext().getJSModule(JSTimersExecution.class)
|
||||
getReactApplicationContext().getJSModule(JSTimers.class)
|
||||
.emitTimeDriftWarning(
|
||||
"Debugger and device times have drifted by more than 60s. Please correct this by " +
|
||||
"running adb shell \"date `date +%m%d%H%M%Y.%S`\" on your debugger machine.");
|
||||
@@ -349,7 +349,7 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl
|
||||
if (duration == 0 && !repeat) {
|
||||
WritableArray timerToCall = Arguments.createArray();
|
||||
timerToCall.pushInt(callbackID);
|
||||
getReactApplicationContext().getJSModule(JSTimersExecution.class)
|
||||
getReactApplicationContext().getJSModule(JSTimers.class)
|
||||
.callTimers(timerToCall);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ import com.facebook.react.bridge.JavaOnlyArray;
|
||||
import com.facebook.react.devsupport.interfaces.DevSupportManager;
|
||||
import com.facebook.react.common.SystemClock;
|
||||
import com.facebook.react.modules.core.ChoreographerCompat;
|
||||
import com.facebook.react.modules.core.JSTimersExecution;
|
||||
import com.facebook.react.modules.core.JSTimers;
|
||||
import com.facebook.react.modules.core.ReactChoreographer;
|
||||
import com.facebook.react.modules.core.Timing;
|
||||
|
||||
@@ -51,7 +51,7 @@ public class TimingModuleTest {
|
||||
private PostFrameCallbackHandler mPostFrameCallbackHandler;
|
||||
private PostFrameIdleCallbackHandler mIdlePostFrameCallbackHandler;
|
||||
private long mCurrentTimeNs;
|
||||
private JSTimersExecution mJSTimersMock;
|
||||
private JSTimers mJSTimersMock;
|
||||
|
||||
@Rule
|
||||
public PowerMockRule rule = new PowerMockRule();
|
||||
@@ -97,8 +97,8 @@ public class TimingModuleTest {
|
||||
any(ChoreographerCompat.FrameCallback.class));
|
||||
|
||||
mTiming = new Timing(reactContext, mock(DevSupportManager.class));
|
||||
mJSTimersMock = mock(JSTimersExecution.class);
|
||||
when(reactContext.getJSModule(JSTimersExecution.class)).thenReturn(mJSTimersMock);
|
||||
mJSTimersMock = mock(JSTimers.class);
|
||||
when(reactContext.getJSModule(JSTimers.class)).thenReturn(mJSTimersMock);
|
||||
|
||||
doAnswer(new Answer() {
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user