From 0dd8f985c4247c0bc7609b414b02178f3d1aed60 Mon Sep 17 00:00:00 2001 From: Panayot Cankov Date: Wed, 25 Jan 2017 13:17:33 +0200 Subject: [PATCH] Add animations demo to the gallery app, make vertical alignment center and visibility collapsed backward compatible --- apps/app/gallery-app/animations/bkg.png | Bin 0 -> 311 bytes .../gallery-app/animations/configurable.ts | 175 ++++++++++++++++++ .../gallery-app/animations/configurable.xml | 36 ++++ apps/app/gallery-app/animations/model.ts | 37 ++++ apps/app/gallery-app/animations/opacity.css | 27 +++ apps/app/gallery-app/animations/opacity.ts | 47 +++++ apps/app/gallery-app/animations/opacity.xml | 35 ++++ apps/app/gallery-app/animations/package.json | 2 + apps/app/gallery-app/animations/test-icon.png | Bin 0 -> 1304 bytes apps/app/gallery-app/main-page.xml | 6 + .../data/observable/observable.d.ts | 7 + tns-core-modules/ui/core/view-common.ts | 15 +- 12 files changed, 376 insertions(+), 11 deletions(-) create mode 100644 apps/app/gallery-app/animations/bkg.png create mode 100644 apps/app/gallery-app/animations/configurable.ts create mode 100644 apps/app/gallery-app/animations/configurable.xml create mode 100644 apps/app/gallery-app/animations/model.ts create mode 100644 apps/app/gallery-app/animations/opacity.css create mode 100644 apps/app/gallery-app/animations/opacity.ts create mode 100644 apps/app/gallery-app/animations/opacity.xml create mode 100644 apps/app/gallery-app/animations/package.json create mode 100644 apps/app/gallery-app/animations/test-icon.png diff --git a/apps/app/gallery-app/animations/bkg.png b/apps/app/gallery-app/animations/bkg.png new file mode 100644 index 0000000000000000000000000000000000000000..fa059ba75757ee3886a8fa6b4ad4e7cba46142f1 GIT binary patch literal 311 zcmeAS@N?(olHy`uVBq!ia0vp^Mj*_=1SBWM%0B~AjKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1qucL5ULAh?3y^w370~qEv>0#LT=By}Z;C1rt33 zJ=4@yqg0@p6`n4RArbCxuN!h5HV|n}WSzs8|MtR8yJG)K+`CR)II5aps(+OApt+>Z zKOV^*hAg&s3A{1cOz#Rdram~g?MDXZj>l^f&jnd{Kh$a6EP}!?%)hqeeE5;3D4`=o zj&}n3AM@?svf!@pl|x6>Zx!Atyk?ND>39B-z3HOeU%S`5dop?Ry*XQtM{=cW&RP0n r{Tji$YcFr!_gLrXnMh%~69W1>69hV1_WscYx|zY#)z4*}Q$iB}A7yx< literal 0 HcmV?d00001 diff --git a/apps/app/gallery-app/animations/configurable.ts b/apps/app/gallery-app/animations/configurable.ts new file mode 100644 index 000000000..1f2aa4d08 --- /dev/null +++ b/apps/app/gallery-app/animations/configurable.ts @@ -0,0 +1,175 @@ +import * as observable from "data/observable"; +import * as pages from "ui/page"; +import * as buttonModule from "ui/button"; +import * as abs from "ui/layouts/absolute-layout"; +import * as animationModule from "ui/animation"; +import * as colorModule from "color"; +import * as model from "./model"; +import * as enums from "ui/enums"; +import * as frame from "ui/frame"; +import * as trace from "trace"; + +var vm = new model.ViewModel(); + +var page: pages.Page; +var panel: abs.AbsoluteLayout; +var button1: buttonModule.Button; +var button2: buttonModule.Button; +var button3: buttonModule.Button; +var buttonAnimation: animationModule.Animation; +var panelAnimation: animationModule.Animation; + +export function pageLoaded(args: observable.EventData) { + page = args.object; + page.bindingContext = vm; + panel = page.getViewById("panel1"); + button1 = page.getViewById("button1"); + button2 = page.getViewById("button2"); + button3 = page.getViewById("button3"); + + + trace.enable(); + trace.addCategories(trace.categories.concat(trace.categories.Animation)); +} + +export function onSlideOut(args: observable.EventData) { + console.log("onSlideOut"); + var curve = enums.AnimationCurve.easeOut; + + var buttonAnimations = [ + { 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 }, + { 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 }, + { 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 }, + ] + buttonAnimation = new animationModule.Animation(buttonAnimations, vm.playSequentially); + + 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 }); + + buttonAnimation.play() + .then(() => panelAnimation.play()) + .catch((e) => console.log(e.message)); +} + +export function onSlideIn(args: observable.EventData) { + console.log("onSlideIn"); + var curve = enums.AnimationCurve.easeIn; + + 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 }); + + var buttonAnimations = [ + { target: button3, translate: { x: 0, y: 0 }, scale: { x: 1, y: 1 }, opacity: 1, duration: vm.duration, delay: 0, iterations: vm.iterations, curve: curve }, + { 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 }, + { 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 }, + ] + buttonAnimation = new animationModule.Animation(buttonAnimations, vm.playSequentially); + + panelAnimation.play() + .then(() => buttonAnimation.play()) + .catch((e) => console.log(e.message)); +} + +export function onCancel(args: observable.EventData) { + console.log("onCancel"); + if (panelAnimation && panelAnimation.isPlaying) { + panelAnimation.cancel(); + } + if (buttonAnimation && buttonAnimation.isPlaying) { + buttonAnimation.cancel(); + } +} + +export function onTap(args: observable.EventData) { + console.log((args.object).text); +} + +export function onSingle(args: observable.EventData) { + console.log("onSingle"); + button1.animate({ + opacity: 0.75, + backgroundColor: new colorModule.Color("Red"), + translate: { x: 100, y: 100 }, + scale: { x: 2, y: 2 }, + rotate: 180, + duration: vm.duration, + delay: 0, + iterations: vm.iterations, + curve: enums.AnimationCurve.linear, + }) + .then(() => console.log("Animation finished")) + .catch((e) => console.log(e.message)); +} + +export function onSequence(args: observable.EventData) { + console.log("onSequence"); + + button3.animate({ + translate: { x: 80, y: -40 }, + scale: { x: 0.9, y: 0.3 }, + rotate: 25, + duration: 1000 + }) + .then(() => button3.animate({ + translate: { x: 0, y: -80 }, + scale: { x: 0.5, y: 0.5 }, + rotate: -25, + duration: 1000 + })) + .then(() => button3.animate({ + translate: { x: -80, y: -40 }, + scale: { x: 0.5, y: 0.9 }, + rotate: 45, + duration: 1000 + })) + .then(() => button3.animate({ + translate: { x: 0, y: 0 }, + scale: { x: 1, y: 1 }, + rotate: 0, + duration: 1000 + })) + .then(() => console.log("Animation finished")) + .catch((e) => console.log(e.message)); +} + +export function onInterrupted(args: observable.EventData) { + console.log("onInterrupt"); + + setTimeout(() => { + button3.animate({ + translate: { x: 80, y: -40 }, + scale: { x: 0.9, y: 0.3 }, + rotate: 25, + duration: 1000 + }); + }, 700 * 0); + + setTimeout(function() { + button3.animate({ + translate: { x: 0, y: -80 }, + scale: { x: 0.5, y: 0.5 }, + rotate: -25, + duration: 1000 + }) + }, 700 * 1); + + setTimeout(function() { + button3.animate({ + translate: { x: -80, y: -40 }, + scale: { x: 0.5, y: 0.9 }, + rotate: 45, + duration: 1000 + }) + }, 700 * 2); + + setTimeout(function() { + button3.animate({ + translate: { x: 0, y: 0 }, + scale: { x: 1, y: 1 }, + rotate: 0, + duration: 1000 + }) + }, 700 * 3); +} + +export function onOpacity(args: observable.EventData) { + frame.topmost().navigate("./opacity"); +} diff --git a/apps/app/gallery-app/animations/configurable.xml b/apps/app/gallery-app/animations/configurable.xml new file mode 100644 index 000000000..8b939ab70 --- /dev/null +++ b/apps/app/gallery-app/animations/configurable.xml @@ -0,0 +1,36 @@ + + + + +