Commit 2ba96877 authored by Adam Barth's avatar Adam Barth

Input asserts while keyboard is dismissed

Now we recreate the stub every time we try to connect to the keyboard. The
underlying message pipe in the stub cannot be re-used, which is why we
previously asserted.

Fixes #776
parent dc7451d6
...@@ -80,7 +80,7 @@ const Curve _kTransitionCurve = Curves.ease; ...@@ -80,7 +80,7 @@ const Curve _kTransitionCurve = Curves.ease;
class _InputState extends State<Input> { class _InputState extends State<Input> {
String _value; String _value;
EditableString _editableString; EditableString _editableString;
KeyboardHandle _keyboardHandle = KeyboardHandle.unattached; KeyboardHandle _keyboardHandle;
// Used by tests. // Used by tests.
EditableString get editableValue => _editableString; EditableString get editableValue => _editableString;
...@@ -96,19 +96,22 @@ class _InputState extends State<Input> { ...@@ -96,19 +96,22 @@ class _InputState extends State<Input> {
} }
void dispose() { void dispose() {
if (_keyboardHandle.attached) if (_isAttachedToKeyboard)
_keyboardHandle.release(); _keyboardHandle.release();
super.dispose(); super.dispose();
} }
bool get _isAttachedToKeyboard => _keyboardHandle != null && _keyboardHandle.attached;
void _attachOrDetachKeyboard(bool focused) { void _attachOrDetachKeyboard(bool focused) {
if (focused && !_keyboardHandle.attached) { if (focused && !_isAttachedToKeyboard) {
_keyboardHandle = keyboard.show(_editableString.stub, config.keyboardType); _keyboardHandle = keyboard.show(_editableString.createStub(), config.keyboardType);
_keyboardHandle.setText(_editableString.text); _keyboardHandle.setText(_editableString.text);
_keyboardHandle.setSelection(_editableString.selection.start, _keyboardHandle.setSelection(_editableString.selection.start,
_editableString.selection.end); _editableString.selection.end);
} else if (!focused && _keyboardHandle.attached) { } else if (!focused && _isAttachedToKeyboard) {
_keyboardHandle.release(); _keyboardHandle.release();
_keyboardHandle = null;
_editableString.didDetachKeyboard(); _editableString.didDetachKeyboard();
} }
} }
...@@ -251,7 +254,7 @@ class _InputState extends State<Input> { ...@@ -251,7 +254,7 @@ class _InputState extends State<Input> {
behavior: HitTestBehavior.opaque, behavior: HitTestBehavior.opaque,
onTap: () { onTap: () {
if (Focus.at(context)) { if (Focus.at(context)) {
assert(_keyboardHandle.attached); assert(_isAttachedToKeyboard);
_keyboardHandle.showByRequest(); _keyboardHandle.showByRequest();
} else { } else {
Focus.moveTo(config.key); Focus.moveTo(config.key);
......
...@@ -10,19 +10,6 @@ import 'shell.dart'; ...@@ -10,19 +10,6 @@ import 'shell.dart';
export 'package:mojo_services/keyboard/keyboard.mojom.dart'; export 'package:mojo_services/keyboard/keyboard.mojom.dart';
class _KeyboardConnection {
_KeyboardConnection() {
proxy = new KeyboardServiceProxy.unbound();
shell.connectToService(null, proxy);
}
KeyboardServiceProxy proxy;
KeyboardService get keyboardService => proxy.ptr;
static final _KeyboardConnection instance = new _KeyboardConnection();
}
/// An interface to the system's keyboard. /// An interface to the system's keyboard.
/// ///
/// Most clients will want to use the [keyboard] singleton instance. /// Most clients will want to use the [keyboard] singleton instance.
...@@ -40,11 +27,8 @@ class Keyboard { ...@@ -40,11 +27,8 @@ class Keyboard {
KeyboardHandle show(KeyboardClientStub stub, KeyboardType keyboardType) { KeyboardHandle show(KeyboardClientStub stub, KeyboardType keyboardType) {
assert(stub != null); assert(stub != null);
if (_currentHandle != null) { _currentHandle?.release();
if (_currentHandle.stub == stub) assert(_currentHandle == null);
return _currentHandle;
_currentHandle.release();
}
_currentHandle = new KeyboardHandle._show(this, stub, keyboardType); _currentHandle = new KeyboardHandle._show(this, stub, keyboardType);
return _currentHandle; return _currentHandle;
} }
...@@ -67,16 +51,12 @@ class Keyboard { ...@@ -67,16 +51,12 @@ class Keyboard {
class KeyboardHandle { class KeyboardHandle {
KeyboardHandle._show(Keyboard keyboard, this.stub, KeyboardType keyboardType) : _keyboard = keyboard { KeyboardHandle._show(Keyboard keyboard, KeyboardClientStub stub, KeyboardType keyboardType) : _keyboard = keyboard {
_keyboard.service.show(stub, keyboardType); _keyboard.service.show(stub, keyboardType);
_attached = true; _attached = true;
} }
KeyboardHandle._unattached(Keyboard keyboard) : _keyboard = keyboard, stub = null, _attached = false;
static final unattached = new KeyboardHandle._unattached(keyboard);
final Keyboard _keyboard; final Keyboard _keyboard;
final KeyboardClientStub stub;
bool _attached; bool _attached;
bool get attached => _attached; bool get attached => _attached;
...@@ -111,4 +91,11 @@ class KeyboardHandle { ...@@ -111,4 +91,11 @@ class KeyboardHandle {
} }
final Keyboard keyboard = new Keyboard(_KeyboardConnection.instance.keyboardService); KeyboardServiceProxy _initKeyboardProxy() {
KeyboardServiceProxy proxy = new KeyboardServiceProxy.unbound();
shell.connectToService(null, proxy);
return proxy;
}
final KeyboardServiceProxy _keyboardProxy = _initKeyboardProxy();
final Keyboard keyboard = new Keyboard(_keyboardProxy.ptr);
...@@ -64,7 +64,6 @@ class _KeyboardClientImpl implements KeyboardClient { ...@@ -64,7 +64,6 @@ class _KeyboardClientImpl implements KeyboardClient {
}) { }) {
assert(onUpdated != null); assert(onUpdated != null);
assert(onSubmitted != null); assert(onSubmitted != null);
stub = new KeyboardClientStub.unbound()..impl = this;
selection = new TextRange(start: text.length, end: text.length); selection = new TextRange(start: text.length, end: text.length);
} }
...@@ -84,7 +83,9 @@ class _KeyboardClientImpl implements KeyboardClient { ...@@ -84,7 +83,9 @@ class _KeyboardClientImpl implements KeyboardClient {
TextRange selection = TextRange.empty; TextRange selection = TextRange.empty;
/// A keyboard client stub that can be attached to a keyboard service. /// A keyboard client stub that can be attached to a keyboard service.
KeyboardClientStub stub; KeyboardClientStub createStub() {
return new KeyboardClientStub.unbound()..impl = this;
}
void _delete(TextRange range) { void _delete(TextRange range) {
if (range.isCollapsed || !range.isValid) return; if (range.isCollapsed || !range.isValid) return;
...@@ -196,7 +197,7 @@ class EditableString { ...@@ -196,7 +197,7 @@ class EditableString {
/// A keyboard client stub that can be attached to a keyboard service. /// A keyboard client stub that can be attached to a keyboard service.
/// ///
/// See [Keyboard]. /// See [Keyboard].
KeyboardClientStub get stub => _client.stub; KeyboardClientStub createStub() => _client.createStub();
void didDetachKeyboard() { void didDetachKeyboard() {
_client.composing = TextRange.empty; _client.composing = TextRange.empty;
......
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