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

Side by Side Diff: sky/sdk/lib/editing/input.dart

Issue 1234963002: Start an AddressBook example (to test text fields) (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 5 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
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 'package:sky/editing/editable_string.dart'; 5 import 'package:sky/editing/editable_string.dart';
6 import 'package:sky/editing/editable_text.dart'; 6 import 'package:sky/editing/editable_text.dart';
7 import 'package:sky/mojo/keyboard.dart'; 7 import 'package:sky/mojo/keyboard.dart';
8 import 'package:sky/painting/text_style.dart'; 8 import 'package:sky/painting/text_style.dart';
9 import 'package:sky/widgets/basic.dart'; 9 import 'package:sky/widgets/basic.dart';
10 import 'package:sky/widgets/theme.dart'; 10 import 'package:sky/widgets/theme.dart';
11 11
12 typedef void ValueChanged(value); 12 typedef void ValueChanged(value);
13 13
14 const double _kHintOpacity = 0.26; 14 // TODO(eseidel): This isn't right, it's 16px on the bottom:
15 // http://www.google.com/design/spec/components/text-fields.html#text-fields-sin gle-line-text-field
15 const EdgeDims _kTextfieldPadding = const EdgeDims.symmetric(vertical: 8.0); 16 const EdgeDims _kTextfieldPadding = const EdgeDims.symmetric(vertical: 8.0);
16 17
17 class Input extends StatefulComponent { 18 class Input extends StatefulComponent {
18 19
20 // Current thinking is that Widget will have an optional globalKey
21 // or heroKey and it will ask Focus.from(this).isFocused which will
22 // check using its globalKey.
23 // Only one element can use a globalKey at a time and its' up to
24 // Widget.sync to maintain the mapping.
25 // Never makes sense to have both a localKey and a globalKey.
26 // Possibly a class HeroKey who functions as a UUID.
27
19 Input({String key, 28 Input({String key,
20 this.placeholder, 29 this.placeholder,
21 this.onChanged, 30 this.onChanged,
22 this.focused}) 31 this.focused})
23 : super(key: key); 32 : super(key: key);
24 33
25 String placeholder; 34 String placeholder;
26 ValueChanged onChanged; 35 ValueChanged onChanged;
27 bool focused = false; 36 bool focused = false;
28 37
(...skipping 18 matching lines...) Expand all
47 void _handleTextUpdated() { 56 void _handleTextUpdated() {
48 scheduleBuild(); 57 scheduleBuild();
49 if (_value != _editableValue.text) { 58 if (_value != _editableValue.text) {
50 _value = _editableValue.text; 59 _value = _editableValue.text;
51 if (onChanged != null) 60 if (onChanged != null)
52 onChanged(_value); 61 onChanged(_value);
53 } 62 }
54 } 63 }
55 64
56 Widget build() { 65 Widget build() {
66 ThemeData themeData = Theme.of(this);
67
57 if (focused && !_isAttachedToKeyboard) { 68 if (focused && !_isAttachedToKeyboard) {
58 keyboard.show(_editableValue.stub); 69 keyboard.show(_editableValue.stub);
59 _isAttachedToKeyboard = true; 70 _isAttachedToKeyboard = true;
60 } 71 }
61 72
62 TextStyle textStyle = Theme.of(this).text.subhead; 73 TextStyle textStyle = themeData.text.subhead;
63 List<Widget> textChildren = <Widget>[]; 74 List<Widget> textChildren = <Widget>[];
64 75
65 if (placeholder != null && _value.isEmpty) { 76 if (placeholder != null && _value.isEmpty) {
66 Widget child = new Opacity( 77 Widget child = new Opacity(
67 key: "placeholder", 78 key: "placeholder",
68 child: new Text(placeholder, style: textStyle), 79 child: new Text(placeholder, style: textStyle),
69 opacity: _kHintOpacity 80 opacity: themeData.hintOpacity
70 ); 81 );
71 textChildren.add(child); 82 textChildren.add(child);
72 } 83 }
73 84
74 ThemeData themeData = Theme.of(this);
75 Color focusHighlightColor = themeData.accentColor; 85 Color focusHighlightColor = themeData.accentColor;
76 Color cursorColor = themeData.accentColor; 86 Color cursorColor = themeData.accentColor;
77 if (themeData.primarySwatch != null) { 87 if (themeData.primarySwatch != null) {
78 cursorColor = Theme.of(this).primarySwatch[200]; 88 cursorColor = themeData.primarySwatch[200];
79 focusHighlightColor = focused ? themeData.primarySwatch[400] : themeData.p rimarySwatch[200]; 89 focusHighlightColor = focused ? themeData.primarySwatch[400] : themeData.h intColor;
80 } 90 }
81 91
82 textChildren.add(new EditableText( 92 textChildren.add(new EditableText(
83 value: _editableValue, 93 value: _editableValue,
84 focused: focused, 94 focused: focused,
85 style: textStyle, 95 style: textStyle,
86 cursorColor: cursorColor 96 cursorColor: cursorColor
87 )); 97 ));
88 98
89 Border focusHighlight = new Border(bottom: new BorderSide( 99 Border focusHighlight = new Border(bottom: new BorderSide(
(...skipping 12 matching lines...) Expand all
102 onPointerDown: (_) => keyboard.showByRequest() 112 onPointerDown: (_) => keyboard.showByRequest()
103 ); 113 );
104 } 114 }
105 115
106 void didUnmount() { 116 void didUnmount() {
107 if (_isAttachedToKeyboard) 117 if (_isAttachedToKeyboard)
108 keyboard.hide(); 118 keyboard.hide();
109 super.didUnmount(); 119 super.didUnmount();
110 } 120 }
111 } 121 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698