diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java index 10fa6a6054..a3e8d462ea 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/JavaTimerManager.java @@ -73,7 +73,7 @@ public class JavaTimerManager { } if (mTimersToCall != null) { - mReactApplicationContext.getJSModule(JSTimers.class).callTimers(mTimersToCall); + mJSTimers.callTimers(mTimersToCall); mTimersToCall = null; } @@ -131,9 +131,7 @@ public class JavaTimerManager { } if (sendIdleEvents) { - mReactApplicationContext - .getJSModule(JSTimers.class) - .callIdleCallbacks(absoluteFrameStartTime); + mJSTimers.callIdleCallbacks(absoluteFrameStartTime); } mCurrentIdleCallbackRunnable = null; @@ -145,6 +143,7 @@ public class JavaTimerManager { } private final ReactApplicationContext mReactApplicationContext; + private final JSTimers mJSTimers; private final ReactChoreographer mReactChoreographer; private final DevSupportManager mDevSupportManager; private final Object mTimerGuard = new Object(); @@ -162,9 +161,11 @@ public class JavaTimerManager { public JavaTimerManager( ReactApplicationContext reactContext, + JSTimers jsTimers, ReactChoreographer reactChoreographer, DevSupportManager devSupportManager) { mReactApplicationContext = reactContext; + mJSTimers = jsTimers; mReactChoreographer = reactChoreographer; mDevSupportManager = devSupportManager; @@ -291,11 +292,9 @@ public class JavaTimerManager { if (mDevSupportManager.getDevSupportEnabled()) { long driftTime = Math.abs(remoteTime - deviceTime); if (driftTime > 60000) { - mReactApplicationContext - .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."); + mJSTimers.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."); } } @@ -304,7 +303,7 @@ public class JavaTimerManager { if (duration == 0 && !repeat) { WritableArray timerToCall = Arguments.createArray(); timerToCall.pushInt(callbackID); - mReactApplicationContext.getJSModule(JSTimers.class).callTimers(timerToCall); + mJSTimers.callTimers(timerToCall); return; } diff --git a/ReactAndroid/src/main/java/com/facebook/react/modules/core/TimingModule.java b/ReactAndroid/src/main/java/com/facebook/react/modules/core/TimingModule.java index 2712c49562..03fd1f29d9 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/modules/core/TimingModule.java +++ b/ReactAndroid/src/main/java/com/facebook/react/modules/core/TimingModule.java @@ -10,6 +10,7 @@ import com.facebook.react.bridge.LifecycleEventListener; import com.facebook.react.bridge.ReactApplicationContext; import com.facebook.react.bridge.ReactContextBaseJavaModule; import com.facebook.react.bridge.ReactMethod; +import com.facebook.react.bridge.WritableArray; import com.facebook.react.devsupport.interfaces.DevSupportManager; import com.facebook.react.jstasks.HeadlessJsTaskContext; import com.facebook.react.jstasks.HeadlessJsTaskEventListener; @@ -26,8 +27,30 @@ public final class TimingModule extends ReactContextBaseJavaModule public TimingModule(ReactApplicationContext reactContext, DevSupportManager devSupportManager) { super(reactContext); + + JSTimers jsTimersProxy = + new JSTimers() { + @Override + public void callTimers(WritableArray timerIDs) { + getReactApplicationContext().getJSModule(JSTimers.class).callTimers(timerIDs); + } + + @Override + public void callIdleCallbacks(double frameTime) { + getReactApplicationContext().getJSModule(JSTimers.class).callIdleCallbacks(frameTime); + } + + @Override + public void emitTimeDriftWarning(String warningMessage) { + getReactApplicationContext() + .getJSModule(JSTimers.class) + .emitTimeDriftWarning(warningMessage); + } + }; + mJavaTimerManager = - new JavaTimerManager(reactContext, ReactChoreographer.getInstance(), devSupportManager); + new JavaTimerManager( + reactContext, jsTimersProxy, ReactChoreographer.getInstance(), devSupportManager); } @Override