import React from 'react'; import { ContainerRef } from '@cleartrip/ct-design-container'; import { AnimatedStyleWithController, IAnimatedRef, IAnimationOptions } from '../type'; import { IAnimatedStyleClass } from './IAnimatedStyleClass'; class AnimatedStyle implements IAnimatedStyleClass { private animatedStyle: IAnimationOptions | AnimatedStyleWithController[]; private elementRefCallback: (element: React.MutableRefObject) => void; private classNamesRef: React.RefObject; private isSequence: boolean; private springRef: React.RefObject | null; constructor( animationOptions?: IAnimationOptions | AnimatedStyleWithController[], elementRefCallback?: (element: React.MutableRefObject) => void, classNamesRef?: React.RefObject, springRef?: React.RefObject | null, ) { this.animatedStyle = animationOptions ?? {}; this.elementRefCallback = elementRefCallback ?? (() => { // no-op }); this.classNamesRef = classNamesRef ?? React.createRef(); this.isSequence = Array.isArray(animationOptions); this.springRef = springRef ?? null; } getWebIsSpring(): boolean { if (!this.isSequence) { return (this.animatedStyle as IAnimationOptions).config?.animationType === 'spring'; } return false; } getWebSpringRef(): React.RefObject | null { return this.springRef; } getWebIsSequence(): boolean { return this.isSequence; } getWebAnimatedStyle(): IAnimationOptions | null { if (this.getWebIsSequence()) return null; return this.animatedStyle as IAnimationOptions; } getWebAnimatedSequenceStyles(): AnimatedStyleWithController[] { return this.animatedStyle as AnimatedStyleWithController[]; } setWebElementRef(element: React.MutableRefObject): void { this.elementRefCallback(element); } getWebClassNamesRef(): React.RefObject { return this.classNamesRef as React.RefObject; } setWebClassNamesRef(ref: React.RefObject): void { this.classNamesRef = ref; } // Platform-agnostic methods (delegate to web implementations) getAnimatedStyle(): IAnimationOptions | null { return this.getWebAnimatedStyle(); } getAnimatedSequenceStyles(): AnimatedStyleWithController[] { return this.getWebAnimatedSequenceStyles(); } getIsSequence(): boolean { return this.getWebIsSequence(); } getNativeAnimatedStyle(): IAnimationOptions | null { // No Operation return null; } getNativeAnimatedSequenceStyles(): AnimatedStyleWithController[] { // No Operation return []; } getNativeElementRef(): React.RefObject | null { // No Operation return null; } setNativeElementRef(_: React.RefObject | null): void { // No Operation return; } getNativeIsSequence(): boolean { // No Operation return false; } } export default AnimatedStyle;