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

Side by Side Diff: sky/sdk/lib/widgets/widget.dart

Issue 1233703003: add initState, rename animated_container (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: remove print statement 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 'dart:async'; 5 import 'dart:async';
6 import 'dart:collection'; 6 import 'dart:collection';
7 import 'dart:sky' as sky; 7 import 'dart:sky' as sky;
8 8
9 import 'package:sky/mojo/activity.dart' as activity; 9 import 'package:sky/mojo/activity.dart' as activity;
10 10
(...skipping 503 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 514
515 Widget build(); 515 Widget build();
516 516
517 } 517 }
518 518
519 abstract class StatefulComponent extends Component { 519 abstract class StatefulComponent extends Component {
520 520
521 StatefulComponent({ String key }) : super(key: key); 521 StatefulComponent({ String key }) : super(key: key);
522 522
523 bool _disqualifiedFromEverAppearingAgain = false; 523 bool _disqualifiedFromEverAppearingAgain = false;
524 bool _isStateInitialized = false;
524 525
525 void didMount() { 526 void didMount() {
526 assert(!_disqualifiedFromEverAppearingAgain); 527 assert(!_disqualifiedFromEverAppearingAgain);
527 super.didMount(); 528 super.didMount();
528 } 529 }
529 530
530 void _buildIfDirty() { 531 void _buildIfDirty() {
531 assert(!_disqualifiedFromEverAppearingAgain); 532 assert(!_disqualifiedFromEverAppearingAgain);
532 super._buildIfDirty(); 533 super._buildIfDirty();
533 } 534 }
534 535
535 void _sync(Widget old, dynamic slot) { 536 void _sync(Widget old, dynamic slot) {
536 assert(!_disqualifiedFromEverAppearingAgain); 537 assert(!_disqualifiedFromEverAppearingAgain);
538 // TODO(ianh): _sync should only be called once when old == null
539 if (old == null && !_isStateInitialized) {
540 initState();
541 _isStateInitialized = true;
542 }
537 super._sync(old, slot); 543 super._sync(old, slot);
538 } 544 }
539 545
540 Widget syncChild(Widget node, Widget oldNode, dynamic slot) { 546 Widget syncChild(Widget node, Widget oldNode, dynamic slot) {
541 assert(!_disqualifiedFromEverAppearingAgain); 547 assert(!_disqualifiedFromEverAppearingAgain);
542 return super.syncChild(node, oldNode, slot); 548 return super.syncChild(node, oldNode, slot);
543 } 549 }
544 550
545 bool retainStatefulNodeIfPossible(StatefulComponent newNode) { 551 bool retainStatefulNodeIfPossible(StatefulComponent newNode) {
546 assert(!_disqualifiedFromEverAppearingAgain); 552 assert(!_disqualifiedFromEverAppearingAgain);
(...skipping 13 matching lines...) Expand all
560 } 566 }
561 567
562 // This is called by retainStatefulNodeIfPossible(), during 568 // This is called by retainStatefulNodeIfPossible(), during
563 // syncChild(), just before _sync() is called. Derived 569 // syncChild(), just before _sync() is called. Derived
564 // classes should override this method to update `this` to 570 // classes should override this method to update `this` to
565 // account for the new values the parent passed to `source`. 571 // account for the new values the parent passed to `source`.
566 // Make sure to call super.syncFields(source) unless you are 572 // Make sure to call super.syncFields(source) unless you are
567 // extending StatefulComponent directly. 573 // extending StatefulComponent directly.
568 void syncFields(Component source); 574 void syncFields(Component source);
569 575
576 // Stateful components can override initState if they want
577 // to do non-trivial work to initialize state. This is
578 // always called before build().
579 void initState() { }
580
570 void setState(Function fn()) { 581 void setState(Function fn()) {
571 assert(!_disqualifiedFromEverAppearingAgain); 582 assert(!_disqualifiedFromEverAppearingAgain);
572 fn(); 583 fn();
573 scheduleBuild(); 584 scheduleBuild();
574 } 585 }
575 } 586 }
576 587
577 Set<Component> _dirtyComponents = new Set<Component>(); 588 Set<Component> _dirtyComponents = new Set<Component>();
578 bool _buildScheduled = false; 589 bool _buildScheduled = false;
579 bool _inRenderDirtyComponents = false; 590 bool _inRenderDirtyComponents = false;
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1130 if (root.parent == null) { 1141 if (root.parent == null) {
1131 // we haven't attached it yet 1142 // we haven't attached it yet
1132 assert(_container.child == null); 1143 assert(_container.child == null);
1133 _container.child = root; 1144 _container.child = root;
1134 } 1145 }
1135 assert(root.parent == _container); 1146 assert(root.parent == _container);
1136 } 1147 }
1137 1148
1138 Widget build() => builder(); 1149 Widget build() => builder();
1139 } 1150 }
OLDNEW
« sky/sdk/lib/widgets/material.dart ('K') | « sky/sdk/lib/widgets/scrollable.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698