Skip to content

Fix timestamps on android touch events to use milliseconds, to be consistent with iOS #8199

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void testMetionsInputColors() throws Throwable {
eventDispatcher.dispatchEvent(
new ReactTextChangedEvent(
reactEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
newText.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
Expand All @@ -125,7 +125,7 @@ public void testMetionsInputColors() throws Throwable {
eventDispatcher.dispatchEvent(
new ReactTextInputEvent(
reactEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
newText.toString(),
"",
start,
Expand All @@ -150,7 +150,7 @@ public void testMetionsInputColors() throws Throwable {
eventDispatcher.dispatchEvent(
new ReactTextChangedEvent(
reactEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
newText.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
Expand All @@ -159,7 +159,7 @@ public void testMetionsInputColors() throws Throwable {
eventDispatcher.dispatchEvent(
new ReactTextInputEvent(
reactEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
moreText,
"",
start,
Expand All @@ -184,7 +184,7 @@ public void testMetionsInputColors() throws Throwable {
eventDispatcher.dispatchEvent(
new ReactTextChangedEvent(
reactEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
newText.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
Expand All @@ -193,7 +193,7 @@ public void testMetionsInputColors() throws Throwable {
eventDispatcher.dispatchEvent(
new ReactTextInputEvent(
reactEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
moreText,
"",
start,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ public static long currentTimeMillis() {
public static long nanoTime() {
return System.nanoTime();
}

public static long elapsedRealtime() {
return android.os.SystemClock.elapsedRealtime();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ public void createTimer(
return;
}

long initialTargetTime = SystemClock.nanoTime() / 1000000 + adjustedDuration;
long initialTargetTime = SystemClock.elapsedRealtime() + adjustedDuration;
Timer timer = new Timer(executorToken, callbackID, initialTargetTime, duration, repeat);
synchronized (mTimerGuard) {
mTimers.add(timer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
TouchEventType.START,
ev,
mTargetCoordinates[0],
Expand All @@ -105,7 +105,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
TouchEventType.END,
ev,
mTargetCoordinates[0],
Expand All @@ -117,7 +117,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
TouchEventType.MOVE,
ev,
mTargetCoordinates[0],
Expand All @@ -128,7 +128,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
TouchEventType.START,
ev,
mTargetCoordinates[0],
Expand All @@ -139,7 +139,7 @@ public void handleTouchEvent(MotionEvent ev, EventDispatcher eventDispatcher) {
eventDispatcher.dispatchEvent(
TouchEvent.obtain(
mTargetTag,
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
TouchEventType.END,
ev,
mTargetCoordinates[0],
Expand Down Expand Up @@ -180,7 +180,7 @@ private void dispatchCancelEvent(MotionEvent androidEvent, EventDispatcher event
Assertions.assertNotNull(eventDispatcher).dispatchEvent(
TouchEvent.obtain(
mTargetTag,
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
TouchEventType.CANCEL,
androidEvent,
mTargetCoordinates[0],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private OnLayoutEvent() {
}

protected void init(int viewTag, int x, int y, int width, int height) {
super.init(viewTag, SystemClock.nanoTime());
super.init(viewTag, SystemClock.elapsedRealtime());
mX = x;
mY = y;
mWidth = width;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,25 +188,25 @@ public DrawerEventEmitter(DrawerLayout drawerLayout, EventDispatcher eventDispat
@Override
public void onDrawerSlide(View view, float v) {
mEventDispatcher.dispatchEvent(
new DrawerSlideEvent(mDrawerLayout.getId(), SystemClock.nanoTime(), v));
new DrawerSlideEvent(mDrawerLayout.getId(), SystemClock.elapsedRealtime(), v));
}

@Override
public void onDrawerOpened(View view) {
mEventDispatcher.dispatchEvent(
new DrawerOpenedEvent(mDrawerLayout.getId(), SystemClock.nanoTime()));
new DrawerOpenedEvent(mDrawerLayout.getId(), SystemClock.elapsedRealtime()));
}

@Override
public void onDrawerClosed(View view) {
mEventDispatcher.dispatchEvent(
new DrawerClosedEvent(mDrawerLayout.getId(), SystemClock.nanoTime()));
new DrawerClosedEvent(mDrawerLayout.getId(), SystemClock.elapsedRealtime()));
}

@Override
public void onDrawerStateChanged(int i) {
mEventDispatcher.dispatchEvent(
new DrawerStateChangedEvent(mDrawerLayout.getId(), SystemClock.nanoTime(), i));
new DrawerStateChangedEvent(mDrawerLayout.getId(), SystemClock.elapsedRealtime(), i));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public void setShouldNotifyLoadEvents(boolean shouldNotify) {
@Override
public void onSubmit(String id, Object callerContext) {
mEventDispatcher.dispatchEvent(
new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD_START));
new ImageLoadEvent(getId(), SystemClock.elapsedRealtime(), ImageLoadEvent.ON_LOAD_START));
}

@Override
Expand All @@ -202,18 +202,18 @@ public void onFinalImageSet(
@Nullable Animatable animatable) {
if (imageInfo != null) {
mEventDispatcher.dispatchEvent(
new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD));
new ImageLoadEvent(getId(), SystemClock.elapsedRealtime(), ImageLoadEvent.ON_LOAD));
mEventDispatcher.dispatchEvent(
new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD_END));
new ImageLoadEvent(getId(), SystemClock.elapsedRealtime(), ImageLoadEvent.ON_LOAD_END));
}
}

@Override
public void onFailure(String id, Throwable throwable) {
mEventDispatcher.dispatchEvent(
new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_ERROR));
new ImageLoadEvent(getId(), SystemClock.elapsedRealtime(), ImageLoadEvent.ON_ERROR));
mEventDispatcher.dispatchEvent(
new ImageLoadEvent(getId(), SystemClock.nanoTime(), ImageLoadEvent.ON_LOAD_END));
new ImageLoadEvent(getId(), SystemClock.elapsedRealtime(), ImageLoadEvent.ON_LOAD_END));
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,14 @@ protected void addEventEmitters(
new ReactModalHostView.OnRequestCloseListener() {
@Override
public void onRequestClose(DialogInterface dialog) {
dispatcher.dispatchEvent(new RequestCloseEvent(view.getId(), SystemClock.nanoTime()));
dispatcher.dispatchEvent(new RequestCloseEvent(view.getId(), SystemClock.elapsedRealtime()));
}
});
view.setOnShowListener(
new DialogInterface.OnShowListener() {
@Override
public void onShow(DialogInterface dialog) {
dispatcher.dispatchEvent(new ShowEvent(view.getId(), SystemClock.nanoTime()));
dispatcher.dispatchEvent(new ShowEvent(view.getId(), SystemClock.elapsedRealtime()));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public PickerEventEmitter(ReactPicker reactPicker, EventDispatcher eventDispatch
@Override
public void onItemSelected(int position) {
mEventDispatcher.dispatchEvent( new PickerItemSelectEvent(
mReactPicker.getId(), SystemClock.nanoTime(), position));
mReactPicker.getId(), SystemClock.elapsedRealtime(), position));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ protected void onScrollChanged(int l, int t, int oldl, int oldt) {
((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(ScrollEvent.obtain(
getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
ScrollEventType.SCROLL,
0, /* offsetX = 0, horizontal scrolling only */
calculateAbsoluteOffset(),
Expand All @@ -359,7 +359,7 @@ private void onTotalChildrenHeightChange(int newTotalChildrenHeight) {
((ReactContext) getContext()).getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(new ContentSizeChangeEvent(
getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
getWidth(),
newTotalChildrenHeight));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private static void emitScrollEvent(ViewGroup scrollView, ScrollEventType scroll
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
ScrollEvent.obtain(
scrollView.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
scrollEventType,
scrollView.getScrollX(),
scrollView.getScrollY(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSliderEvent(
seekbar.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
((ReactSlider)seekbar).toRealProgress(progress),
fromUser));
}
Expand All @@ -96,7 +96,7 @@ public void onStopTrackingTouch(SeekBar seekbar) {
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSlidingCompleteEvent(
seekbar.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
((ReactSlider)seekbar).toRealProgress(seekbar.getProgress())));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ protected void addEventEmitters(
@Override
public void onRefresh() {
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()
.dispatchEvent(new RefreshEvent(view.getId(), SystemClock.nanoTime()));
.dispatchEvent(new RefreshEvent(view.getId(), SystemClock.elapsedRealtime()));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher().dispatchEvent(
new ReactSwitchEvent(
buttonView.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
isChecked));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -567,7 +567,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
mEventDispatcher.dispatchEvent(
new ReactTextChangedEvent(
mEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
s.toString(),
(int) PixelUtil.toDIPFromPixel(contentWidth),
(int) PixelUtil.toDIPFromPixel(contentHeight),
Expand All @@ -576,7 +576,7 @@ public void onTextChanged(CharSequence s, int start, int before, int count) {
mEventDispatcher.dispatchEvent(
new ReactTextInputEvent(
mEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
newText,
oldText,
start,
Expand All @@ -602,17 +602,17 @@ public void onFocusChange(View v, boolean hasFocus) {
eventDispatcher.dispatchEvent(
new ReactTextInputFocusEvent(
editText.getId(),
SystemClock.nanoTime()));
SystemClock.elapsedRealtime()));
} else {
eventDispatcher.dispatchEvent(
new ReactTextInputBlurEvent(
editText.getId(),
SystemClock.nanoTime()));
SystemClock.elapsedRealtime()));

eventDispatcher.dispatchEvent(
new ReactTextInputEndEditingEvent(
editText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
editText.getText().toString()));
}
}
Expand All @@ -630,7 +630,7 @@ public boolean onEditorAction(TextView v, int actionId, KeyEvent keyEvent) {
eventDispatcher.dispatchEvent(
new ReactTextInputSubmitEditingEvent(
editText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
editText.getText().toString()));
}
if (actionId == EditorInfo.IME_ACTION_NEXT ||
Expand Down Expand Up @@ -667,7 +667,7 @@ public void onSelectionChanged(int start, int end) {
mEventDispatcher.dispatchEvent(
new ReactTextInputSelectionEvent(
mReactEditText.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
start,
end
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ protected void addEventEmitters(final ThemedReactContext reactContext, final Rea
@Override
public void onClick(View v) {
mEventDispatcher.dispatchEvent(
new ToolbarClickEvent(view.getId(), SystemClock.nanoTime(), -1));
new ToolbarClickEvent(view.getId(), SystemClock.elapsedRealtime(), -1));
}
});

Expand All @@ -142,7 +142,7 @@ public boolean onMenuItemClick(MenuItem menuItem) {
mEventDispatcher.dispatchEvent(
new ToolbarClickEvent(
view.getId(),
SystemClock.nanoTime(),
SystemClock.elapsedRealtime(),
menuItem.getOrder()));
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ private class PageChangeListener implements OnPageChangeListener {
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
mEventDispatcher.dispatchEvent(
new PageScrollEvent(getId(), SystemClock.nanoTime(), position, positionOffset));
new PageScrollEvent(getId(), SystemClock.elapsedRealtime(), position, positionOffset));
}

@Override
public void onPageSelected(int position) {
if (!mIsCurrentItemFromJs) {
mEventDispatcher.dispatchEvent(
new PageSelectedEvent(getId(), SystemClock.nanoTime(), position));
new PageSelectedEvent(getId(), SystemClock.elapsedRealtime(), position));
}
}

Expand All @@ -119,7 +119,7 @@ public void onPageScrollStateChanged(int state) {
throw new IllegalStateException("Unsupported pageScrollState");
}
mEventDispatcher.dispatchEvent(
new PageScrollStateChangedEvent(getId(), SystemClock.nanoTime(), pageScrollState));
new PageScrollStateChangedEvent(getId(), SystemClock.elapsedRealtime(), pageScrollState));
}
}

Expand Down
Loading