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