Skip to content

Commit f2c1868

Browse files
Dave MillerFacebook Github Bot 0
authored andcommitted
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
1 parent 2525feb commit f2c1868

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

ReactAndroid/src/main/java/com/facebook/react/uimanager/events/TouchesHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private static WritableArray createsPointersArray(int reactTarget, TouchEvent ev
6262
touch.putDouble(LOCATION_X_KEY, PixelUtil.toDIPFromPixel(locationX));
6363
touch.putDouble(LOCATION_Y_KEY, PixelUtil.toDIPFromPixel(locationY));
6464
touch.putInt(TARGET_KEY, reactTarget);
65-
touch.putDouble(TIMESTAMP_KEY, motionEvent.getEventTime());
65+
touch.putDouble(TIMESTAMP_KEY, event.getTimestampMs());
6666
touch.putDouble(POINTER_IDENTIFIER_KEY, motionEvent.getPointerId(index));
6767
touches.pushMap(touch);
6868
}

ReactAndroid/src/test/java/com/facebook/react/RootViewTest.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import com.facebook.react.bridge.JavaOnlyArray;
2323
import com.facebook.react.bridge.JavaOnlyMap;
2424
import com.facebook.react.bridge.WritableArray;
25+
import com.facebook.react.common.SystemClock;
2526
import com.facebook.react.uimanager.UIManagerModule;
2627
import com.facebook.react.uimanager.DisplayMetricsHolder;
2728
import com.facebook.react.uimanager.events.Event;
@@ -51,7 +52,7 @@
5152
import static org.mockito.Mockito.verifyNoMoreInteractions;
5253
import static org.mockito.Mockito.when;
5354

54-
@PrepareForTest(Arguments.class)
55+
@PrepareForTest({Arguments.class, SystemClock.class})
5556
@RunWith(RobolectricTestRunner.class)
5657
@PowerMockIgnore({"org.mockito.*", "org.robolectric.*", "android.*"})
5758
public class RootViewTest {
@@ -64,6 +65,7 @@ public class RootViewTest {
6465

6566
@Before
6667
public void setUp() {
68+
final long ts = SystemClock.nanoTime();
6769
PowerMockito.mockStatic(Arguments.class);
6870
PowerMockito.when(Arguments.createArray()).thenAnswer(new Answer<Object>() {
6971
@Override
@@ -77,6 +79,13 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
7779
return new JavaOnlyMap();
7880
}
7981
});
82+
PowerMockito.mockStatic(SystemClock.class);
83+
PowerMockito.when(SystemClock.nanoTime()).thenAnswer(new Answer<Object>() {
84+
@Override
85+
public Object answer(InvocationOnMock invocation) throws Throwable {
86+
return ts;
87+
}
88+
});
8089

8190
mCatalystInstanceMock = ReactTestHelper.createMockCatalystInstance();
8291
mReactContext = new ReactApplicationContext(RuntimeEnvironment.application);
@@ -107,7 +116,7 @@ public void testTouchEmitter() {
107116
rootView.startReactApplication(instanceManager, "");
108117
rootView.simulateAttachForTesting();
109118

110-
long ts = new Date().getTime();
119+
long ts = SystemClock.nanoTime();
111120

112121
// Test ACTION_DOWN event
113122
rootView.onTouchEvent(

0 commit comments

Comments
 (0)