Skip to content

Commit

Permalink
Take the events back from framework
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaushik Iska committed Jul 6, 2020
1 parent 61b6271 commit 27015c8
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,12 @@ public static MotionEventId createUnique() {
return MotionEventId.from(ID_COUNTER.incrementAndGet());
}

public boolean equals(Object object) {
if (this == object) return true;
if (object == null || getClass() != object.getClass()) return false;
if (!super.equals(object)) return false;

MotionEventId that = (MotionEventId) object;

if (id != that.id) return false;

return true;
}

public int hashCode() {
int result = super.hashCode();
result = 31 * result + (int) (id ^ (id >>> 32));
return result;
}

public long getId() {
return id;
}
}

private final Map<MotionEventId, MotionEvent> eventById;
private final Map<Long, MotionEvent> eventById;
private static MotionEventTracker INSTANCE;

public static MotionEventTracker getInstance() {
Expand All @@ -66,7 +48,7 @@ private MotionEventTracker() {
/** Tracks the event and returns a unique MotionEventId identifying the event. */
public MotionEventId track(MotionEvent event) {
MotionEventId eventId = MotionEventId.createUnique();
eventById.put(eventId, event);
eventById.put(eventId.id, event);
return eventId;
}

Expand All @@ -78,6 +60,6 @@ public MotionEventId track(MotionEvent event) {
@Nullable
public MotionEvent pop(MotionEventId eventId) {
// TODO(kaushikiska) do the actual timestamp based book-keeping.
return eventById.remove(eventId);
return eventById.remove(eventId.id);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ private void touch(@NonNull MethodCall call, @NonNull MethodChannel.Result resul
(int) args.get(11),
(int) args.get(12),
(int) args.get(13),
(int) args.get(14));
(int) args.get(14),
((Number) args.get(15)).longValue());

try {
handler.onTouch(touch);
Expand Down Expand Up @@ -380,6 +381,8 @@ public static class PlatformViewTouch {
public final int source;
/** TODO(mattcarroll): javadoc */
public final int flags;
/** TODO(iskakaushik): javadoc */
public final long motionEventId;

PlatformViewTouch(
int viewId,
Expand All @@ -396,7 +399,8 @@ public static class PlatformViewTouch {
int deviceId,
int edgeFlags,
int source,
int flags) {
int flags,
long motionEventId) {
this.viewId = viewId;
this.downTime = downTime;
this.eventTime = eventTime;
Expand All @@ -412,6 +416,7 @@ public static class PlatformViewTouch {
this.edgeFlags = edgeFlags;
this.source = source;
this.flags = flags;
this.motionEventId = motionEventId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import androidx.annotation.VisibleForTesting;
import io.flutter.embedding.android.FlutterImageView;
import io.flutter.embedding.android.FlutterView;
import io.flutter.embedding.android.MotionEventTracker;
import io.flutter.embedding.engine.FlutterOverlaySurface;
import io.flutter.embedding.engine.dart.DartExecutor;
import io.flutter.embedding.engine.mutatorsstack.*;
Expand Down Expand Up @@ -93,6 +94,9 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
// Platform view IDs that were displayed since the start of the current frame.
private HashSet<Integer> currentFrameUsedPlatformViewIds;

// Used to acquire the original motion events using the motionEventIds.
private final MotionEventTracker motionEventTracker;

private final PlatformViewsChannel.PlatformViewsHandler channelHandler =
new PlatformViewsChannel.PlatformViewsHandler() {

Expand Down Expand Up @@ -301,8 +305,16 @@ private void ensureValidAndroidVersion(int minSdkVersion) {
}
};

private static MotionEvent toMotionEvent(
float density, PlatformViewsChannel.PlatformViewTouch touch) {
private MotionEvent toMotionEvent(float density, PlatformViewsChannel.PlatformViewTouch touch) {
MotionEventTracker.MotionEventId motionEventId =
MotionEventTracker.MotionEventId.from(touch.motionEventId);
MotionEvent trackedEvent = motionEventTracker.pop(motionEventId);
if (trackedEvent != null) {
return trackedEvent;
}

// TODO (kaushikiska) : warn that we are potentially using an untracked
// event in the platform views.
PointerProperties[] pointerProperties =
parsePointerPropertiesList(touch.rawPointerPropertiesList)
.toArray(new PointerProperties[touch.pointerCount]);
Expand Down Expand Up @@ -339,6 +351,8 @@ public PlatformViewsController() {
platformViewRequests = new SparseArray<>();
platformViews = new SparseArray<>();
mutatorViews = new SparseArray<>();

motionEventTracker = MotionEventTracker.getInstance();
}

/**
Expand Down

0 comments on commit 27015c8

Please sign in to comment.