Repository navigation
fix a PlatformView gesture bug #84257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,9 +4,11 @@ | |
|
|
||
| import 'dart:ui' as ui; | ||
|
|
||
| import 'package:fake_async/fake_async.dart'; | ||
| import 'package:flutter/foundation.dart'; | ||
| import 'package:flutter/gestures.dart'; | ||
| import 'package:flutter/rendering.dart'; | ||
| import 'package:flutter/services.dart'; | ||
| import 'package:flutter_test/flutter_test.dart'; | ||
| import '../services/fake_platform_views.dart'; | ||
| import 'rendering_tester.dart'; | ||
|
|
@@ -98,15 +100,68 @@ void main() { | |
| }); | ||
|
|
||
| }, skip: isBrowser); // TODO(yjbanov): fails on Web with obscured stack trace: https://github.com/flutter/flutter/issues/42770 | ||
|
|
||
| // Regression test for https://github.com/flutter/flutter/issues/69431 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. did you confirm that reverting the changes in platform_views.dart causes this test to fail?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes,this can reproduce the issue. |
||
| test('multi-finger touch test', () { | ||
| renderer; // Initialize bindings. | ||
| final FakeAndroidPlatformViewsController viewsController = FakeAndroidPlatformViewsController(); | ||
| viewsController.registerViewType('webview'); | ||
| final AndroidViewController viewController = | ||
| PlatformViewsService.initAndroidView(id: 0, viewType: 'webview', layoutDirection: TextDirection.rtl); | ||
| final PlatformViewRenderBox platformViewRenderBox = PlatformViewRenderBox( | ||
| controller: viewController, | ||
| hitTestBehavior: PlatformViewHitTestBehavior.opaque, | ||
| gestureRecognizers: <Factory<OneSequenceGestureRecognizer>>{ | ||
| Factory<VerticalDragGestureRecognizer>( | ||
| () => VerticalDragGestureRecognizer(), | ||
| ), | ||
| }, | ||
| ); | ||
| layout(platformViewRenderBox); | ||
| pumpFrame(phase: EnginePhase.flushSemantics); | ||
|
|
||
| viewController.pointTransformer = (Offset offset) => platformViewRenderBox.globalToLocal(offset); | ||
|
|
||
| FakeAsync().run((FakeAsync async) { | ||
| // Put one pointer down. | ||
| ui.window.onPointerDataPacket!(ui.PointerDataPacket(data: <ui.PointerData>[ | ||
| _pointerData(ui.PointerChange.add, Offset.zero, pointer: 1, kind: PointerDeviceKind.touch), | ||
| _pointerData(ui.PointerChange.down, const Offset(10, 10), pointer: 1, kind: PointerDeviceKind.touch), | ||
| _pointerData(ui.PointerChange.remove, const Offset(10, 10), pointer: 1, kind: PointerDeviceKind.touch), | ||
| ])); | ||
| async.flushMicrotasks(); | ||
|
|
||
| // Put another pointer down and then cancel it. | ||
| ui.window.onPointerDataPacket!(ui.PointerDataPacket(data: <ui.PointerData>[ | ||
| _pointerData(ui.PointerChange.add, Offset.zero, pointer: 2, kind: PointerDeviceKind.touch), | ||
| _pointerData(ui.PointerChange.down, const Offset(20, 10), pointer: 2, kind: PointerDeviceKind.touch), | ||
| _pointerData(ui.PointerChange.cancel, const Offset(20, 10), pointer: 2, kind: PointerDeviceKind.touch), | ||
| ])); | ||
| async.flushMicrotasks(); | ||
|
|
||
| // The first pointer can still moving without crashing. | ||
| ui.window.onPointerDataPacket!(ui.PointerDataPacket(data: <ui.PointerData>[ | ||
| _pointerData(ui.PointerChange.add, Offset.zero, pointer: 1, kind: PointerDeviceKind.touch), | ||
| _pointerData(ui.PointerChange.move, const Offset(10, 10), pointer: 1, kind: PointerDeviceKind.touch), | ||
| _pointerData(ui.PointerChange.remove, const Offset(10, 10), pointer: 1, kind: PointerDeviceKind.touch), | ||
| ])); | ||
| async.flushMicrotasks(); | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this test need to expect something?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the original issue, it does not need to expect anything, but only not throw any errors. I usually include the following line for such cases: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if possible, I'd try to test this logic explicitly: https://github.com/flutter/flutter/pull/84257/files#diff-02ee737d0b04265db456b12d3e7c3499b84e321bcc8d3a8e4e30757b6cba3e94R544-R546 |
||
| }); | ||
|
|
||
| // Passes if no crashes. | ||
| }); | ||
| } | ||
|
|
||
| ui.PointerData _pointerData( | ||
| ui.PointerChange change, | ||
| Offset logicalPosition, { | ||
| int device = 0, | ||
| PointerDeviceKind kind = PointerDeviceKind.mouse, | ||
| int pointer = 0, | ||
| }) { | ||
| return ui.PointerData( | ||
| pointerIdentifier: pointer, | ||
| embedderId: pointer, | ||
| change: change, | ||
| physicalX: logicalPosition.dx * ui.window.devicePixelRatio, | ||
| physicalY: logicalPosition.dy * ui.window.devicePixelRatio, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a comment would be helpful: "pointer cancel is handled like pointer up. Normally, the difference is that pointer cancel doesn't perform any action, but in this case neither up or cancel perform any action".