feat(animation): add animation utility (#18918)

* Add new keyframes proof of concept

* update esm import

* add base before and after methods, add tests

* add base before and after hooks

* update clean up methods, add tests

* add web animations support, change to arrow functions

* remove console logs

* add from, to, fromTo, and other properties

* add more tests, fix onFinish functionality, being testing with nav transitions

* add progress methods, use force linear

* run linter

* Add playSync

* integrate animations with framework components

* onFinish now supports multiple callbacks

* change const to let

* testing reverse

* add support for both animation utilities

* bug fix

* export createAnimation, a few tweaks

* add base tests

* fix issue with onFinish being called out of order. added tests

* fix race conditions in tests

* clean up

* fix bug where onFinish not calling for empty elements array,  update test

* clean up

* fix treeshaking, remove old comments

* remove old tests

* Add test for animationbuilder backwards compat

* update typings for menu controller

* mock web animations in tests

* run build

* fix type errors

* sync with master

* use requestAnimationFrame instead of writeTask

* fix flaky tests, fix menu

* fix ordering

* update webdriver

* fix wrong version

* Revert "fix wrong version"

This reverts commit be91296e9701399f8d784b08d09a3c475ca15df7.

Revert chromedriver update

* Revert "update webdriver"

This reverts commit e49bc9d76e335a0af5828725065399bd6795fa37.

Revert chromedriver update

* expose raw animation object, add tests

* add stylesheet recycling

* finalize before and after hook tests

* a few styling changes

* fix lint warnings

* get rid of old code

* Fix progressStep overflow bug

* disable reuse stylesheet

* small updates

* fix old animation create

* setStyleProperty helper

* reuse keyframe styles

* keyframes

* fix css animation issue with display: none, add tests

* add comment

* fix issue with progress animations and css animations

* clean up

* clean up pt2

* fix tests

* fix linter

* add fill for overlays

* fix swipe to go back

* clean up css animations when done

* fix edge cases with css animations

* fix menu open and close

* add reset function

* clean up reset fn

* Fix issue where animation always being reset

* allow updating animations on the fly

* add clear onfinish method

* fix linter

* add callback options, expand force direction

* ensure opts is defined

* fix css animations open and close for menus

* remove test

* add extra check

* clean up

* fix css anim bug swipe to go back

* fix pause

* setup alt animation to avoid flickering

* clean up

* reset flags on destroy

* add ability to change duration on progressEnd

* fix flicker on duration change for css animations

* fix ios transition

* remove unneeded recursion

* increase durability of updating css animations on the fly

* fix gesture anim

* fix web anim as well. more work for cleanup

* simplify progressEnd for css animations

* fix swipe to go back race condition

* clean up

* Add todo

* fix one more bug
This commit is contained in:
Liam DeBeasi
2019-08-12 10:05:04 -04:00
committed by GitHub
parent e33cf854a9
commit 30ca46ab12
70 changed files with 3974 additions and 762 deletions

View File

@ -2,7 +2,7 @@ import { Build, Component, ComponentInterface, Element, Event, EventEmitter, Hos
import { config } from '../../global/config';
import { getIonMode } from '../../global/ionic-global';
import { Animation, Gesture, GestureDetail, MenuChangeEventDetail, MenuControllerI, MenuI, Side } from '../../interface';
import { Gesture, GestureDetail, IonicAnimation, MenuChangeEventDetail, MenuControllerI, MenuI, Side } from '../../interface';
import { GESTURE_CONTROLLER } from '../../utils/gesture';
import { assert, isEndSide as isEnd } from '../../utils/helpers';
@ -16,7 +16,7 @@ import { assert, isEndSide as isEnd } from '../../utils/helpers';
})
export class Menu implements ComponentInterface, MenuI {
private animation?: Animation;
private animation?: any;
private lastOnEnd = 0;
private gesture?: Gesture;
private blocker = GESTURE_CONTROLLER.createBlocker({ disableScroll: true });
@ -309,10 +309,15 @@ export class Menu implements ComponentInterface, MenuI {
}
// Create new animation
this.animation = await this.menuCtrl!._createAnimation(this.type!, this);
this.animation.fill('both');
}
private async startAnimation(shouldOpen: boolean, animated: boolean): Promise<void> {
const ani = this.animation!.reverse(!shouldOpen);
const isReversed = !shouldOpen;
const ani = (this.animation as IonicAnimation)!
.direction((isReversed) ? 'reverse' : 'normal')
.easing((isReversed) ? 'cubic-bezier(0.4, 0.0, 0.6, 1)' : 'cubic-bezier(0.0, 0.0, 0.2, 1)');
if (animated) {
await ani.playAsync();
} else {
@ -358,7 +363,9 @@ export class Menu implements ComponentInterface, MenuI {
}
// the cloned animation should not use an easing curve during seek
this.animation.reverse(this._isOpen).progressStart();
(this.animation as IonicAnimation)
.direction((this._isOpen) ? 'reverse' : 'normal')
.progressStart(true);
}
private onMove(detail: GestureDetail) {
@ -369,7 +376,10 @@ export class Menu implements ComponentInterface, MenuI {
const delta = computeDelta(detail.deltaX, this._isOpen, this.isEndSide);
const stepValue = delta / this.width;
this.animation.progressStep(stepValue);
this.animation
.progressStep(stepValue);
}
private onEnd(detail: GestureDetail) {
@ -410,8 +420,7 @@ export class Menu implements ComponentInterface, MenuI {
this.lastOnEnd = detail.timeStamp;
this.animation
.onFinish(() => this.afterAnimation(shouldOpen), {
clearExistingCallbacks: true,
oneTimeCallback: true
oneTime: true
})
.progressEnd(shouldComplete, stepValue, realDur);
}
@ -492,7 +501,7 @@ export class Menu implements ComponentInterface, MenuI {
assert(this._isOpen, 'menu cannot be closed');
this.isAnimating = true;
const ani = this.animation!.reverse(true);
const ani = (this.animation as IonicAnimation)!.direction('reverse');
ani.playSync();
this.afterAnimation(false);
}