Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 27015c8

Browse files
author
Kaushik Iska
committed
Take the events back from framework
1 parent 61b6271 commit 27015c8

File tree

3 files changed

+26
-25
lines changed

3 files changed

+26
-25
lines changed

shell/platform/android/io/flutter/embedding/android/MotionEventTracker.java

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,12 @@ public static MotionEventId createUnique() {
2626
return MotionEventId.from(ID_COUNTER.incrementAndGet());
2727
}
2828

29-
public boolean equals(Object object) {
30-
if (this == object) return true;
31-
if (object == null || getClass() != object.getClass()) return false;
32-
if (!super.equals(object)) return false;
33-
34-
MotionEventId that = (MotionEventId) object;
35-
36-
if (id != that.id) return false;
37-
38-
return true;
39-
}
40-
41-
public int hashCode() {
42-
int result = super.hashCode();
43-
result = 31 * result + (int) (id ^ (id >>> 32));
44-
return result;
45-
}
46-
4729
public long getId() {
4830
return id;
4931
}
5032
}
5133

52-
private final Map<MotionEventId, MotionEvent> eventById;
34+
private final Map<Long, MotionEvent> eventById;
5335
private static MotionEventTracker INSTANCE;
5436

5537
public static MotionEventTracker getInstance() {
@@ -66,7 +48,7 @@ private MotionEventTracker() {
6648
/** Tracks the event and returns a unique MotionEventId identifying the event. */
6749
public MotionEventId track(MotionEvent event) {
6850
MotionEventId eventId = MotionEventId.createUnique();
69-
eventById.put(eventId, event);
51+
eventById.put(eventId.id, event);
7052
return eventId;
7153
}
7254

@@ -78,6 +60,6 @@ public MotionEventId track(MotionEvent event) {
7860
@Nullable
7961
public MotionEvent pop(MotionEventId eventId) {
8062
// TODO(kaushikiska) do the actual timestamp based book-keeping.
81-
return eventById.remove(eventId);
63+
return eventById.remove(eventId.id);
8264
}
8365
}

shell/platform/android/io/flutter/embedding/engine/systemchannels/PlatformViewsChannel.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ private void touch(@NonNull MethodCall call, @NonNull MethodChannel.Result resul
166166
(int) args.get(11),
167167
(int) args.get(12),
168168
(int) args.get(13),
169-
(int) args.get(14));
169+
(int) args.get(14),
170+
((Number) args.get(15)).longValue());
170171

171172
try {
172173
handler.onTouch(touch);
@@ -380,6 +381,8 @@ public static class PlatformViewTouch {
380381
public final int source;
381382
/** TODO(mattcarroll): javadoc */
382383
public final int flags;
384+
/** TODO(iskakaushik): javadoc */
385+
public final long motionEventId;
383386

384387
PlatformViewTouch(
385388
int viewId,
@@ -396,7 +399,8 @@ public static class PlatformViewTouch {
396399
int deviceId,
397400
int edgeFlags,
398401
int source,
399-
int flags) {
402+
int flags,
403+
long motionEventId) {
400404
this.viewId = viewId;
401405
this.downTime = downTime;
402406
this.eventTime = eventTime;
@@ -412,6 +416,7 @@ public static class PlatformViewTouch {
412416
this.edgeFlags = edgeFlags;
413417
this.source = source;
414418
this.flags = flags;
419+
this.motionEventId = motionEventId;
415420
}
416421
}
417422
}

shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import androidx.annotation.VisibleForTesting;
2222
import io.flutter.embedding.android.FlutterImageView;
2323
import io.flutter.embedding.android.FlutterView;
24+
import io.flutter.embedding.android.MotionEventTracker;
2425
import io.flutter.embedding.engine.FlutterOverlaySurface;
2526
import io.flutter.embedding.engine.dart.DartExecutor;
2627
import io.flutter.embedding.engine.mutatorsstack.*;
@@ -93,6 +94,9 @@ public class PlatformViewsController implements PlatformViewsAccessibilityDelega
9394
// Platform view IDs that were displayed since the start of the current frame.
9495
private HashSet<Integer> currentFrameUsedPlatformViewIds;
9596

97+
// Used to acquire the original motion events using the motionEventIds.
98+
private final MotionEventTracker motionEventTracker;
99+
96100
private final PlatformViewsChannel.PlatformViewsHandler channelHandler =
97101
new PlatformViewsChannel.PlatformViewsHandler() {
98102

@@ -301,8 +305,16 @@ private void ensureValidAndroidVersion(int minSdkVersion) {
301305
}
302306
};
303307

304-
private static MotionEvent toMotionEvent(
305-
float density, PlatformViewsChannel.PlatformViewTouch touch) {
308+
private MotionEvent toMotionEvent(float density, PlatformViewsChannel.PlatformViewTouch touch) {
309+
MotionEventTracker.MotionEventId motionEventId =
310+
MotionEventTracker.MotionEventId.from(touch.motionEventId);
311+
MotionEvent trackedEvent = motionEventTracker.pop(motionEventId);
312+
if (trackedEvent != null) {
313+
return trackedEvent;
314+
}
315+
316+
// TODO (kaushikiska) : warn that we are potentially using an untracked
317+
// event in the platform views.
306318
PointerProperties[] pointerProperties =
307319
parsePointerPropertiesList(touch.rawPointerPropertiesList)
308320
.toArray(new PointerProperties[touch.pointerCount]);
@@ -339,6 +351,8 @@ public PlatformViewsController() {
339351
platformViewRequests = new SparseArray<>();
340352
platformViews = new SparseArray<>();
341353
mutatorViews = new SparseArray<>();
354+
355+
motionEventTracker = MotionEventTracker.getInstance();
342356
}
343357

344358
/**

0 commit comments

Comments
 (0)