Remove bridge access from JavaTimerManager

Summary:
The next step to making our existing timers logic usable outside of the context of the native module. This diff removes the bridge access through ReactContext in JavaTimerManager, and instead relies on a delegate that implements the JSTimers interface. I'm reusing the JSTimers interface for convenience even though it extends JavaScriptModule, which I don't plan on using for bridgeless RN.

Also changing from ReadableArray to ReadableNativeArray so that it can be directly accessed from C++.

Reviewed By: PeteTheHeat

Differential Revision: D17282188

fbshipit-source-id: 5c5e0b12a2250334e96885c220feb52146e57c83
This commit is contained in:
Emily Janzer 2019-09-19 11:31:11 -07:00 коммит произвёл Facebook Github Bot
Родитель 4d774bdc0d
Коммит cc36b89b17
2 изменённых файлов: 33 добавлений и 11 удалений

Просмотреть файл

@ -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,9 +292,7 @@ public class JavaTimerManager {
if (mDevSupportManager.getDevSupportEnabled()) {
long driftTime = Math.abs(remoteTime - deviceTime);
if (driftTime > 60000) {
mReactApplicationContext
.getJSModule(JSTimers.class)
.emitTimeDriftWarning(
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;
}

Просмотреть файл

@ -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