Update the timestamp we send in touch events to be the more accurate timestamp we use

Summary: Use the more accurate timestamp that we have computed for the touch event rather than the event timestamp that Android provides.

Reviewed By: andreicoman11

Differential Revision: D3292705

fbshipit-source-id: dad082ab74406d391481d16cdac19629751aa1eb
This commit is contained in:
Dave Miller 2016-05-12 09:39:39 -07:00 committed by Facebook Github Bot 0
parent 2525feb37f
commit f2c1868b56
2 changed files with 12 additions and 3 deletions

View File

@ -62,7 +62,7 @@ import com.facebook.react.uimanager.PixelUtil;
touch.putDouble(LOCATION_X_KEY, PixelUtil.toDIPFromPixel(locationX));
touch.putDouble(LOCATION_Y_KEY, PixelUtil.toDIPFromPixel(locationY));
touch.putInt(TARGET_KEY, reactTarget);
touch.putDouble(TIMESTAMP_KEY, motionEvent.getEventTime());
touch.putDouble(TIMESTAMP_KEY, event.getTimestampMs());
touch.putDouble(POINTER_IDENTIFIER_KEY, motionEvent.getPointerId(index));
touches.pushMap(touch);
}

View File

@ -22,6 +22,7 @@ import com.facebook.react.bridge.ReactTestHelper;
import com.facebook.react.bridge.JavaOnlyArray;
import com.facebook.react.bridge.JavaOnlyMap;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.common.SystemClock;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.DisplayMetricsHolder;
import com.facebook.react.uimanager.events.Event;
@ -51,7 +52,7 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
@PrepareForTest(Arguments.class)
@PrepareForTest({Arguments.class, SystemClock.class})
@RunWith(RobolectricTestRunner.class)
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
public class RootViewTest {
@ -64,6 +65,7 @@ public class RootViewTest {
@Before
public void setUp() {
final long ts = SystemClock.nanoTime();
PowerMockito.mockStatic(Arguments.class);
PowerMockito.when(Arguments.createArray()).thenAnswer(new Answer<Object>() {
@Override
@ -77,6 +79,13 @@ public class RootViewTest {
return new JavaOnlyMap();
}
});
PowerMockito.mockStatic(SystemClock.class);
PowerMockito.when(SystemClock.nanoTime()).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return ts;
}
});
mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
mReactContext = new ReactApplicationContext(RuntimeEnvironment.application);
@ -107,7 +116,7 @@ public class RootViewTest {
rootView.startReactApplication(instanceManager, "");
rootView.simulateAttachForTesting();
long ts = new Date().getTime();
long ts = SystemClock.nanoTime();
// Test ACTION_DOWN event
rootView.onTouchEvent(