feat: detect if web animations is supported and fallback

This commit is contained in:
Sean Perkins
2024-01-16 21:15:19 -05:00
parent 26567e1661
commit 8a924f33cd
2 changed files with 19 additions and 1 deletions

View File

@@ -1,7 +1,9 @@
import type { ComponentInterface, EventEmitter } from '@stencil/core';
import { Component, Element, Event, Host, Method, Prop, State, Watch, h } from '@stencil/core';
import { supportsWebAnimations } from '@utils/animation/animation';
import { findClosestIonContent, disableContentScrollY, resetContentScrollY } from '@utils/content';
import { isEndSide } from '@utils/helpers';
import { printIonWarning } from '@utils/logging';
import { isRTL } from '@utils/rtl';
import { watchForOptions } from '@utils/watch-options';
@@ -136,6 +138,13 @@ export class ItemSliding implements ComponentInterface {
}
}
componentWillLoad() {
if (!supportsWebAnimations && this.animationType === 'modern') {
printIonWarning('Animation type "modern" needs Web Animations API support. Falling back to "legacy".');
this.animationType = 'legacy';
}
}
/**
* Get the amount the item is open in pixels.
*/
@@ -260,7 +269,7 @@ export class ItemSliding implements ComponentInterface {
/**
* Given a side, return the width of the options on that side.
*
*
* @param side The side of the options to get the width for.
*/
private getOptionsWidth(side: 'start' | 'end'): number {

View File

@@ -38,6 +38,15 @@ type AnimationOnStopCallback = AnimationOnFinishCallback;
*/
type AnimationReadWriteCallback = () => void;
export const supportsAnimationEffect =
typeof (AnimationEffect as any) === 'function' ||
(win !== undefined && typeof (win as any).AnimationEffect === 'function');
export const supportsWebAnimations =
typeof (Element as any) === 'function' &&
typeof (Element as any).prototype!.animate === 'function' &&
supportsAnimationEffect;
export const createAnimation = (animationId?: string): Animation => {
let _delay: number | undefined;
let _duration: number | undefined;