Skip to content

Conversation

@gspencergoog
Copy link
Contributor

Description

This changes Listener to trigger enter/move/exit in all Listeners below the pointer, not just the leaf region (the first region hit). This is because we need to allow listeners to be nested so that, say, a widget that handles changing color on hover, but also is wrapped in a Tooltip (that handles hover) can trigger both actions, not just one.

To that end, I added a findAll to Layer, similar to the existing find method that was previously used. It returns an iterator over annotated layers which match the given data type.

Since the findAll is implemented as returning an Iterable (and is sync*), I re-implemented the find routines as just returning the first result from findAll, since that should be just as efficient, and would then prevent duplication in the implementation.

Tests

I added the following tests:

  • Tests for findAll similar to find, as well as extra tests having to do with returned order of results (which is leaf first, then ancestors).
  • Tests for Listener that assure that nested listeners do the right thing.

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?

  • No, this is not a breaking change. Although it does change the behavior of Listener, it is a bug fix in that previously nested listeners would not have been functional (the parent listeners would have been ignored), and now they are functional (not ignored).

@gspencergoog gspencergoog changed the title Fix nested listeners so that parent listeners can also receive enter/exit/move events. Fix nested listeners so that ancestor listeners can also receive enter/exit/move events. May 8, 2019
Copy link
Contributor

@jonahwilliams jonahwilliams left a comment

Choose a reason for hiding this comment

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

LGTM with nitt

}

@override
Iterable<S> findAll<S>(Offset regionOffset) sync* {
Copy link
Contributor

Choose a reason for hiding this comment

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

TBH I really dislike sync*, it has very poor performance characteristics. On the other hand, it is a clear win getting to implement findAll in terms of find in a lazy manner

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this was a tradeoff. It's an implementation detail, though, so we can change it to use lists or something if it turns out to hurt performance.

@gspencergoog gspencergoog merged commit aeccd6a into flutter:master May 9, 2019
gspencergoog added a commit to gspencergoog/flutter that referenced this pull request May 9, 2019
…ive enter/exit/move events. (flutter#32350)"

This reverts commit aeccd6a due to a performance regression.
gspencergoog added a commit that referenced this pull request May 9, 2019
This fixes a benchmark regression introduced in #32350. The performance is improved by just reverting the Layer.find<S> routines to use their old definitions, instead of defining them in terms of the findAll<S> lazy iterators.

Fixes #32387
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants