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

Side by Side Diff: sky/sdk/lib/framework/components2/input.dart

Issue 1177243002: Refactor fn2.dart, since it breached our 1000-line threshold. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 5 years, 6 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
OLDNEW
(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 }
OLDNEW
« no previous file with comments | « sky/sdk/lib/framework/components2/ink_well.dart ('k') | sky/sdk/lib/framework/components2/material.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698