Skip to content

Conversation

@dkwingsmt
Copy link
Contributor

@dkwingsmt dkwingsmt commented Jun 5, 2019

Description

While I'm writing #32770, which involves a custom gesture recognizer, I discovered that it is impossible for custom gestures to provide semantics information, because RawGestureDetector hard-coded how it generates them and only supports the "official" gesture recognizers.

This PR adds a new parameter to RawGestureDetector, SemanticsGestureDelegate semantics configures how detectors handle semantics gestures. It has a default delegate that keep the current behavior.

SemanticsGestureDelegate has a method that allows custom GestureDetectors to define the semantics annotations to add.

Regarding the changed test

A test "cache unchanged callbacks" has been changed so that it is no longer required to cache callbacks.

  • Why it is safe to remove:
  • Why it is preferable to remove:
    • It brings unnecessary overhead in terms of time and memory.
    • It makes writing a custom SemanticsGestureDelegate more complicated. To cache it, the delegate must be stored in a State, which requires the custom gesture detector to be stateful.

This change has been discussed with and approved by @goderbauer.

Related Issues

Tests

I added the following tests:

  • RawGestureDetector
    • A semantic gesture triggers all handlers of that kind
    • Replacing gesture recognizers should update semantic handlers
    • RawGestureDetector caches handlers returned by GestureSemanticsMapping
  • DefaultGestureSemanticsMapping, for each of the methods
    • It should return null when there is no recognizer
    • It should return non-null when there is a recognizer (with empty callback)
    • It should correctly call callbacks

I changed the following tests:

  • "cache unchanged callbacks" no longer requires caching callbacks

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.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@dkwingsmt dkwingsmt added the f: gestures flutter/packages/flutter/gestures repository. label Jun 5, 2019
@Piinks Piinks added the framework flutter/packages/flutter repository. See also f: labels. label Jun 5, 2019
@dkwingsmt dkwingsmt requested a review from Hixie June 7, 2019 19:48
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the analyzer found something:

  • info • Avoid empty statements • packages/flutter/lib/src/widgets/gesture_detector.dart:947:6 • empty_statements

@dkwingsmt dkwingsmt requested a review from goderbauer June 25, 2019 01:31
@Hixie
Copy link
Contributor

Hixie commented Jun 26, 2019

LGTM modulo the docs fixes and measuring the perf impact relating to the test at the end.

@dkwingsmt dkwingsmt mentioned this pull request Jun 28, 2019
9 tasks
Copy link
Member

@goderbauer goderbauer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this is missing a tests that shows that changing RawGestureDetector.semantics from one delegate to another actually correctly updates the semantics tree?

@dkwingsmt
Copy link
Contributor Author

@goderbauer I forgot to push my latest commits. Can you check out https://github.com/flutter/flutter/pull/33936/files#diff-322ca57cfdd8734e5234cc676b05ce2cR177 and L213?

@goderbauer
Copy link
Member

Can you check out https://github.com/flutter/flutter/pull/33936/files#diff-322ca57cfdd8734e5234cc676b05ce2cR177 and L213?

That seems to only tests switching from and to the DefaultDelegate. What if semantics switches from non-default-delegate x to non-default-delegate y?

@dkwingsmt
Copy link
Contributor Author

The last comment has been addressed by 36352c5

@dkwingsmt dkwingsmt merged commit 1a374d8 into flutter:master Jul 1, 2019
@dkwingsmt dkwingsmt deleted the general-gesture-semantics-v2 branch July 1, 2019 23:17
tango5614 added a commit to tango5614/flutter that referenced this pull request Jul 4, 2019
* commit 'a0c47e2216a2b50b70c478001cf5652f31a783af': (187 commits)
  Do not use ideographic baseline for RenderPargraph baseline (flutter#35493)
  Add type to StreamChannel in generated test code. (flutter#35367)
  Fix RenderFittedBox when child.size.isEmpty (flutter#35487)
  add APK build time benchmarks (flutter#35481)
  fix Selection handles position is off (flutter#34665)
  Move usage flutter create tests into memory filesystem. (flutter#35160)
  Include tags in SemanticsNode debug properties (flutter#35491)
  Re-apply 'Add currentSystemFrameTimeStamp to SchedulerBinding' (flutter#35492)
  CupertinoTextField vertical alignment (flutter#34723)
  Mark update-packages as non-experimental (flutter#35467)
  fix default artifacts to exclude ios and android (flutter#35303)
  Roll engine ffba2f6..7d3e722 (59 commits) (flutter#35489)
  Update macrobenchmarks README and app name (flutter#35477)
  mark windows and macos chrome dev mode as flaky (flutter#35495)
  Use the new service protocol message names (flutter#35482)
  Manual roll of engine 45b66b7...ffba2f6 (flutter#35464)
  more ui-as-code (flutter#35393)
  update reassemble doc (flutter#35164)
  New parameter for RawGestureDetector to customize semantics mapping (flutter#33936)
  Add --target support for Windows and Linux (flutter#34660)
  ...
johnsonmh pushed a commit to johnsonmh/flutter that referenced this pull request Jul 30, 2019
…lutter#33936)

This PR adds a new parameter to RawGestureDetector, `semantics`, which configures how detectors handle semantics gestures. It has a default delegate that keep the current behavior.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: gestures flutter/packages/flutter/gestures repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants