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

Side by Side Diff: sky/framework/editing/editable_text.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/scrollable.dart ('k') | sky/framework/fn.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 '../fn.dart'; 5 import '../fn.dart';
6 import '../theme/colors.dart'; 6 import '../theme/colors.dart';
7 import 'dart:async'; 7 import 'dart:async';
8 import 'editable_string.dart'; 8 import 'editable_string.dart';
9 9
10 class EditableText extends Component { 10 class EditableText extends Component {
(...skipping 14 matching lines...) Expand all
25 text-decoration: underline;''' 25 text-decoration: underline;'''
26 ); 26 );
27 27
28 EditableString value; 28 EditableString value;
29 bool focused; 29 bool focused;
30 Timer _cursorTimer; 30 Timer _cursorTimer;
31 bool _showCursor = false; 31 bool _showCursor = false;
32 32
33 EditableText({Object key, this.value, this.focused}) 33 EditableText({Object key, this.value, this.focused})
34 : super(key: key, stateful: true) { 34 : super(key: key, stateful: true) {
35 onDidUnmount(() {
36 if (_cursorTimer != null)
37 _stopCursorTimer();
38 });
35 } 39 }
36 40
37 void _cursorTick(Timer timer) { 41 void _cursorTick(Timer timer) {
38 setState(() { 42 setState(() {
39 _showCursor = !_showCursor; 43 _showCursor = !_showCursor;
40 }); 44 });
41 } 45 }
42 46
43 void _startCursorTimer() { 47 void _startCursorTimer() {
44 _showCursor = true; 48 _showCursor = true;
45 _cursorTimer = new Timer.periodic( 49 _cursorTimer = new Timer.periodic(
46 new Duration(milliseconds: 500), _cursorTick); 50 new Duration(milliseconds: 500), _cursorTick);
47 } 51 }
48 52
49 void _stopCursorTimer() { 53 void _stopCursorTimer() {
50 _cursorTimer.cancel(); 54 _cursorTimer.cancel();
51 _cursorTimer = null; 55 _cursorTimer = null;
52 _showCursor = false; 56 _showCursor = false;
53 } 57 }
54 58
55 void didUnmount() {
56 if (_cursorTimer != null)
57 _stopCursorTimer();
58 }
59
60 Node build() { 59 Node build() {
61 if (focused && _cursorTimer == null) 60 if (focused && _cursorTimer == null)
62 _startCursorTimer(); 61 _startCursorTimer();
63 else if (!focused && _cursorTimer != null) 62 else if (!focused && _cursorTimer != null)
64 _stopCursorTimer(); 63 _stopCursorTimer();
65 64
66 List<Node> children = new List<Node>(); 65 List<Node> children = new List<Node>();
67 66
68 if (!value.composing.isValid) { 67 if (!value.composing.isValid) {
69 children.add(new Text(value.text)); 68 children.add(new Text(value.text));
(...skipping 18 matching lines...) Expand all
88 87
89 if (_showCursor) 88 if (_showCursor)
90 children.add(new Container(key: 'cursor', style: _cusorStyle)); 89 children.add(new Container(key: 'cursor', style: _cusorStyle));
91 90
92 return new Container( 91 return new Container(
93 style: _style, 92 style: _style,
94 children: children 93 children: children
95 ); 94 );
96 } 95 }
97 } 96 }
OLDNEW
« no previous file with comments | « sky/framework/components/scrollable.dart ('k') | sky/framework/fn.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698