Commit 6669aafa authored by Jason Simmons's avatar Jason Simmons

Merge pull request #1759 from jason-simmons/edit_text_keyboard_flicker

Hide the keyboard in a deferred task.
parents 375f3247 6c98721d
......@@ -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);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment