From addd233d31cf0304feea4e9ac63749f152ffd774 Mon Sep 17 00:00:00 2001 From: Andrei Coman Date: Mon, 22 Feb 2016 03:25:58 -0800 Subject: [PATCH] Use nanoTime instead of currentTimeMillis for events Summary: Public We wanted to do this before, but couldn't because touch events had timestamps set by the system (and matched System.currentTimeMillis), but now we set those timestamps! The idea behind this change is that System.currentTimeMillis is unreliable, but nanoTime isn't, and it also guarantees that we will never have two events with the same timestamp. We're still seeing crashes with touch events not ending correctly in JS, this might be the cause of that. Reviewed By: foghina Differential Revision: D2953917 --- .../java/com/facebook/react/flat/FlatViewGroup.java | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java index 6ff83f607..040cec66d 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java +++ b/ReactAndroid/src/main/java/com/facebook/react/flat/FlatViewGroup.java @@ -9,16 +9,15 @@ package com.facebook.react.flat; +import javax.annotation.Nullable; + import java.lang.ref.WeakReference; import java.util.ArrayList; -import javax.annotation.Nullable; - import android.content.Context; import android.graphics.Canvas; import android.graphics.Rect; import android.graphics.drawable.Drawable; -import android.os.SystemClock; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; @@ -26,8 +25,9 @@ import android.view.ViewParent; import com.facebook.react.bridge.ReactContext; import com.facebook.react.bridge.SoftAssertions; -import com.facebook.react.touch.ReactInterceptingViewGroup; +import com.facebook.react.common.SystemClock; import com.facebook.react.touch.OnInterceptTouchEventListener; +import com.facebook.react.touch.ReactInterceptingViewGroup; import com.facebook.react.uimanager.PointerEvents; import com.facebook.react.uimanager.ReactCompoundView; import com.facebook.react.uimanager.ReactPointerEventsView; @@ -68,7 +68,7 @@ import com.facebook.react.views.image.ImageLoadEvent; ReactContext reactContext = ((ReactContext) view.getContext()); UIManagerModule uiManagerModule = reactContext.getNativeModule(UIManagerModule.class); uiManagerModule.getEventDispatcher().dispatchEvent( - new ImageLoadEvent(reactTag, SystemClock.uptimeMillis(), imageLoadEvent)); + new ImageLoadEvent(reactTag, SystemClock.nanoTime(), imageLoadEvent)); } } @@ -234,7 +234,7 @@ import com.facebook.react.views.image.ImageLoadEvent; // height is 0. This is because invalidate() has an optimization where it will not invalidate // empty Views at all. A quick fix is to invalidate a slightly larger region to make sure we // never hit that optimization. - // + // // Another thing to note is that this may not work correctly with software rendering because // in software, Android tracks dirty regions to redraw. We would need to collect information // about all children boundaries (recursively) to track dirty region precisely.