-
Notifications
You must be signed in to change notification settings - Fork 245
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
[SuperTextField][Android] Fix drag handle jumping when adding text at the end (Resolves #1114) #1124
[SuperTextField][Android] Fix drag handle jumping when adding text at the end (Resolves #1114) #1124
Conversation
bool get _shouldShowCollapsedHandle => | ||
widget.editingController.textController.selection.isCollapsed && !_isDraggingBase && !_isDraggingExtent; | ||
|
||
/// Holds the offset in text layout space where the collapsed drag handle is displayed. |
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.
Did you test to see if any similar positioning issues occur with expanded handles?
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 didn't notice issues like this with expanded handles.
/// Update the offset for the collapsed handle and call `setState`. | ||
/// | ||
/// Re-schedules the update if we can't compute compute the offset at the current frame. | ||
void _updateOffsetForCollapsedHandleAndRebuild() { |
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 looks nearly identical to the other method.
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.
Yeah, this is nearly identical. The only difference is that one method directly assignes the value because it is called in the build phase and the other calls setState.
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.
So we should de-duplicate it.
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.
After reviewing and testing again, it seems we don't need two methods. We aren't calling this from the build phase.
Updated.
a9efa9e
to
b338d05
Compare
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.
LGTM
[SuperTextField][Android] Fix drag handle jumping when adding text at the end. Resolves #1114
When the text field is center-aligned, typing at the end of the text field causes the drag handle to "flash" at the center of the text field before being displayed at the correct position:
2023-05-09.19-56-12.mp4
The cause seems to be a timing issue. We are computing the drag handle offset during build and it seems we are requesting the caret offset while the text layout isn't updated with the new text.
This PR changes the
AndroidEditingOverlayControls
to compute and cache the caret offset in a post-frame callback after the text/selection changes.After the changes:
2023-05-09.20-00-09.mp4
Unfortunately, I couldn't write a test for it. We don't seem to have the same timing issues in the widget tests.