|
| 1 | +import * as observable from "data/observable"; |
| 2 | +import * as pages from "ui/page"; |
| 3 | +import * as buttonModule from "ui/button"; |
| 4 | +import * as abs from "ui/layouts/absolute-layout"; |
| 5 | +import * as animationModule from "ui/animation"; |
| 6 | +import * as colorModule from "color"; |
| 7 | +import * as model from "./model"; |
| 8 | +import * as enums from "ui/enums"; |
| 9 | +import * as frame from "ui/frame"; |
| 10 | +import * as trace from "trace"; |
| 11 | + |
| 12 | +var vm = new model.ViewModel(); |
| 13 | + |
| 14 | +var page: pages.Page; |
| 15 | +var panel: abs.AbsoluteLayout; |
| 16 | +var button1: buttonModule.Button; |
| 17 | +var button2: buttonModule.Button; |
| 18 | +var button3: buttonModule.Button; |
| 19 | +var buttonAnimation: animationModule.Animation; |
| 20 | +var panelAnimation: animationModule.Animation; |
| 21 | + |
| 22 | +export function pageLoaded(args: observable.EventData) { |
| 23 | + page = <pages.Page>args.object; |
| 24 | + page.bindingContext = vm; |
| 25 | + panel = page.getViewById<abs.AbsoluteLayout>("panel1"); |
| 26 | + button1 = page.getViewById<buttonModule.Button>("button1"); |
| 27 | + button2 = page.getViewById<buttonModule.Button>("button2"); |
| 28 | + button3 = page.getViewById<buttonModule.Button>("button3"); |
| 29 | + |
| 30 | + |
| 31 | + trace.enable(); |
| 32 | + trace.addCategories(trace.categories.concat(trace.categories.Animation)); |
| 33 | +} |
| 34 | + |
| 35 | +export function onSlideOut(args: observable.EventData) { |
| 36 | + console.log("onSlideOut"); |
| 37 | + var curve = enums.AnimationCurve.easeOut; |
| 38 | + |
| 39 | + var buttonAnimations = [ |
| 40 | + { target: button1, translate: { x: -240, y: 0 }, scale: { x: 0.5, y: 0.5 }, opacity: 0, duration: vm.duration, delay: 0, iterations: vm.iterations, curve: curve }, |
| 41 | + { target: button2, translate: { x: -240, y: 0 }, scale: { x: 0.5, y: 0.5 }, opacity: 0, duration: vm.duration, delay: vm.duration, iterations: vm.iterations, curve: curve }, |
| 42 | + { target: button3, translate: { x: -240, y: 0 }, scale: { x: 0.5, y: 0.5 }, opacity: 0, duration: vm.duration, delay: vm.duration * 2, iterations: vm.iterations, curve: curve }, |
| 43 | + ] |
| 44 | + buttonAnimation = new animationModule.Animation(buttonAnimations, vm.playSequentially); |
| 45 | + |
| 46 | + panelAnimation = panel.createAnimation({ opacity: 0, scale: { x: 0.5, y: 0.5 }, rotate: -360, backgroundColor: new colorModule.Color("red"), duration: vm.duration, iterations: vm.iterations, curve: enums.AnimationCurve.easeInOut }); |
| 47 | + |
| 48 | + buttonAnimation.play() |
| 49 | + .then(() => panelAnimation.play()) |
| 50 | + .catch((e) => console.log(e.message)); |
| 51 | +} |
| 52 | + |
| 53 | +export function onSlideIn(args: observable.EventData) { |
| 54 | + console.log("onSlideIn"); |
| 55 | + var curve = enums.AnimationCurve.easeIn; |
| 56 | + |
| 57 | + panelAnimation = panel.createAnimation({ opacity: 1, scale: { x: 1, y: 1 }, rotate: 0, backgroundColor: new colorModule.Color("yellow"), duration: vm.duration, iterations: vm.iterations, curve: enums.AnimationCurve.easeInOut }); |
| 58 | + |
| 59 | + var buttonAnimations = [ |
| 60 | + { target: button3, translate: { x: 0, y: 0 }, scale: { x: 1, y: 1 }, opacity: 1, duration: vm.duration, delay: 0, iterations: vm.iterations, curve: curve }, |
| 61 | + { target: button2, translate: { x: 0, y: 0 }, scale: { x: 1, y: 1 }, opacity: 1, duration: vm.duration, delay: vm.duration, iterations: vm.iterations, curve: curve }, |
| 62 | + { target: button1, translate: { x: 0, y: 0 }, scale: { x: 1, y: 1 }, opacity: 1, duration: vm.duration, delay: vm.duration * 2, iterations: vm.iterations, curve: curve }, |
| 63 | + ] |
| 64 | + buttonAnimation = new animationModule.Animation(buttonAnimations, vm.playSequentially); |
| 65 | + |
| 66 | + panelAnimation.play() |
| 67 | + .then(() => buttonAnimation.play()) |
| 68 | + .catch((e) => console.log(e.message)); |
| 69 | +} |
| 70 | + |
| 71 | +export function onCancel(args: observable.EventData) { |
| 72 | + console.log("onCancel"); |
| 73 | + if (panelAnimation && panelAnimation.isPlaying) { |
| 74 | + panelAnimation.cancel(); |
| 75 | + } |
| 76 | + if (buttonAnimation && buttonAnimation.isPlaying) { |
| 77 | + buttonAnimation.cancel(); |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +export function onTap(args: observable.EventData) { |
| 82 | + console.log((<any>a
F987
rgs.object).text); |
| 83 | +} |
| 84 | + |
| 85 | +export function onSingle(args: observable.EventData) { |
| 86 | + console.log("onSingle"); |
| 87 | + button1.animate({ |
| 88 | + opacity: 0.75, |
| 89 | + backgroundColor: new colorModule.Color("Red"), |
| 90 | + translate: { x: 100, y: 100 }, |
| 91 | + scale: { x: 2, y: 2 }, |
| 92 | + rotate: 180, |
| 93 | + duration: vm.duration, |
| 94 | + delay: 0, |
| 95 | + iterations: vm.iterations, |
| 96 | + curve: enums.AnimationCurve.linear, |
| 97 | + }) |
| 98 | + .then(() => console.log("Animation finished")) |
| 99 | + .catch((e) => console.log(e.message)); |
| 100 | +} |
| 101 | + |
| 102 | +export function onSequence(args: observable.EventData) { |
| 103 | + console.log("onSequence"); |
| 104 | + |
| 105 | + button3.animate({ |
| 106 | + translate: { x: 80, y: -40 }, |
| 107 | + scale: { x: 0.9, y: 0.3 }, |
| 108 | + rotate: 25, |
| 109 | + duration: 1000 |
| 110 | + }) |
| 111 | + .then(() => button3.animate({ |
| 112 | + translate: { x: 0, y: -80 }, |
| 113 | + scale: { x: 0.5, y: 0.5 }, |
| 114 | + rotate: -25, |
| 115 | + duration: 1000 |
| 116 | + })) |
| 117 | + .then(() => button3.animate({ |
| 118 | + translate: { x: -80, y: -40 }, |
| 119 | + scale: { x: 0.5, y: 0.9 }, |
| 120 | + rotate: 45, |
| 121 | + duration: 1000 |
| 122 | + })) |
| 123 | + .then(() => button3.animate({ |
| 124 | + translate: { x: 0, y: 0 }, |
| 125 | + scale: { x: 1, y: 1 }, |
| 126 | + rotate: 0, |
| 127 | + duration: 1000 |
| 128 | + })) |
| 129 | + .then(() => console.log("Animation finished")) |
| 130 | + .catch((e) => console.log(e.message)); |
| 131 | +} |
| 132 | + |
| 133 | +export function onInterrupted(args: observable.EventData) { |
| 134 | + console.log("onInterrupt"); |
| 135 | + |
| 136 | + setTimeout(() => { |
| 137 | + button3.animate({ |
| 138 | + translate: { x: 80, y: -40 }, |
| 139 | + scale: { x: 0.9, y: 0.3 }, |
| 140 | + rotate: 25, |
| 141 | + duration: 1000 |
| 142 | + }); |
| 143 | + }, 700 * 0); |
| 144 | + |
| 145 | + setTimeout(function() { |
| 146 | + button3.animate({ |
| 147 | + translate: { x: 0, y: -80 }, |
| 148 | + scale: { x: 0.5, y: 0.5 }, |
| 149 | + rotate: -25, |
| 150 | + duration: 1000 |
| 151 | + }) |
| 152 | + }, 700 * 1); |
| 153 | + |
| 154 | + setTimeout(function() { |
| 155 | + button3.animate({ |
| 156 | + translate: { x: -80, y: -40 }, |
| 157 | + scale: { x: 0.5, y: 0.9 }, |
| 158 | + rotate: 45, |
| 159 | + duration: 1000 |
| 160 | + }) |
| 161 | + }, 700 * 2); |
| 162 | + |
| 163 | + setTimeout(function() { |
| 164 | + button3.animate({ |
| 165 | + translate: { x: 0, y: 0 }, |
| 166 | + scale: { x: 1, y: 1 }, |
| 167 | + rotate: 0, |
| 168 | + duration: 1000 |
| 169 | + }) |
| 170 | + }, 700 * 3); |
| 171 | +} |
| 172 | + |
| 173 | +export function onOpacity(args: observable.EventData) { |
| 174 | + frame.topmost().navigate("./opacity"); |
| 175 | +} |
0 commit comments