-
Notifications
You must be signed in to change notification settings - Fork 3.6k
[pointer_interceptor] Allow conditional pointer interception #538
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
Merged
fluttergithubbot
merged 6 commits into
flutter:main
from
Rexios80:feature/pointer-interceptor-toggle
Feb 1, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0834744
Added an intercepting field to conditionally disable pointer intercep…
Rexios80 c19ea83
Added changelog entry
Rexios80 af607c5
Added a test and updated pubspec
Rexios80 6495632
Merge branch 'main' into feature/pointer-interceptor-toggle
Rexios80 5bb458e
Update README with the new prop.
ditman fad4268
Merge branch 'main' into feature/pointer-interceptor-toggle
ditman File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This isn't at all how the other classes you referenced behave. What's the use case for having a property vs. clients just not using the wrapper if this is the behavior they want?
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.
I'm using floating_material_search_bar which always has a widget filling the whole screen for hit testing. I need the widget to pass through touches to a Google Map when the search bar is not focused, but intercept them when the search bar is focused.
I didn't look at the implementation of Ignore/AbsorbPointer, but how is this different than how they behave?
AbsorbPointer documentation:
IgnorePointer documentation:
Is a lot simpler than:
I used mobile.dart as reference for what to do when the flag is false.
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.
They don't conditionally change what
buildreturns, unless I missed something.That's true, but that's a false choice because you're duplicating the code to create the child. If what you want is to conditionally wrap something in a
PointerInterceptoryou could make a trivial local helper method that does that.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.
On implementation
There's two ways to do this. One is what this PR does or the helper method that @stuartmorgan is suggecting (let's call it "conditional build"). Another one is to do it at the
RenderObjectlevel (let's call it "conditional render"). There are pros and cons.Pros of conditional build:
interceptingdoesn't change over time (or changes rarely), then it's more efficient for thefalsecase because it doesn't increase the size of theElementtree.Pros of conditional render:
interceptingchanges frequently. Because pointer interceptor is a platform view italwaysNeedsCompositing, so it will break up pictures into more layers than when there's no interceptor. If the widget flips between intercepting and not, it will significantly alter the shape of the render tree and especially of the layer tree. At the render object level the tree could be kept more stable between intercepting or not because it could keep the same layer structure.Conditional rendering would have to be implemented in this package. Conditional build can be implemented as a helper function.
On ergonomics
I really prefer the ergonomics of a flag compared to having to write a helper function. You won't have many interceptors in the same library, but you may have many interceptors across your codebase and the discovery of a custom helper function like this will be low. In most cases we want people to just be able to import this package and get good ergonomics from it out of the box. If enabling/disabling the interceptor is an important use-case, then I'd argue it should also be ergonomic out of the box. Honestly, I wouldn't want to write that
if/elseeven once. If the interceptor is in the middle of a deep widget hierarchy, making it conditional will mess up all of the surrounding code.