Immediate dispatch 0 time timers
Summary: Calling setTimeout(f, 0) will currently schedule f to be called the next frame instead of immediately (which is how it behaves on iOS). This immediately calls back to JS and invokes the function. Reviewed By: astreet, tadeuzagallo Differential Revision: D3006125 fb-gh-sync-id: 9fa109ed82836a718cbb2e8cb21da4943d96f5f6 shipit-source-id: 9fa109ed82836a718cbb2e8cb21da4943d96f5f6
This commit is contained in:
parent
8d52567754
commit
ea882b6f16
|
@ -217,6 +217,14 @@ public final class Timing extends ReactContextBaseJavaModule implements Lifecycl
|
||||||
long adjustedDuration = (long) Math.max(
|
long adjustedDuration = (long) Math.max(
|
||||||
0,
|
0,
|
||||||
jsSchedulingTime - SystemClock.currentTimeMillis() + duration);
|
jsSchedulingTime - SystemClock.currentTimeMillis() + duration);
|
||||||
|
if (duration == 0 && !repeat) {
|
||||||
|
WritableArray timerToCall = Arguments.createArray();
|
||||||
|
timerToCall.pushInt(callbackID);
|
||||||
|
getReactApplicationContext().getJSModule(executorToken, JSTimersExecution.class)
|
||||||
|
.callTimers(timerToCall);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
long initialTargetTime = SystemClock.nanoTime() / 1000000 + adjustedDuration;
|
long initialTargetTime = SystemClock.nanoTime() / 1000000 + adjustedDuration;
|
||||||
Timer timer = new Timer(executorToken, callbackID, initialTargetTime, duration, repeat);
|
Timer timer = new Timer(executorToken, callbackID, initialTargetTime, duration, repeat);
|
||||||
synchronized (mTimerGuard) {
|
synchronized (mTimerGuard) {
|
||||||
|
|
|
@ -110,7 +110,7 @@ public class TimingModuleTest {
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleTimer() {
|
public void testSimpleTimer() {
|
||||||
mTiming.onHostResume();
|
mTiming.onHostResume();
|
||||||
mTiming.createTimer(mExecutorTokenMock, 1, 0, 0, false);
|
mTiming.createTimer(mExecutorTokenMock, 1, 1, 0, false);
|
||||||
stepChoreographerFrame();
|
stepChoreographerFrame();
|
||||||
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(1));
|
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(1));
|
||||||
reset(mJSTimersMock);
|
reset(mJSTimersMock);
|
||||||
|
@ -120,7 +120,7 @@ public class TimingModuleTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testSimpleRecurringTimer() {
|
public void testSimpleRecurringTimer() {
|
||||||
mTiming.createTimer(mExecutorTokenMock, 100, 0, 0, true);
|
mTiming.createTimer(mExecutorTokenMock, 100, 1, 0, true);
|
||||||
mTiming.onHostResume();
|
mTiming.onHostResume();
|
||||||
stepChoreographerFrame();
|
stepChoreographerFrame();
|
||||||
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(100));
|
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(100));
|
||||||
|
@ -133,7 +133,7 @@ public class TimingModuleTest {
|
||||||
@Test
|
@Test
|
||||||
public void testCancelRecurringTimer() {
|
public void testCancelRecurringTimer() {
|
||||||
mTiming.onHostResume();
|
mTiming.onHostResume();
|
||||||
mTiming.createTimer(mExecutorTokenMock, 105, 0, 0, true);
|
mTiming.createTimer(mExecutorTokenMock, 105, 1, 0, true);
|
||||||
|
|
||||||
stepChoreographerFrame();
|
stepChoreographerFrame();
|
||||||
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(105));
|
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(105));
|
||||||
|
@ -147,7 +147,7 @@ public class TimingModuleTest {
|
||||||
@Test
|
@Test
|
||||||
public void testPausingAndResuming() {
|
public void testPausingAndResuming() {
|
||||||
mTiming.onHostResume();
|
mTiming.onHostResume();
|
||||||
mTiming.createTimer(mExecutorTokenMock, 41, 0, 0, true);
|
mTiming.createTimer(mExecutorTokenMock, 41, 1, 0, true);
|
||||||
|
|
||||||
stepChoreographerFrame();
|
stepChoreographerFrame();
|
||||||
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));
|
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));
|
||||||
|
@ -163,6 +163,12 @@ public class TimingModuleTest {
|
||||||
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));
|
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(41));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetTimeoutZero() {
|
||||||
|
mTiming.createTimer(mExecutorTokenMock, 100, 0, 0, false);
|
||||||
|
verify(mJSTimersMock).callTimers(JavaOnlyArray.of(100));
|
||||||
|
}
|
||||||
|
|
||||||
private static class PostFrameCallbackHandler implements Answer<Void> {
|
private static class PostFrameCallbackHandler implements Answer<Void> {
|
||||||
|
|
||||||
private Choreographer.FrameCallback mFrameCallback;
|
private Choreographer.FrameCallback mFrameCallback;
|
||||||
|
|
Loading…
Reference in New Issue