-
Notifications
You must be signed in to change notification settings - Fork 270
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
Keyboard can pop up on returning from lightbox or internal link #1100
Comments
I think there are basically two strategies for solving this:
The second strategy is what Discord does. (I don't know if they've found a clean way to do it or are using that crude hack.)
The first strategy is what Facebook Messenger does and what Slack does.
|
This looks like flutter/flutter#94249. We linked to this issue back in #552 (comment), but I think the bug applies here better. |
My theory is that a
then, the void _handleFocusChanged() {
_openOrCloseInputConnectionIfNeeded();
_startOrStopCursorTimerIfNeeded();
_updateOrDisposeSelectionOverlayIfNeeded();
if (_hasFocus) {
// Listen for changing viewInsets, which indicates keyboard showing up.
WidgetsBinding.instance.addObserver(this);
_lastBottomViewInset = View.of(context).viewInsets.bottom;
if (!widget.readOnly) {
_scheduleShowCaretOnScreen(withAnimation: true);
}
final TextSelection? updatedSelection = _adjustedSelectionWhenFocused();
if (updatedSelection != null) {
_handleSelectionChanged(updatedSelection, null);
}
} else {
WidgetsBinding.instance.removeObserver(this);
setState(() {
_currentPromptRectRange = null;
});
}
updateKeepAlive();
} I believe that the input connection is relevant to the keyboard being shown by looking at /// Express interest in interacting with the keyboard.
///
/// If this control is already attached to the keyboard, this function will
/// request that the keyboard become visible. Otherwise, this function will
/// ask the focus system that it become focused. If successful in acquiring
/// focus, the control will then attach to the keyboard and request that the
/// keyboard become visible.
void requestKeyboard() {
if (_hasFocus) {
_openInputConnection();
} else {
_flagInternalFocus();
widget.focusNode
.requestFocus(); // This eventually calls _openInputConnection also, see _handleFocusChanged.
}
} Because the focus on the We could borrow @override
void didChangeMetrics() {
if (!mounted) {
return;
}
final ui.FlutterView view = View.of(context);
if (_lastBottomViewInset != view.viewInsets.bottom) {
SchedulerBinding.instance.addPostFrameCallback((Duration _) {
_selectionOverlay?.updateForScroll();
}, debugLabel: 'EditableText.updateForScroll');
if (_lastBottomViewInset < view.viewInsets.bottom) {
// Because the metrics change signal from engine will come here every frame
// (on both iOS and Android). So we don't need to show caret with animation.
_scheduleShowCaretOnScreen(withAnimation: false);
}
}
_lastBottomViewInset = view.viewInsets.bottom;
} |
This all seem to be a side-effect of how focus is retained after navigating away, and how It's not certain that the behavior of unfocusing is correct either, as sometimes the keyboard can be hidden while the input connection is still needed (flutter/flutter#142930 (comment), flutter/flutter#148475 (comment)). |
That's exactly what happens. I forgot to put a link to the related CZO discussion in here. There's a complete method call stack on how it happens and a solution for the bug, which involves creating an upstream PR. There's also another possibility for the problem to be solved which I will test in these days. |
Repro:
This is a variant of #1097, and I assume it has the same root cause: after dismissing the keyboard in step 3 above, the text field is still focused. When it occurs, this symptom is much more obtrusive and annoying.
I learned about this symptom the other day from a longtime Zulip user who was trying out the Flutter beta app; he ran into this within the first few minutes.
The text was updated successfully, but these errors were encountered: