Skip to content

Commit

Permalink
feat: add interface for load start event
Browse files Browse the repository at this point in the history
  • Loading branch information
TheRogue76 committed Apr 12, 2024
1 parent 8e39694 commit a2ba511
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 5 additions & 0 deletions packages/core/src/LottieView/index.tsx
Expand Up @@ -67,6 +67,10 @@ export class LottieView extends React.PureComponent<Props, {}> {
Commands.resume(this.lottieAnimationViewRef);
}

private onAnimationLoadStart = () => {
this.props.onAnimationLoadStart?.()
}

private onAnimationFinish = (
evt: NativeSyntheticEvent<{ isCancelled: boolean }>,
) => {
Expand Down Expand Up @@ -132,6 +136,7 @@ export class LottieView extends React.PureComponent<Props, {}> {
onAnimationFinish={this.onAnimationFinish}
onAnimationFailure={this.onAnimationFailure}
onAnimationLoaded={this.onAnimationLoaded}
onAnimationLoadStarted={this.onAnimationLoadStart}
autoPlay={autoPlay}
resizeMode={resizeMode}
{...sources}
Expand Down
10 changes: 8 additions & 2 deletions packages/core/src/specs/LottieAnimationViewNativeComponent.ts
Expand Up @@ -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;
}>;

Expand Down Expand Up @@ -54,8 +56,12 @@ export interface NativeProps extends ViewProps {
dummy?: Readonly<{ dummy: boolean }>;
textFiltersAndroid?: ReadonlyArray<TextFilterAndroidStruct>;
textFiltersIOS?: ReadonlyArray<TextFilterIOSStruct>;
onAnimationLoadStart?: BubblingEventHandler<
AnimationLoadStartEvent,
'onAnimationLoadStarted'
>
onAnimationFinish?: BubblingEventHandler<
OnAnimationFinishEvent,
AnimationFinishEvent,
'onAnimationFinish'
>;
onAnimationFailure?: BubblingEventHandler<
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/types.ts
Expand Up @@ -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.
Expand Down

0 comments on commit a2ba511

Please sign in to comment.