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

Side by Side Diff: samples/swarm/swarm_ui_lib/view/ConveyorView.dart

Issue 12259037: Reapply remove setTimeout, take 3. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 part of view; 5 part of view;
6 6
7 /** 7 /**
8 * Holds a number of child views. As you switch between views, the old 8 * Holds a number of child views. As you switch between views, the old
9 * view is pushed off to the side and the new view slides in from the other 9 * view is pushed off to the side and the new view slides in from the other
10 * side. 10 * side.
11 */ 11 */
12 class ConveyorView extends CompositeView { 12 class ConveyorView extends CompositeView {
13 // TODO(jmesserly): some places use this property to know when the slide 13 // TODO(jmesserly): some places use this property to know when the slide
14 // transition is finished. It would be better to have an event that fires 14 // transition is finished. It would be better to have an event that fires
15 // when we're done sliding 15 // when we're done sliding
16 static const ANIMATE_SECONDS = 0.25; 16 static const ANIMATE_SECONDS = 0.25;
17 17
18 View targetView; 18 View targetView;
19 // TODO(rnystrom): Should not be settable. 19 // TODO(rnystrom): Should not be settable.
20 View selectedView; 20 View selectedView;
21 // TODO(rnystrom): Hackish. Should use a real multicast event-like class. 21 // TODO(rnystrom): Hackish. Should use a real multicast event-like class.
22 // Or just have it depend on an Observable to select a view and indicate 22 // Or just have it depend on an Observable to select a view and indicate
23 // which view is selected? (e.g. the MVVM pattern) 23 // which view is selected? (e.g. the MVVM pattern)
24 Function viewSelected; 24 Function viewSelected;
25 25
26 int animationTimeoutId; 26 Timer animationTimer;
27 27
28 ConveyorView() 28 ConveyorView()
29 : super('conveyor-view', true), 29 : super('conveyor-view', true),
30 animationTimeoutId = null { 30 animationTimer = null {
31 } 31 }
32 32
33 Element render() { 33 Element render() {
34 final result = super.render(); 34 final result = super.render();
35 // TODO(rnystrom): Have to do this in render() because container doesn't 35 // TODO(rnystrom): Have to do this in render() because container doesn't
36 // exist before then. Hack. Should find a cleaner solution. One of: 36 // exist before then. Hack. Should find a cleaner solution. One of:
37 // - Add a ctor param to CompositeView for container class name. 37 // - Add a ctor param to CompositeView for container class name.
38 // - Make ConveyorView contain a CompositeView instead of subclass. 38 // - Make ConveyorView contain a CompositeView instead of subclass.
39 // - Add method to CompositeView to set class name. 39 // - Add method to CompositeView to set class name.
40 container.attributes['class'] = 'conveyor-view-container'; 40 container.attributes['class'] = 'conveyor-view-container';
(...skipping 13 matching lines...) Expand all
54 int index = getIndexOfSelectedView(); 54 int index = getIndexOfSelectedView();
55 final durationSeconds = animate ? ANIMATE_SECONDS : 0.0; 55 final durationSeconds = animate ? ANIMATE_SECONDS : 0.0;
56 56
57 final style = container.style; 57 final style = container.style;
58 // TODO(jacobr): modify setTransitionDuration so the input is always 58 // TODO(jacobr): modify setTransitionDuration so the input is always
59 // specified in miliseconds rather than accepting a string. 59 // specified in miliseconds rather than accepting a string.
60 style.transitionDuration = '${durationSeconds}s'; 60 style.transitionDuration = '${durationSeconds}s';
61 final xTranslationPercent = -index * 100; 61 final xTranslationPercent = -index * 100;
62 style.transform = 'translate3d(${xTranslationPercent}%, 0px, 0px)'; 62 style.transform = 'translate3d(${xTranslationPercent}%, 0px, 0px)';
63 63
64 if (animationTimeoutId != null) {
65 window.clearTimeout(animationTimeoutId);
66 }
67
68 if (animate) { 64 if (animate) {
69 animationTimeoutId = window.setTimeout( 65 animationTimer = new Timer(
70 () { _onAnimationEnd(); }, (durationSeconds * 1000).toInt()); 66 new Duration(milliseconds: ((durationSeconds * 1000).toInt())),
67 () { _onAnimationEnd(); });
71 } 68 }
72 // TODO(mattsh), we should set the visibility to hide everything but the 69 // TODO(mattsh), we should set the visibility to hide everything but the
73 // selected view. 70 // selected view.
74 } 71 }
75 72
76 int getIndexOfSelectedView() { 73 int getIndexOfSelectedView() {
77 for (int i = 0; i < childViews.length; i++) { 74 for (int i = 0; i < childViews.length; i++) {
78 if (childViews[i] == selectedView) { 75 if (childViews[i] == selectedView) {
79 return i; 76 return i;
80 } 77 }
(...skipping 10 matching lines...) Expand all
91 view.transform = 'translate3d(${(childViews.length * 100)}%, 0, 0)'; 88 view.transform = 'translate3d(${(childViews.length * 100)}%, 0, 0)';
92 return super.addChild(view); 89 return super.addChild(view);
93 } 90 }
94 91
95 void _onAnimationEnd() { 92 void _onAnimationEnd() {
96 if (viewSelected != null) { 93 if (viewSelected != null) {
97 viewSelected(selectedView); 94 viewSelected(selectedView);
98 } 95 }
99 } 96 }
100 } 97 }
OLDNEW
« no previous file with comments | « samples/swarm/swarm_ui_lib/touch/Scrollbar.dart ('k') | samples/tests/samples/dartcombat/dartcombat_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698