mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-19 19:57:22 +08:00
fix(animation): track correctly when updating CSS Animation (#19813)
* fix bug * update menu * fix
This commit is contained in:
@ -337,7 +337,12 @@ AFTER:
|
|||||||
const isReversed = !shouldOpen;
|
const isReversed = !shouldOpen;
|
||||||
const ani = (this.animation as Animation)!
|
const ani = (this.animation as Animation)!
|
||||||
.direction((isReversed) ? 'reverse' : 'normal')
|
.direction((isReversed) ? 'reverse' : 'normal')
|
||||||
.easing((isReversed) ? this.easingReverse : this.easing);
|
.easing((isReversed) ? this.easingReverse : this.easing)
|
||||||
|
.onFinish(() => {
|
||||||
|
if (ani.getDirection() === 'reverse') {
|
||||||
|
ani.direction('normal');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
if (animated) {
|
if (animated) {
|
||||||
await ani.play();
|
await ani.play();
|
||||||
@ -384,9 +389,7 @@ AFTER:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// the cloned animation should not use an easing curve during seek
|
// the cloned animation should not use an easing curve during seek
|
||||||
(this.animation as Animation)
|
(this.animation as Animation).progressStart(true, (this._isOpen) ? 1 : 0);
|
||||||
.direction((this._isOpen) ? 'reverse' : 'normal')
|
|
||||||
.progressStart(true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private onMove(detail: GestureDetail) {
|
private onMove(detail: GestureDetail) {
|
||||||
@ -398,7 +401,7 @@ AFTER:
|
|||||||
const delta = computeDelta(detail.deltaX, this._isOpen, this.isEndSide);
|
const delta = computeDelta(detail.deltaX, this._isOpen, this.isEndSide);
|
||||||
const stepValue = delta / this.width;
|
const stepValue = delta / this.width;
|
||||||
|
|
||||||
this.animation.progressStep(stepValue);
|
this.animation.progressStep((this._isOpen) ? 1 - stepValue : stepValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
private onEnd(detail: GestureDetail) {
|
private onEnd(detail: GestureDetail) {
|
||||||
@ -451,12 +454,14 @@ AFTER:
|
|||||||
*/
|
*/
|
||||||
newStepValue += getTimeGivenProgression([0, 0], [0.4, 0], [0.6, 1], [1, 1], clamp(0, adjustedStepValue, 1))[0];
|
newStepValue += getTimeGivenProgression([0, 0], [0.4, 0], [0.6, 1], [1, 1], clamp(0, adjustedStepValue, 1))[0];
|
||||||
|
|
||||||
|
const playTo = (this._isOpen) ? !shouldComplete : shouldComplete;
|
||||||
|
|
||||||
this.animation
|
this.animation
|
||||||
.easing('cubic-bezier(0.4, 0.0, 0.6, 1)')
|
.easing('cubic-bezier(0.4, 0.0, 0.6, 1)')
|
||||||
.onFinish(
|
.onFinish(
|
||||||
() => this.afterAnimation(shouldOpen),
|
() => this.afterAnimation(shouldOpen),
|
||||||
{ oneTimeCallback: true })
|
{ oneTimeCallback: true })
|
||||||
.progressEnd(shouldComplete ? 1 : 0, newStepValue, 300);
|
.progressEnd((playTo) ? 1 : 0, (this._isOpen) ? 1 - newStepValue : newStepValue, 300);
|
||||||
}
|
}
|
||||||
|
|
||||||
private beforeAnimation(shouldOpen: boolean) {
|
private beforeAnimation(shouldOpen: boolean) {
|
||||||
|
@ -29,7 +29,7 @@ export interface Animation {
|
|||||||
*/
|
*/
|
||||||
destroy(): void;
|
destroy(): void;
|
||||||
|
|
||||||
progressStart(forceLinearEasing: boolean): void;
|
progressStart(forceLinearEasing: boolean, step?: number): void;
|
||||||
progressStep(step: number): void;
|
progressStep(step: number): void;
|
||||||
progressEnd(playTo: 0 | 1 | undefined, step: number, dur?: number): void;
|
progressEnd(playTo: 0 | 1 | undefined, step: number, dur?: number): void;
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ interface AnimationInternal extends Animation {
|
|||||||
/**
|
/**
|
||||||
* Updates any existing animations.
|
* Updates any existing animations.
|
||||||
*/
|
*/
|
||||||
update(deep: boolean): Animation;
|
update(deep: boolean, toggleAnimationName: boolean, step?: number): Animation;
|
||||||
|
|
||||||
animationFinish(): void;
|
animationFinish(): void;
|
||||||
}
|
}
|
||||||
@ -611,8 +611,7 @@ export const createAnimation = (animationId?: string): Animation => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
const animationDelay = getDelay() || 0;
|
const animationDuration = `-${getDuration()! * step}ms`;
|
||||||
const animationDuration = `-${animationDelay + (getDuration()! * step)}ms`;
|
|
||||||
|
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
if (_keyframes.length > 0) {
|
if (_keyframes.length > 0) {
|
||||||
@ -623,7 +622,7 @@ export const createAnimation = (animationId?: string): Animation => {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateWebAnimation = () => {
|
const updateWebAnimation = (step?: number) => {
|
||||||
webAnimations.forEach(animation => {
|
webAnimations.forEach(animation => {
|
||||||
animation.effect.updateTiming({
|
animation.effect.updateTiming({
|
||||||
delay: getDelay(),
|
delay: getDelay(),
|
||||||
@ -634,15 +633,19 @@ export const createAnimation = (animationId?: string): Animation => {
|
|||||||
direction: getDirection()
|
direction: getDirection()
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (step !== undefined) {
|
||||||
|
setAnimationStep(step);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateCSSAnimation = (toggleAnimationName = true) => {
|
const updateCSSAnimation = (toggleAnimationName = true, step?: number) => {
|
||||||
raf(() => {
|
raf(() => {
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
setStyleProperty(element, 'animation-name', keyframeName || null);
|
setStyleProperty(element, 'animation-name', keyframeName || null);
|
||||||
setStyleProperty(element, 'animation-duration', `${getDuration()}ms`);
|
setStyleProperty(element, 'animation-duration', `${getDuration()}ms`);
|
||||||
setStyleProperty(element, 'animation-timing-function', getEasing());
|
setStyleProperty(element, 'animation-timing-function', getEasing());
|
||||||
setStyleProperty(element, 'animation-delay', `${getDelay()}ms`);
|
setStyleProperty(element, 'animation-delay', (step !== undefined) ? `-${step! * getDuration()}ms` : `${getDelay()}ms`);
|
||||||
setStyleProperty(element, 'animation-fill-mode', getFill() || null);
|
setStyleProperty(element, 'animation-fill-mode', getFill() || null);
|
||||||
setStyleProperty(element, 'animation-direction', getDirection() || null);
|
setStyleProperty(element, 'animation-direction', getDirection() || null);
|
||||||
|
|
||||||
@ -663,25 +666,25 @@ export const createAnimation = (animationId?: string): Animation => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const update = (deep = false, toggleAnimationName = true) => {
|
const update = (deep = false, toggleAnimationName = true, step?: number) => {
|
||||||
if (deep) {
|
if (deep) {
|
||||||
childAnimations.forEach(animation => {
|
childAnimations.forEach(animation => {
|
||||||
animation.update(deep);
|
animation.update(deep, toggleAnimationName, step);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (supportsWebAnimations) {
|
if (supportsWebAnimations) {
|
||||||
updateWebAnimation();
|
updateWebAnimation(step);
|
||||||
} else {
|
} else {
|
||||||
updateCSSAnimation(toggleAnimationName);
|
updateCSSAnimation(toggleAnimationName, step);
|
||||||
}
|
}
|
||||||
|
|
||||||
return ani;
|
return ani;
|
||||||
};
|
};
|
||||||
|
|
||||||
const progressStart = (forceLinearEasing = false) => {
|
const progressStart = (forceLinearEasing = false, step?: number) => {
|
||||||
childAnimations.forEach(animation => {
|
childAnimations.forEach(animation => {
|
||||||
animation.progressStart(forceLinearEasing);
|
animation.progressStart(forceLinearEasing, step);
|
||||||
});
|
});
|
||||||
|
|
||||||
pauseAnimation();
|
pauseAnimation();
|
||||||
@ -690,8 +693,7 @@ export const createAnimation = (animationId?: string): Animation => {
|
|||||||
if (!initialized) {
|
if (!initialized) {
|
||||||
initializeAnimation();
|
initializeAnimation();
|
||||||
} else {
|
} else {
|
||||||
update();
|
update(false, true, step);
|
||||||
setAnimationStep(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ani;
|
return ani;
|
||||||
|
Reference in New Issue
Block a user