| OLD | NEW |
| 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 Timer animationTimer; | 26 int animationTimeoutId; |
| 27 | 27 |
| 28 ConveyorView() | 28 ConveyorView() |
| 29 : super('conveyor-view', true), | 29 : super('conveyor-view', true), |
| 30 animationTimer = null { | 30 animationTimeoutId = 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 Loading... |
| 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 |
| 64 if (animate) { | 68 if (animate) { |
| 65 animationTimer = new Timer( | 69 animationTimeoutId = window.setTimeout( |
| 66 new Duration(milliseconds: ((durationSeconds * 1000).toInt())), | 70 () { _onAnimationEnd(); }, (durationSeconds * 1000).toInt()); |
| 67 () { _onAnimationEnd(); }); | |
| 68 } | 71 } |
| 69 // TODO(mattsh), we should set the visibility to hide everything but the | 72 // TODO(mattsh), we should set the visibility to hide everything but the |
| 70 // selected view. | 73 // selected view. |
| 71 } | 74 } |
| 72 | 75 |
| 73 int getIndexOfSelectedView() { | 76 int getIndexOfSelectedView() { |
| 74 for (int i = 0; i < childViews.length; i++) { | 77 for (int i = 0; i < childViews.length; i++) { |
| 75 if (childViews[i] == selectedView) { | 78 if (childViews[i] == selectedView) { |
| 76 return i; | 79 return i; |
| 77 } | 80 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 88 view.transform = 'translate3d(${(childViews.length * 100)}%, 0, 0)'; | 91 view.transform = 'translate3d(${(childViews.length * 100)}%, 0, 0)'; |
| 89 return super.addChild(view); | 92 return super.addChild(view); |
| 90 } | 93 } |
| 91 | 94 |
| 92 void _onAnimationEnd() { | 95 void _onAnimationEnd() { |
| 93 if (viewSelected != null) { | 96 if (viewSelected != null) { |
| 94 viewSelected(selectedView); | 97 viewSelected(selectedView); |
| 95 } | 98 } |
| 96 } | 99 } |
| 97 } | 100 } |
| OLD | NEW |