Repository navigation
create gesture recognizers on attach and dispose on detach to avoid leaks - #42076
Conversation
|
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
|
First of all, Welcome and thank you for contributing to flutter ! The change looks good, but we would like to have test to make sure no one break it in the future. Can you add a test for this change? |
|
Thanks :) |
|
Yes, it seems extreme hard to test this method.... Someone might have a better idea I can only think of an indirect way of testing this test('editale test', () {
final TextSelectionDelegate delegate = FakeEditableTextState();
final RenderEditable editable = RenderEditable(
backgroundCursorColor: Colors.grey,
selectionColor: Colors.black,
textDirection: TextDirection.ltr,
cursorColor: Colors.red,
offset: ViewportOffset.zero(),
textSelectionDelegate: delegate,
text: const TextSpan(
text: 'test',
style: TextStyle(
height: 1.0, fontSize: 10.0, fontFamily: 'Ahem',
),
),
startHandleLayerLink: LayerLink(),
endHandleLayerLink: LayerLink(),
selection: const TextSelection(
baseOffset: 0,
extentOffset: 3,
affinity: TextAffinity.upstream,
),
onSelectionChanged: (_, __, ___) { },
);
final PipelineOwner owner = PipelineOwner(onNeedVisualUpdate: () { });
// Implement CustomTestWidgetsFlutterBinding that implement a spy into
// GestureBinding.instance.pointerRouter you can use TestWidgetsFlutterBinding
// as template
CustomTestWidgetsFlutterBinding.ensureInitialized();
editable.attach(owner);
// This should register pointer into GestureBinding.instance.pointerRouter.
editable.handleEvent(const PointerDownEvent(), BoxHitTestEntry(editable, const Offset(10,10)));
editable.detach();
// Make sure GestureBinding.instance.pointerRouter is removed
// ...
});When Rendereditable handle a pointer event it will use taprecognizer to register the pointer into GestureBinding.instance.pointerRouter. Let me know if any of the code above is unclear. |
f590209 to
09db9bb
Compare
|
@chunhtai ok I finally was able to make that test !! I was struggling to spy the GestureBinding. Let me know if it's ok |
chunhtai
left a comment
There was a problem hiding this comment.
Nice test!
I left some minor styling comment. overall all looks good.
0274895 to
6b5f238
Compare
|
@chunhtai I have a problem, look like _GestureBindingSpy() have to be called before the test start, but if I do so all other tests are failing. |
6b5f238 to
605eb92
Compare
|
I've push it on another file to be sure all the CI builds were green :) all good |
605eb92 to
f58da36
Compare
f58da36 to
7d1430a
Compare
|
@goderbauer I have made the changes, but look like some builds need to be restart (errors doesn't look like happening because of my changes) |
goderbauer
left a comment
There was a problem hiding this comment.
LGTM
I restarted the build for you.
|
Thank you again for the contribution @jaumard ! 🎉 |
Description
Create gesture recognizer on attach and dispose them on dispose to avoid leaks on RenderEditable
Related Issues
fix #39636
Tests
I added the following tests:
Didn't added any as it's only internal fields, let me know if I can add some and how.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]). This will ensure a smooth and quick review process.///).flutter analyze --flutter-repo) does not report any problems on my PR.Breaking Change
Does your PR require Flutter developers to manually update their apps to accommodate your change?