[web] Fix inability to type in text fields in iOS (flutter/engine#27563)
This commit is contained in:
@@ -1133,13 +1133,23 @@ class IOSTextEditingStrategy extends GloballyPositionedTextEditingStrategy {
|
||||
|
||||
_addTapListener();
|
||||
|
||||
// On iOS, blur is trigerred if the virtual keyboard is closed or the
|
||||
// browser is sent to background or the browser tab is changed.
|
||||
// On iOS, blur is trigerred in the following cases:
|
||||
//
|
||||
// Since in all these cases, the connection needs to be closed,
|
||||
// [domRenderer.windowHasFocus] is not checked in [IOSTextEditingStrategy].
|
||||
// 1. The browser app is sent to the background (or the tab is changed). In
|
||||
// this case, the window loses focus (see [domRenderer.windowHasFocus]),
|
||||
// so we close the input connection with the framework.
|
||||
// 2. The user taps on another focusable element. In this case, we refocus
|
||||
// the input field and wait for the framework to manage the focus change.
|
||||
// 3. The virtual keyboard is closed by tapping "done". We can't detect this
|
||||
// programmatically, so we end up refocusing the input field. This is
|
||||
// okay because the virtual keyboard will hide, and as soon as the user
|
||||
// taps the text field again, the virtual keyboard will come up.
|
||||
subscriptions.add(activeDomElement.onBlur.listen((_) {
|
||||
owner.sendTextConnectionClosedToFrameworkIfAny();
|
||||
if (domRenderer.windowHasFocus) {
|
||||
activeDomElement.focus();
|
||||
} else {
|
||||
owner.sendTextConnectionClosedToFrameworkIfAny();
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
@@ -584,24 +584,12 @@ void testMain() {
|
||||
// DOM element is blurred.
|
||||
textEditing!.strategy.domElement!.blur();
|
||||
|
||||
// For ios-safari the connection is closed.
|
||||
if (browserEngine == BrowserEngine.webkit &&
|
||||
operatingSystem == OperatingSystem.iOs) {
|
||||
expect(spy.messages, hasLength(1));
|
||||
expect(spy.messages[0].channel, 'flutter/textinput');
|
||||
expect(
|
||||
spy.messages[0].methodName, 'TextInputClient.onConnectionClosed');
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
// DOM element loses the focus.
|
||||
expect(defaultTextEditingRoot.activeElement, null);
|
||||
} else {
|
||||
// No connection close message sent.
|
||||
expect(spy.messages, hasLength(0));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
// DOM element still keeps the focus.
|
||||
expect(defaultTextEditingRoot.activeElement,
|
||||
textEditing!.strategy.domElement);
|
||||
}
|
||||
// No connection close message sent.
|
||||
expect(spy.messages, hasLength(0));
|
||||
await Future<void>.delayed(Duration.zero);
|
||||
// DOM element still keeps the focus.
|
||||
expect(defaultTextEditingRoot.activeElement,
|
||||
textEditing!.strategy.domElement);
|
||||
},
|
||||
// TODO(nurhan): https://github.com/flutter/flutter/issues/50769
|
||||
skip: browserEngine == BrowserEngine.edge);
|
||||
|
||||
Reference in New Issue
Block a user