RFC: A position aware composited transform follower #4
Replies: 2 comments 4 replies
-
Hi, I implemented exactly this for a |
Beta Was this translation helpful? Give feedback.
-
Problem mappingTo understand the solution I came up with, I want to quickly map the problem described in your original comment to the specific classes used. Specifically, the selected text is wrapped in a The problem now is that the popover toolbar should change its offset relative to the selected text based on:
Issue to solveThe solution to this seems quite easy:
However, the issue is that the follower (popover toolbar) automatically follows the target (selected text) via the SolutionThis means the solution involves some way of informing our follower about the target's position when making our layout decisions. This is not possible by default (it is hidden in the implementation of the linking). → We need to modify some parts of ImplementationThis is possible. I tried to explain it to you already @matthew-carroll - I am not sure if I am really missing the point here or if you did not look into it closely / were not able to grasp it on the high-level, so I will just try to be as detailed as possible and explain the modifications that I made. The implementation that I built was for
|
Beta Was this translation helpful? Give feedback.
-
Flutter provides two widgets that, when used together, cause one widget to always appear near another widget.
This RFC identifies a limitation of the existing widgets and recommends an extension.
The widget being followed is wrapped with a
CompositedTransformTarget
widget. The widget doing the following is wrapped with aCompositedTransformFollower
widget.One use-case where these widgets are useful is when a text selection drag handle sits beneath the caret.
As shown above, the drag handle always sits a few pixels below the caret. This relative position should remain true, no matter where the caret goes, or where the user scrolls. For example, even when the user scrolls the content off-screen, the selection handle should remain beneath the caret.
A composited transform follower provides two benefits:
Scrollable
, then to align an overlay widget with a piece of content in that scrollable, the developer would need to listen for all scroll changes and then rebuild the overlay widget. This problem is compounded if aScrollable
sits within anotherScrollable
. Alignment requires full knowledge of the UI, and full access to all controllers that move content around the screen. This problem is generally intractable.The problem with
CompositedTransformFollower
is that itsoffset
is static and so is itschild
.Consider, for example, a popover toolbar for text editing. When it fits on the screen, everything works fine.
The problem with this example is that the popover toolbar should re-orient itself when it gets too close to the screen boundary, but a
CompositedTransformFollower
doesn't allow for this.Instead of scrolling offscreen, the toolbar should jump to the bottom of the selected content.
The above use-case is not currently possible with a
CompositedTransformFollower
because the developer can't make any decisions based on the target's offset or bounds.Flutter should consider introducing a similar widget to
CompositedTransformFollower
that facilitates such decisions.The following is a jumping off point to design such a widget.
There may be a challenge in the timing of this solution. The standard Flutter order of operations is:
If the compositor is the only part that knows about a change to the target's position, then it's unclear how the follower can rebuild.
That said, any overlay widget associated with a piece of content will want to follow that content around, without concern for what moves that content, but with consideration for screen boundaries. Flutter should make this use-case easier for developers, and should provide a generic approach.
Beta Was this translation helpful? Give feedback.
All reactions