From f5a349021d3e9ccaf1a1590dc984c0ea16a177ca Mon Sep 17 00:00:00 2001 From: Andrei Coman Date: Wed, 9 Mar 2016 12:40:35 -0800 Subject: [PATCH] Fix event dispatcher timestamp sorting bug Summary:Turns out even using nanoseconds as timestamps will not guarantee that events won't happen at the same time. This fixes sorting for event comparison. Differential Revision: D3030540 fb-gh-sync-id: 2630c50ea60a792ea07b1bf1c6cd46a6d9859268 shipit-source-id: 2630c50ea60a792ea07b1bf1c6cd46a6d9859268 --- .../react/uimanager/events/EventDispatcher.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java index d55401af6..537f1bfb4 100644 --- a/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java +++ b/ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java @@ -13,7 +13,6 @@ import javax.annotation.Nullable; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.Comparator; import java.util.Map; @@ -75,7 +74,14 @@ public class EventDispatcher implements LifecycleEventListener { return 1; } - return lhs.getTimestampMs() < rhs.getTimestampMs() ? -1 : 1; + long diff = lhs.getTimestampMs() - rhs.getTimestampMs(); + if (diff == 0) { + return 0; + } else if (diff < 0) { + return -1; + } else { + return 1; + } } };