From 66d631ebca392cc8046b8d33c7f684ec488640d1 Mon Sep 17 00:00:00 2001 From: Vasil Chimev Date: Thu, 7 Dec 2017 12:17:54 +0200 Subject: [PATCH 1/4] Revert "Revert "feat(animation): support animating width/height properties (WIP) (#4917)" (#5136)" This reverts commit 8973a6febde4a4b41637d80b17506a7d25ffebf8. --- .../animation/animation-army-100.ts | 114 +++++++++++++ .../animation/animation-army-100.xml | 157 ++++++++++++++++++ .../animation/animation-curves.ts | 72 ++++++++ .../animation/animation-curves.xml | 31 ++++ .../animation/effect-summary-details.ts | 79 +++++++++ .../animation/effect-summary-details.xml | 13 ++ .../ui-tests-app/animation/height-basic.ts | 17 ++ .../ui-tests-app/animation/height-basic.xml | 10 ++ .../animation/layout-stack-height.ts | 12 ++ .../animation/layout-stack-height.xml | 16 ++ apps/app/ui-tests-app/animation/main-page.ts | 20 +++ apps/app/ui-tests-app/animation/main-page.xml | 6 + apps/app/ui-tests-app/main-page.ts | 3 +- .../ui-tests-app/test-page-main-view-model.ts | 1 + tests/app/ui/animation/animation-tests.ts | 114 ++++++++++++- .../app/ui/styling/style-properties-tests.ts | 55 ++++++ tns-core-modules/globals/globals.ts | 9 + .../ui/animation/animation-common.ts | 36 +++- .../ui/animation/animation.android.ts | 50 +++++- tns-core-modules/ui/animation/animation.d.ts | 11 ++ .../ui/animation/animation.ios.ts | 109 ++++++++---- .../ui/animation/keyframe-animation.ts | 17 +- .../ui/styling/style-properties.d.ts | 4 +- .../ui/styling/style-properties.ts | 34 +++- 24 files changed, 943 insertions(+), 47 deletions(-) create mode 100644 apps/app/ui-tests-app/animation/animation-army-100.ts create mode 100644 apps/app/ui-tests-app/animation/animation-army-100.xml create mode 100644 apps/app/ui-tests-app/animation/animation-curves.ts create mode 100644 apps/app/ui-tests-app/animation/animation-curves.xml create mode 100644 apps/app/ui-tests-app/animation/effect-summary-details.ts create mode 100644 apps/app/ui-tests-app/animation/effect-summary-details.xml create mode 100644 apps/app/ui-tests-app/animation/height-basic.ts create mode 100644 apps/app/ui-tests-app/animation/height-basic.xml create mode 100644 apps/app/ui-tests-app/animation/layout-stack-height.ts create mode 100644 apps/app/ui-tests-app/animation/layout-stack-height.xml create mode 100644 apps/app/ui-tests-app/animation/main-page.ts create mode 100644 apps/app/ui-tests-app/animation/main-page.xml diff --git a/apps/app/ui-tests-app/animation/animation-army-100.ts b/apps/app/ui-tests-app/animation/animation-army-100.ts new file mode 100644 index 000000000..994d811ec --- /dev/null +++ b/apps/app/ui-tests-app/animation/animation-army-100.ts @@ -0,0 +1,114 @@ +import * as view from 'tns-core-modules/ui/core/view'; +import {View} from 'tns-core-modules/ui/core/view'; +import * as pages from 'tns-core-modules/ui/page'; +import {Button} from 'tns-core-modules/ui/button'; +import {SegmentedBar, SegmentedBarItem} from 'tns-core-modules/ui/segmented-bar'; +import {Label} from 'tns-core-modules/ui/label'; +import {Animation, AnimationDefinition} from 'tns-core-modules/ui/animation'; +import * as fpsMeter from 'tns-core-modules/fps-meter'; + +let fpsCallbackId; +export function onLoaded(args) { + const page = args.object; + const fpsLabel = view.getViewById(page, 'fps') as Label; + fpsCallbackId = fpsMeter.addCallback((fps: number, minFps: number) => { + fpsLabel.text = `${fps.toFixed(2)}/${minFps.toFixed(2)}`; + }); + fpsMeter.start(); +} + +export function onUnloaded() { + fpsMeter.removeCallback(fpsCallbackId); + fpsMeter.stop(); +} + +export function getBoxPropertyAnimationData(property: string, + animateEase: string, + target: View, + extentX: number = 128, + extentY: number = 128) { + let animateKey; + let animateValueTo; + let animateValueFrom; + let animateDuration = animateEase === 'spring' ? 800 : 500; + let animateReturnDelay = animateEase === 'spring' ? 0 : 200; + + // Determine the full animation property name (some are shortened in UI), and the demo to/from values + switch (property) { + case 'height': + target.originX = target.originY = 0.5; + animateKey = 'height'; + animateValueTo = 0; + animateValueFrom = extentY; + break; + case 'width': + target.originX = target.originY = 0.5; + animateKey = 'width'; + animateValueTo = 0; + animateValueFrom = extentX; + break; + case 'opacity': + animateKey = 'opacity'; + animateValueTo = 0; + animateValueFrom = 1; + break; + case 'color': + animateKey = 'backgroundColor'; + animateValueTo = 'blue'; + animateValueFrom = 'purple'; + break; + case 'rotate': + target.originX = target.originY = 0.5; + animateKey = 'rotate'; + animateValueTo = 180; + animateValueFrom = 0; + break; + case 'scale': + target.originX = target.originY = 0.5; + animateKey = 'scale'; + animateValueTo = {x: 0.1, y: 0.1}; + animateValueFrom = {x: 1, y: 1}; + break; + default: + throw new Error(`demo animation for '${property}' is not implemented`); + } + + return { + animateEase, + animateKey, + animateValueTo, + animateValueFrom, + animateReturnDelay, + animateDuration + }; +} + +export function easeAnimate(args) { + const clicked = args.object as Button; + const page: pages.Page = clicked.page; + const select = view.getViewById(page, 'select') as SegmentedBar; + const item: SegmentedBarItem = select.items[select.selectedIndex]; + const animsIn: AnimationDefinition[] = []; + const animsOut: AnimationDefinition[] = []; + for (let i = 0; i < 100; i++) { + const box = view.getViewById(page, 'el-' + i) as Label; + const prop = getBoxPropertyAnimationData(item.title, clicked.text, box, 32, 24); + animsIn.push({ + [prop.animateKey]: prop.animateValueTo, + delay: 15 * i, + target: box, + duration: prop.animateDuration, + curve: prop.animateEase + }); + animsOut.push({ + [prop.animateKey]: prop.animateValueFrom, + target: box, + delay: prop.animateReturnDelay + (5 * (Math.abs(i - 100))), + duration: prop.animateDuration, + curve: prop.animateEase + }); + } + new Animation(animsIn, false).play() + .then(() => new Animation(animsOut, false).play()) + .catch((e) => console.log(e)); +} diff --git a/apps/app/ui-tests-app/animation/animation-army-100.xml b/apps/app/ui-tests-app/animation/animation-army-100.xml new file mode 100644 index 000000000..d56f1558b --- /dev/null +++ b/apps/app/ui-tests-app/animation/animation-army-100.xml @@ -0,0 +1,157 @@ + + + + +