Merge pull request #1759 from jason-simmons/edit_text_keyboard_flicker
Hide the keyboard in a deferred task.
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:mojo_services/keyboard/keyboard.mojom.dart';
|
||||
|
||||
import 'shell.dart';
|
||||
@@ -32,6 +34,8 @@ class Keyboard {
|
||||
|
||||
KeyboardHandle _currentHandle;
|
||||
|
||||
bool _hidePending = false;
|
||||
|
||||
KeyboardHandle show(KeyboardClientStub stub, KeyboardType keyboardType) {
|
||||
assert(stub != null);
|
||||
if (_currentHandle != null) {
|
||||
@@ -43,6 +47,20 @@ class Keyboard {
|
||||
return _currentHandle;
|
||||
}
|
||||
|
||||
void _scheduleHide() {
|
||||
if (_hidePending) return;
|
||||
_hidePending = true;
|
||||
|
||||
// Schedule a deferred task that hides the keyboard. If someone else shows
|
||||
// the keyboard during this update cycle, then the task will do nothing.
|
||||
scheduleMicrotask(() {
|
||||
_hidePending = false;
|
||||
if (_currentHandle == null) {
|
||||
service.hide();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class KeyboardHandle {
|
||||
@@ -70,9 +88,9 @@ class KeyboardHandle {
|
||||
void release() {
|
||||
if (_attached) {
|
||||
assert(_keyboard._currentHandle == this);
|
||||
_keyboard.service.hide();
|
||||
_attached = false;
|
||||
_keyboard._currentHandle = null;
|
||||
_keyboard._scheduleHide();
|
||||
}
|
||||
assert(_keyboard._currentHandle != this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user