-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
LottieAnimationViewNativeComponent.ts
75 lines (66 loc) · 2.25 KB
/
LottieAnimationViewNativeComponent.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
import type {
BubblingEventHandler,
Int32,
Double,
Float,
} from 'react-native/Libraries/Types/CodegenTypes';
import codegenNativeComponent, {
NativeComponentType,
} from 'react-native/Libraries/Utilities/codegenNativeComponent';
import codegenNativeCommands from 'react-native/Libraries/Utilities/codegenNativeCommands';
import type { ProcessedColorValue, ViewProps } from 'react-native';
export type OnAnimationFinishEvent = Readonly<{
isCancelled: boolean;
}>;
type ColorFilterStruct = Readonly<{
keypath: string;
color: ProcessedColorValue;
}>;
type TextFilterIOSStruct = Readonly<{
keypath: string;
text: string;
}>;
type TextFilterAndroidStruct = Readonly<{
find: string;
replace: string;
}>;
export interface NativeProps extends ViewProps {
resizeMode?: string;
renderMode?: string;
sourceName?: string;
sourceJson?: string;
sourceURL?: string;
imageAssetsFolder?: string;
progress?: Float;
speed?: Double;
loop?: boolean;
autoPlay?: boolean;
enableMergePathsAndroidForKitKatAndAbove?: boolean;
hardwareAccelerationAndroid?: boolean;
cacheComposition?: boolean;
colorFilters?: ReadonlyArray<ColorFilterStruct>;
// dummy that solves codegen issue when there's a ReadonlyArray<Object> without another Object prop
// https://github.com/reactwg/react-native-new-architecture/discussions/104
dummy?: Readonly<{ dummy: boolean }>;
textFiltersAndroid?: ReadonlyArray<TextFilterAndroidStruct>;
textFiltersIOS?: ReadonlyArray<TextFilterIOSStruct>;
onAnimationFinish?: BubblingEventHandler<
OnAnimationFinishEvent,
'onAnimationFinish'
>;
}
type LottieViewNativeComponentType = NativeComponentType<NativeProps>;
interface NativeCommands {
play: (
viewRef: React.ElementRef<LottieViewNativeComponentType>,
startFrame: Int32,
endFrame: Int32,
) => void;
reset: (viewRef: React.ElementRef<LottieViewNativeComponentType>) => void;
pause: (viewRef: React.ElementRef<LottieViewNativeComponentType>) => void;
resume: (viewRef: React.ElementRef<LottieViewNativeComponentType>) => void;
}
export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({
supportedCommands: ['play', 'reset', 'pause', 'resume'],
});
export default codegenNativeComponent<NativeProps>('LottieAnimationView');