| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 import '../editing2/editable_string.dart'; | 5 import '../editing2/editable_string.dart'; |
| 6 import '../editing2/editable_text.dart'; | 6 import '../editing2/editable_text.dart'; |
| 7 import '../editing2/keyboard.dart'; | 7 import '../editing2/keyboard.dart'; |
| 8 import '../fn2.dart'; | 8 import '../fn2.dart'; |
| 9 import '../theme2/colors.dart'; | 9 import '../theme2/colors.dart'; |
| 10 import '../theme2/typography.dart' as typography; | 10 import '../theme2/typography.dart' as typography; |
| 11 import '../rendering/flex.dart'; | 11 import '../rendering/flex.dart'; |
| 12 import 'dart:sky' as sky; | 12 import 'dart:sky' as sky; |
| 13 | 13 |
| 14 typedef void ValueChanged(value); | 14 typedef void ValueChanged(value); |
| 15 | 15 |
| 16 class Input extends Component { | 16 class Input extends Component { |
| 17 | 17 |
| 18 Input({Object key, | 18 Input({Object key, |
| 19 this.placeholder, | 19 this.placeholder, |
| 20 this.onChanged, | 20 this.onChanged, |
| 21 this.focused}) | 21 this.focused}) |
| 22 : super(key: key, stateful: true) { | 22 : super(key: key, stateful: true) { |
| 23 _editableValue = new EditableString(text: _value, | 23 _editableValue = new EditableString( |
| 24 onUpdated: _handleTextUpdated); | 24 text: _value, |
| 25 onDidUnmount(() { | 25 onUpdated: _handleTextUpdated |
| 26 if (_isAttachedToKeyboard) | 26 ); |
| 27 keyboard.hide(); | |
| 28 }); | |
| 29 } | 27 } |
| 30 | 28 |
| 31 // static final Style _style = new Style(''' | 29 // static final Style _style = new Style(''' |
| 32 // transform: translateX(0); | 30 // transform: translateX(0); |
| 33 // margin: 8px; | 31 // margin: 8px; |
| 34 // padding: 8px; | 32 // padding: 8px; |
| 35 // border-bottom: 1px solid ${Grey[200]}; | 33 // border-bottom: 1px solid ${Grey[200]}; |
| 36 // align-self: center; | 34 // align-self: center; |
| 37 // height: 1.2em; | 35 // height: 1.2em; |
| 38 // white-space: pre; | 36 // white-space: pre; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 // border-bottom: 2px solid ${Blue[500]};'''; | 49 // border-bottom: 2px solid ${Blue[500]};'''; |
| 52 | 50 |
| 53 String placeholder; | 51 String placeholder; |
| 54 ValueChanged onChanged; | 52 ValueChanged onChanged; |
| 55 bool focused = false; | 53 bool focused = false; |
| 56 | 54 |
| 57 void syncFields(Input source) { | 55 void syncFields(Input source) { |
| 58 placeholder = source.placeholder; | 56 placeholder = source.placeholder; |
| 59 onChanged = source.onChanged; | 57 onChanged = source.onChanged; |
| 60 focused = source.focused; | 58 focused = source.focused; |
| 61 super.syncFields(source); | |
| 62 } | 59 } |
| 63 | 60 |
| 64 String _value = ''; | 61 String _value = ''; |
| 65 bool _isAttachedToKeyboard = false; | 62 bool _isAttachedToKeyboard = false; |
| 66 EditableString _editableValue; | 63 EditableString _editableValue; |
| 67 | 64 |
| 68 void _handleTextUpdated() { | 65 void _handleTextUpdated() { |
| 69 scheduleBuild(); | 66 scheduleBuild(); |
| 70 if (_value != _editableValue.text) { | 67 if (_value != _editableValue.text) { |
| 71 _value = _editableValue.text; | 68 _value = _editableValue.text; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 95 new FlexContainer( | 92 new FlexContainer( |
| 96 direction: FlexDirection.vertical, | 93 direction: FlexDirection.vertical, |
| 97 // style: _style, | 94 // style: _style, |
| 98 // inlineStyle: focused ? _focusedInlineStyle : null, | 95 // inlineStyle: focused ? _focusedInlineStyle : null, |
| 99 children: children | 96 children: children |
| 100 ), | 97 ), |
| 101 onPointerDown: (sky.Event e) => keyboard.showByRequest() | 98 onPointerDown: (sky.Event e) => keyboard.showByRequest() |
| 102 ); | 99 ); |
| 103 } | 100 } |
| 104 | 101 |
| 102 void didUnmount() { |
| 103 if (_isAttachedToKeyboard) |
| 104 keyboard.hide(); |
| 105 super.didUnmount(); |
| 106 } |
| 107 |
| 105 } | 108 } |
| OLD | NEW |