From a2ba511856c1668c6b0f27399541fc84bbd0210a Mon Sep 17 00:00:00 2001 From: Parsa Nasirimehr Date: Fri, 12 Apr 2024 20:54:23 +0200 Subject: [PATCH] feat: add interface for load start event --- packages/core/src/LottieView/index.tsx | 5 +++++ .../src/specs/LottieAnimationViewNativeComponent.ts | 10 ++++++++-- packages/core/src/types.ts | 6 ++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/packages/core/src/LottieView/index.tsx b/packages/core/src/LottieView/index.tsx index bb64c8e7..ea3d1675 100644 --- a/packages/core/src/LottieView/index.tsx +++ b/packages/core/src/LottieView/index.tsx @@ -67,6 +67,10 @@ export class LottieView extends React.PureComponent { Commands.resume(this.lottieAnimationViewRef); } + private onAnimationLoadStart = () => { + this.props.onAnimationLoadStart?.() + } + private onAnimationFinish = ( evt: NativeSyntheticEvent<{ isCancelled: boolean }>, ) => { @@ -132,6 +136,7 @@ export class LottieView extends React.PureComponent { onAnimationFinish={this.onAnimationFinish} onAnimationFailure={this.onAnimationFailure} onAnimationLoaded={this.onAnimationLoaded} + onAnimationLoadStarted={this.onAnimationLoadStart} autoPlay={autoPlay} resizeMode={resizeMode} {...sources} diff --git a/packages/core/src/specs/LottieAnimationViewNativeComponent.ts b/packages/core/src/specs/LottieAnimationViewNativeComponent.ts index 3dc70d87..9f37e272 100644 --- a/packages/core/src/specs/LottieAnimationViewNativeComponent.ts +++ b/packages/core/src/specs/LottieAnimationViewNativeComponent.ts @@ -8,7 +8,9 @@ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNati import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands'; import type { ProcessedColorValue, ViewProps, HostComponent } from 'react-native'; -export type OnAnimationFinishEvent = Readonly<{ +type AnimationLoadStartEvent = Readonly<{}> + +export type AnimationFinishEvent = Readonly<{ isCancelled: boolean; }>; @@ -54,8 +56,12 @@ export interface NativeProps extends ViewProps { dummy?: Readonly<{ dummy: boolean }>; textFiltersAndroid?: ReadonlyArray; textFiltersIOS?: ReadonlyArray; + onAnimationLoadStart?: BubblingEventHandler< + AnimationLoadStartEvent, + 'onAnimationLoadStarted' + > onAnimationFinish?: BubblingEventHandler< - OnAnimationFinishEvent, + AnimationFinishEvent, 'onAnimationFinish' >; onAnimationFailure?: BubblingEventHandler< diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 283b2fca..2ddace57 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -107,6 +107,12 @@ export interface LottieViewProps { */ autoPlay?: boolean; + /** + * A callback function which will be called when animation starts loading. + * @platform ios, android, web + */ + onAnimationLoadStart?: () => void + /** * A callback function which will be called when animation is finished. Note that this * callback will be called only when `loop` is set to false.