OLD | NEW |
(Empty) | |
| 1 part of angular.core.dom_internal; |
| 2 |
| 3 /** |
| 4 * The [Animate] service provides dom lifecycle management, detection and |
| 5 * analysis of css animations, and hooks for custom animations. When any of |
| 6 * these animations are run, [Animation]s are returned so the animation can be |
| 7 * controlled and so that custom dom manipulations can occur when animations |
| 8 * complete. |
| 9 */ |
| 10 @Injectable() |
| 11 class Animate { |
| 12 /** |
| 13 * Add the [cssClass] to the classes on [element] after running any |
| 14 * defined animations. |
| 15 */ |
| 16 Animation addClass(dom.Element element, String cssClass) { |
| 17 element.classes.add(cssClass); |
| 18 return new NoOpAnimation(); |
| 19 } |
| 20 |
| 21 /** |
| 22 * Remove the [cssClass] from the classes on [element] after running any |
| 23 * defined animations. |
| 24 */ |
| 25 Animation removeClass(dom.Element element, String cssClass) { |
| 26 element.classes.remove(cssClass); |
| 27 return new NoOpAnimation(); |
| 28 } |
| 29 |
| 30 /** |
| 31 * Perform an 'enter' animation for each element in [nodes]. The elements |
| 32 * must exist in the dom. This is equivalent to running enter on each element |
| 33 * in [nodes] and returning Future.wait(handles); for the onCompleted |
| 34 * property on [Animation]. |
| 35 */ |
| 36 Animation insert(Iterable<dom.Node> nodes, dom.Node parent, |
| 37 { dom.Node insertBefore }) { |
| 38 util.domInsert(nodes, parent, insertBefore: insertBefore); |
| 39 return new NoOpAnimation(); |
| 40 } |
| 41 |
| 42 /** |
| 43 * Perform a 'remove' animation for each element in [nodes]. The elements |
| 44 * must exist in the dom and should not be detached until the [onCompleted] |
| 45 * future on the [Animation] is executed AND the [AnimationResult] is |
| 46 * [AnimationResult.COMPLETED] or [AnimationResult.COMPLETED_IGNORED]. |
| 47 * |
| 48 * This is equivalent to running remove on each element in [nodes] and |
| 49 * returning Future.wait(handles); for the onCompleted property on |
| 50 * [Animation]. |
| 51 */ |
| 52 Animation remove(Iterable<dom.Node> nodes) { |
| 53 util.domRemove(nodes.toList(growable: false)); |
| 54 return new NoOpAnimation(); |
| 55 } |
| 56 |
| 57 /** |
| 58 * Perform a 'move' animation for each element in [nodes]. The elements |
| 59 * must exist in the dom. This is equivalent to running move on each element |
| 60 * in [nodes] and returning Future.wait(handles); for the onCompleted |
| 61 * property on [Animation]. |
| 62 */ |
| 63 Animation move(Iterable<dom.Node> nodes, dom.Node parent, |
| 64 { dom.Node insertBefore }) { |
| 65 util.domMove(nodes, parent, insertBefore: insertBefore); |
| 66 return new NoOpAnimation(); |
| 67 } |
| 68 } |
| 69 |
| 70 |
| 71 /** |
| 72 * Animation handle for controlling and listening to animation completion. |
| 73 */ |
| 74 abstract class Animation { |
| 75 /** |
| 76 * Executed once when the animation is completed with the type of completion |
| 77 * result. |
| 78 */ |
| 79 async.Future<AnimationResult> get onCompleted; |
| 80 |
| 81 /** |
| 82 * Stop and complete the animation immediately. This has no effect if the |
| 83 * animation has already completed. |
| 84 * |
| 85 * The onCompleted future will be executed if the animation has not been |
| 86 * completed. |
| 87 */ |
| 88 void complete(); |
| 89 |
| 90 /** |
| 91 * Stop and cancel the animation immediately. This has no effect if the |
| 92 * animation has already completed. |
| 93 * |
| 94 * The onCompleted future will be executed if the animation has not been |
| 95 * completed. |
| 96 */ |
| 97 void cancel(); |
| 98 } |
| 99 |
| 100 /** |
| 101 * Completed animation handle that is used when an animation is ignored and the |
| 102 * final effect of the animation is immediately completed. |
| 103 * |
| 104 * TODO(codelogic): consider making a singleton instance. Depends on how future |
| 105 * behaves. |
| 106 */ |
| 107 class NoOpAnimation extends Animation { |
| 108 async.Future<AnimationResult> _future; |
| 109 get onCompleted { |
| 110 if (_future == null) { |
| 111 _future = new async.Future.value(AnimationResult.COMPLETED_IGNORED); |
| 112 } |
| 113 return _future; |
| 114 } |
| 115 |
| 116 complete() { } |
| 117 cancel() { } |
| 118 } |
| 119 |
| 120 /** |
| 121 * Final result of an animation after it is no longer attached to the element. |
| 122 */ |
| 123 class AnimationResult { |
| 124 /// Animation was run (if it exists) and completed successfully. |
| 125 static const COMPLETED = const AnimationResult._('COMPLETED'); |
| 126 |
| 127 /// Animation was skipped, but should be continued. |
| 128 static const COMPLETED_IGNORED = const AnimationResult._('COMPLETED_IGNORED'); |
| 129 |
| 130 /// A [CANCELED] animation should not proceed with it's final effects. |
| 131 static const CANCELED = const AnimationResult._('CANCELED'); |
| 132 |
| 133 /// Convenience method if you don't care exactly how an animation completed |
| 134 /// only that it did. |
| 135 bool get isCompleted => this == COMPLETED || this == COMPLETED_IGNORED; |
| 136 |
| 137 final String value; |
| 138 const AnimationResult._(this.value); |
| 139 } |
OLD | NEW |