Commit 6c98721d authored by Jason Simmons's avatar Jason Simmons

Hide the keyboard in a deferred task.

This is intended to eliminate the flicker that occurs when one widget hides
the keyboard and then another shows it within the same update cycle.
parent 315d77a9
......@@ -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