| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 import '../editing2/editable_string.dart'; | |
| 6 import '../editing2/editable_text.dart'; | |
| 7 import '../editing2/keyboard.dart'; | |
| 8 import '../fn2.dart'; | |
| 9 import '../theme2/colors.dart'; | |
| 10 import '../theme2/typography.dart' as typography; | |
| 11 import '../rendering/flex.dart'; | |
| 12 import 'dart:sky' as sky; | |
| 13 | |
| 14 typedef void ValueChanged(value); | |
| 15 | |
| 16 class Input extends Component { | |
| 17 | |
| 18 Input({Object key, | |
| 19 this.placeholder, | |
| 20 this.onChanged, | |
| 21 this.focused}) | |
| 22 : super(key: key, stateful: true) { | |
| 23 _editableValue = new EditableString( | |
| 24 text: _value, | |
| 25 onUpdated: _handleTextUpdated | |
| 26 ); | |
| 27 } | |
| 28 | |
| 29 // static final Style _style = new Style(''' | |
| 30 // transform: translateX(0); | |
| 31 // margin: 8px; | |
| 32 // padding: 8px; | |
| 33 // border-bottom: 1px solid ${Grey[200]}; | |
| 34 // align-self: center; | |
| 35 // height: 1.2em; | |
| 36 // white-space: pre; | |
| 37 // overflow: hidden;''' | |
| 38 // ); | |
| 39 | |
| 40 // static final Style _placeholderStyle = new Style(''' | |
| 41 // top: 8px; | |
| 42 // left: 8px; | |
| 43 // position: absolute; | |
| 44 // ${typography.black.caption};''' | |
| 45 // ); | |
| 46 | |
| 47 // static final String _focusedInlineStyle = ''' | |
| 48 // padding: 7px; | |
| 49 // border-bottom: 2px solid ${Blue[500]};'''; | |
| 50 | |
| 51 String placeholder; | |
| 52 ValueChanged onChanged; | |
| 53 bool focused = false; | |
| 54 | |
| 55 void syncFields(Input source) { | |
| 56 placeholder = source.placeholder; | |
| 57 onChanged = source.onChanged; | |
| 58 focused = source.focused; | |
| 59 } | |
| 60 | |
| 61 String _value = ''; | |
| 62 bool _isAttachedToKeyboard = false; | |
| 63 EditableString _editableValue; | |
| 64 | |
| 65 void _handleTextUpdated() { | |
| 66 scheduleBuild(); | |
| 67 if (_value != _editableValue.text) { | |
| 68 _value = _editableValue.text; | |
| 69 if (onChanged != null) | |
| 70 onChanged(_value); | |
| 71 } | |
| 72 } | |
| 73 | |
| 74 UINode build() { | |
| 75 if (focused && !_isAttachedToKeyboard) { | |
| 76 keyboard.show(_editableValue.stub); | |
| 77 _isAttachedToKeyboard = true; | |
| 78 } | |
| 79 | |
| 80 List<UINode> children = []; | |
| 81 | |
| 82 if (placeholder != null && _value.isEmpty) { | |
| 83 children.add(new Container( | |
| 84 // style: _placeholderStyle, | |
| 85 child: new Text(placeholder) | |
| 86 )); | |
| 87 } | |
| 88 | |
| 89 children.add(new EditableText(value: _editableValue, focused: focused)); | |
| 90 | |
| 91 return new EventListenerNode( | |
| 92 // style: _style, | |
| 93 // inlineStyle: focused ? _focusedInlineStyle : null, | |
| 94 new Flex(children, direction: FlexDirection.vertical), | |
| 95 onPointerDown: (sky.Event e) => keyboard.showByRequest() | |
| 96 ); | |
| 97 } | |
| 98 | |
| 99 void didUnmount() { | |
| 100 if (_isAttachedToKeyboard) | |
| 101 keyboard.hide(); | |
| 102 super.didUnmount(); | |
| 103 } | |
| 104 | |
| 105 } | |
| OLD | NEW |