Skip to content

Commit 55be696

Browse files
Emmanuel GarciaPragya007
authored andcommitted
Account for MotionEvent instance mutations (flutter#61417)
1 parent feb92a4 commit 55be696

File tree

3 files changed

+15
-115
lines changed

3 files changed

+15
-115
lines changed

dev/integration_tests/android_views/android/app/src/main/java/io/flutter/integration/androidviews/MainActivity.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public void configureFlutterEngine(FlutterEngine flutterEngine) {
5252
.registerViewFactory("simple_view", new SimpleViewFactory(executor));
5353
mMethodChannel = new MethodChannel(executor, "android_views_integration");
5454
mMethodChannel.setMethodCallHandler(this);
55+
GeneratedPluginRegistrant.registerWith(flutterEngine);
5556
}
5657

5758
@Override

dev/integration_tests/android_views/lib/wm_integrations.dart

Lines changed: 10 additions & 114 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'dart:io';
56
import 'dart:ui';
67

78
import 'package:flutter/material.dart';
@@ -16,7 +17,6 @@ class WindowManagerIntegrationsPage extends PageWidget {
1617

1718
@override
1819
Widget build(BuildContext context) => WindowManagerBody();
19-
2020
}
2121

2222
class WindowManagerBody extends StatefulWidget {
@@ -133,15 +133,17 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
133133
}
134134
}
135135

136-
137136
Future<void> onTapWindowPressed() async {
138137
await Future<void>.delayed(const Duration(seconds: 1));
139-
for (final AndroidMotionEvent event in _tapSequence) {
140-
await SystemChannels.platform_views.invokeMethod<dynamic>(
141-
'touch',
142-
_motionEventasList(event, id),
143-
);
144-
}
138+
139+
// Dispatch a tap event on the child view inside the platform view.
140+
//
141+
// Android mutates `MotionEvent` instances, so in this case *do not* dispatch
142+
// new instances as it won't cover the `MotionEventTracker` class in the embedding
143+
// which tracks events.
144+
//
145+
// See the issue this prevents: https://github.com/flutter/flutter/issues/61169
146+
await Process.run('input', const <String>['tap', '250', '550']);
145147
}
146148

147149
void onPlatformViewCreated(int id) {
@@ -151,110 +153,4 @@ class WindowManagerBodyState extends State<WindowManagerBody> {
151153
});
152154
}
153155

154-
155-
static List<double> _pointerCoordsAsList(AndroidPointerCoords coords) {
156-
return <double>[
157-
coords.orientation,
158-
coords.pressure,
159-
coords.size,
160-
coords.toolMajor,
161-
coords.toolMinor,
162-
coords.touchMajor,
163-
coords.touchMinor,
164-
coords.x,
165-
coords.y,
166-
];
167-
}
168-
169-
static List<dynamic> _motionEventasList(AndroidMotionEvent event, int viewId) {
170-
return <dynamic>[
171-
viewId,
172-
event.downTime,
173-
event.eventTime,
174-
event.action,
175-
event.pointerCount,
176-
event.pointerProperties.map<List<int>>((AndroidPointerProperties p) => <int> [p.id, p.toolType]).toList(),
177-
event.pointerCoords.map<List<double>>((AndroidPointerCoords p) => _pointerCoordsAsList(p)).toList(),
178-
event.metaState,
179-
event.buttonState,
180-
event.xPrecision,
181-
event.yPrecision,
182-
event.deviceId,
183-
event.edgeFlags,
184-
event.source,
185-
event.flags,
186-
event.motionEventId,
187-
];
188-
}
189-
190-
static final List<AndroidMotionEvent> _tapSequence = <AndroidMotionEvent> [
191-
AndroidMotionEvent(
192-
downTime: 723657071,
193-
pointerCount: 1,
194-
pointerCoords: <AndroidPointerCoords> [
195-
const AndroidPointerCoords(
196-
orientation: 0.0,
197-
touchMajor: 5.0,
198-
size: 0.019607843831181526,
199-
x: 180.0,
200-
y: 200.0,
201-
touchMinor: 5.0,
202-
pressure: 1.0,
203-
toolMajor: 5.0,
204-
toolMinor: 5.0,
205-
),
206-
],
207-
yPrecision: 1.0,
208-
buttonState: 0,
209-
flags: 0,
210-
source: 4098,
211-
deviceId: 4,
212-
metaState: 0,
213-
pointerProperties: <AndroidPointerProperties> [
214-
const AndroidPointerProperties(
215-
id: 0,
216-
toolType: 1,
217-
),
218-
],
219-
edgeFlags: 0,
220-
eventTime: 723657071,
221-
action: 0,
222-
xPrecision: 1.0,
223-
motionEventId: 1,
224-
),
225-
AndroidMotionEvent(
226-
downTime: 723657071,
227-
eventTime: 723657137,
228-
action: 1,
229-
pointerCount: 1,
230-
pointerProperties: <AndroidPointerProperties> [
231-
const AndroidPointerProperties(
232-
id: 0,
233-
toolType: 1,
234-
),
235-
],
236-
pointerCoords: <AndroidPointerCoords> [
237-
const AndroidPointerCoords(
238-
orientation: 0.0,
239-
touchMajor: 5.0,
240-
size: 0.019607843831181526,
241-
x: 180.0,
242-
y: 200.0,
243-
touchMinor: 5.0,
244-
pressure: 1.0,
245-
toolMajor: 5.0,
246-
toolMinor: 5.0,
247-
)
248-
],
249-
metaState: 0,
250-
buttonState: 0,
251-
xPrecision: 1.0,
252-
yPrecision: 1.0,
253-
deviceId: 4,
254-
edgeFlags: 0,
255-
source: 4098,
256-
flags: 0,
257-
motionEventId: 2,
258-
),
259-
];
260156
}

dev/integration_tests/android_views/test_driver/main_test.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ Future<void> main() async {
5858
await driver.tap(addWindow);
5959
final SerializableFinder tapWindow = find.byValueKey('TapWindow');
6060
await driver.tap(tapWindow);
61-
final String windowClickCount = await driver.getText(find.byValueKey('WindowClickCount'));
61+
final String windowClickCount = await driver.getText(
62+
find.byValueKey('WindowClickCount'),
63+
timeout: const Duration(seconds: 5),
64+
);
6265
expect(windowClickCount, 'Click count: 1');
6366
});
6467
});

0 commit comments

Comments
 (0)