Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(41)

Side by Side Diff: sky/framework/components/input.dart

Issue 1027633003: [Effen] Add AnimatedComponent base class (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: cr changes Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sky/framework/components/ink_well.dart ('k') | sky/framework/components/popup_menu.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 '../editing/editable_string.dart'; 5 import '../editing/editable_string.dart';
6 import '../editing/editable_text.dart'; 6 import '../editing/editable_text.dart';
7 import '../editing/keyboard.dart'; 7 import '../editing/keyboard.dart';
8 import '../fn.dart'; 8 import '../fn.dart';
9 import '../theme/colors.dart'; 9 import '../theme/colors.dart';
10 10
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 bool _isAttachedToKeyboard = false; 42 bool _isAttachedToKeyboard = false;
43 EditableString _editableValue; 43 EditableString _editableValue;
44 44
45 Input({Object key, 45 Input({Object key,
46 this.placeholder, 46 this.placeholder,
47 this.onChanged, 47 this.onChanged,
48 this.focused}) 48 this.focused})
49 : super(key: key, stateful: true) { 49 : super(key: key, stateful: true) {
50 _editableValue = new EditableString(text: _value, 50 _editableValue = new EditableString(text: _value,
51 onUpdated: _handleTextUpdated); 51 onUpdated: _handleTextUpdated);
52 onDidUnmount(() {
53 if (_isAttachedToKeyboard)
54 keyboard.hide();
55 });
52 } 56 }
53 57
54 void _handleTextUpdated() { 58 void _handleTextUpdated() {
55 scheduleBuild(); 59 scheduleBuild();
56 if (_value != _editableValue.text) { 60 if (_value != _editableValue.text) {
57 _value = _editableValue.text; 61 _value = _editableValue.text;
58 if (onChanged != null) 62 if (onChanged != null)
59 onChanged(_value); 63 onChanged(_value);
60 } 64 }
61 } 65 }
62 66
63 void didUnmount() {
64 if (_isAttachedToKeyboard)
65 keyboard.hide();
66 }
67
68 Node build() { 67 Node build() {
69 if (focused && !_isAttachedToKeyboard) { 68 if (focused && !_isAttachedToKeyboard) {
70 keyboard.show(_editableValue.stub); 69 keyboard.show(_editableValue.stub);
71 _isAttachedToKeyboard = true; 70 _isAttachedToKeyboard = true;
72 } 71 }
73 72
74 List<Node> children = []; 73 List<Node> children = [];
75 74
76 if (placeholder != null && _value.isEmpty) { 75 if (placeholder != null && _value.isEmpty) {
77 children.add(new Container( 76 children.add(new Container(
78 style: _placeholderStyle, 77 style: _placeholderStyle,
79 children: [new Text(placeholder)] 78 children: [new Text(placeholder)]
80 )); 79 ));
81 } 80 }
82 81
83 children.add(new EditableText(value: _editableValue, focused: focused)); 82 children.add(new EditableText(value: _editableValue, focused: focused));
84 83
85 return new Container( 84 return new Container(
86 style: _style, 85 style: _style,
87 inlineStyle: focused ? _focusedInlineStyle : null, 86 inlineStyle: focused ? _focusedInlineStyle : null,
88 children: children 87 children: children
89 ); 88 );
90 } 89 }
91 } 90 }
OLDNEW
« no previous file with comments | « sky/framework/components/ink_well.dart ('k') | sky/framework/components/popup_menu.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698