@granite-js/lottie 1.0.17 → 1.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import React, { forwardRef,
|
|
3
|
+
import React, { forwardRef, useRef, useCallback, useMemo } from 'react';
|
|
4
4
|
import { Image, Platform } from 'react-native';
|
|
5
5
|
import NativeGraniteLottieView, { Commands } from './GraniteLottieViewNativeComponent';
|
|
6
6
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
function assignRef(ref, value) {
|
|
8
|
+
if (typeof ref === 'function') {
|
|
9
|
+
ref(value);
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
if (ref != null) {
|
|
13
|
+
ref.current = value;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function attachImperativeMethods(instance) {
|
|
17
|
+
const handle = instance;
|
|
18
|
+
handle.play = (startFrame, endFrame) => {
|
|
19
|
+
Commands.play(instance, startFrame ?? -1, endFrame ?? -1);
|
|
20
|
+
};
|
|
21
|
+
handle.pause = () => {
|
|
22
|
+
Commands.pause(instance);
|
|
23
|
+
};
|
|
24
|
+
handle.resume = () => {
|
|
25
|
+
Commands.resume(instance);
|
|
26
|
+
};
|
|
27
|
+
handle.reset = () => {
|
|
28
|
+
Commands.reset(instance);
|
|
29
|
+
};
|
|
30
|
+
return handle;
|
|
31
|
+
}
|
|
32
|
+
|
|
7
33
|
// Helper to resolve animation source
|
|
8
34
|
function resolveSource(source) {
|
|
9
35
|
if (typeof source === 'number') {
|
|
@@ -89,30 +115,14 @@ export const LottieView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
89
115
|
...restProps
|
|
90
116
|
} = props;
|
|
91
117
|
const nativeRef = useRef(null);
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
Commands.play(nativeRef.current, startFrame ?? -1, endFrame ?? -1);
|
|
98
|
-
}
|
|
99
|
-
},
|
|
100
|
-
pause: () => {
|
|
101
|
-
if (nativeRef.current) {
|
|
102
|
-
Commands.pause(nativeRef.current);
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
resume: () => {
|
|
106
|
-
if (nativeRef.current) {
|
|
107
|
-
Commands.resume(nativeRef.current);
|
|
108
|
-
}
|
|
109
|
-
},
|
|
110
|
-
reset: () => {
|
|
111
|
-
if (nativeRef.current) {
|
|
112
|
-
Commands.reset(nativeRef.current);
|
|
113
|
-
}
|
|
118
|
+
const handleRef = useCallback(instance => {
|
|
119
|
+
nativeRef.current = instance;
|
|
120
|
+
if (instance == null) {
|
|
121
|
+
assignRef(ref, null);
|
|
122
|
+
return;
|
|
114
123
|
}
|
|
115
|
-
|
|
124
|
+
assignRef(ref, attachImperativeMethods(instance));
|
|
125
|
+
}, [ref]);
|
|
116
126
|
|
|
117
127
|
// Resolve source
|
|
118
128
|
const resolvedSource = useMemo(() => resolveSource(source), [source]);
|
|
@@ -172,7 +182,7 @@ export const LottieView = /*#__PURE__*/forwardRef((props, ref) => {
|
|
|
172
182
|
nativeProps.textFiltersIOS = textFiltersIOS;
|
|
173
183
|
}
|
|
174
184
|
return /*#__PURE__*/_jsx(NativeGraniteLottieView, {
|
|
175
|
-
ref:
|
|
185
|
+
ref: handleRef,
|
|
176
186
|
...nativeProps
|
|
177
187
|
});
|
|
178
188
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","forwardRef","
|
|
1
|
+
{"version":3,"names":["React","forwardRef","useRef","useCallback","useMemo","Image","Platform","NativeGraniteLottieView","Commands","jsx","_jsx","assignRef","ref","value","current","attachImperativeMethods","instance","handle","play","startFrame","endFrame","pause","resume","reset","resolveSource","source","resolved","resolveAssetSource","uri","endsWith","sourceDotLottieURI","sourceURL","startsWith","sourceName","sourceJson","JSON","stringify","LottieView","props","style","progress","speed","duration","loop","autoPlay","resizeMode","renderMode","colorFilters","textFiltersIOS","textFiltersAndroid","enableMergePathsAndroidForKitKatAndAbove","enableSafeModeAndroid","hardwareAccelerationAndroid","cacheComposition","imageAssetsFolder","onAnimationFinish","onAnimationFailure","onAnimationLoaded","onAnimationLoop","testID","restProps","nativeRef","handleRef","resolvedSource","resolvedSpeed","fr","Math","round","op","handleAnimationFinish","event","nativeEvent","isCancelled","handleAnimationFailure","error","handleAnimationLoaded","handleAnimationLoop","nativeProps","undefined","OS","displayName"],"sourceRoot":"../../src","sources":["GraniteLottieView.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,MAAM,EAAEC,WAAW,EAAEC,OAAO,QAAQ,OAAO;AACvE,SAASC,KAAK,EAA6BC,QAAQ,QAAQ,cAAc;AACzE,OAAOC,uBAAuB,IAC5BC,QAAQ,QAIH,oCAAoC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAM5C,SAASC,SAASA,CAAIC,GAA0B,EAAEC,KAAe,EAAE;EACjE,IAAI,OAAOD,GAAG,KAAK,UAAU,EAAE;IAC7BA,GAAG,CAACC,KAAK,CAAC;IACV;EACF;EAEA,IAAID,GAAG,IAAI,IAAI,EAAE;IACfA,GAAG,CAACE,OAAO,GAAGD,KAAK;EACrB;AACF;AAEA,SAASE,uBAAuBA,CAACC,QAAkC,EAA0B;EAC3F,MAAMC,MAAM,GAAGD,QAAkC;EAEjDC,MAAM,CAACC,IAAI,GAAG,CAACC,UAAmB,EAAEC,QAAiB,KAAK;IACxDZ,QAAQ,CAACU,IAAI,CAACF,QAAQ,EAAEG,UAAU,IAAI,CAAC,CAAC,EAAEC,QAAQ,IAAI,CAAC,CAAC,CAAC;EAC3D,CAAC;EACDH,MAAM,CAACI,KAAK,GAAG,MAAM;IACnBb,QAAQ,CAACa,KAAK,CAACL,QAAQ,CAAC;EAC1B,CAAC;EACDC,MAAM,CAACK,MAAM,GAAG,MAAM;IACpBd,QAAQ,CAACc,M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sB,GAAGK,SAAS;IAC3ErB,iBAAiB,EAAEA,iBAAiB,GAAGkB,qBAAqB,GAAGG,SAAS;IACxEpB,eAAe,EAAEA,eAAe,GAAGkB,mBAAmB,GAAGE;EAC3D,CAAC;;EAED;EACA,IAAIxE,QAAQ,CAACyE,EAAE,KAAK,SAAS,EAAE;IAC7BF,WAAW,CAAC5B,kBAAkB,GAAGA,kBAAkB;IACnD4B,WAAW,CAAC3B,wCAAwC,GAAGA,wCAAwC;IAC/F2B,WAAW,CAAC1B,qBAAqB,GAAGA,qBAAqB;IACzD0B,WAAW,CAACzB,2BAA2B,GAAGA,2BAA2B;EACvE,CAAC,MAAM,IAAI9C,QAAQ,CAACyE,EAAE,KAAK,KAAK,EAAE;IAChCF,WAAW,CAAC7B,cAAc,GAAGA,cAAc;EAC7C;EAEA,oBAAOtC,IAAA,CAACH,uBAAuB;IAACK,GAAG,EAAEkD,SAAU;IAAA,GAAKe;EAAW,CAAG,CAAC;AACrE,CAAC,CAAC;AAEFxC,UAAU,CAAC2C,WAAW,GAAG,YAAY","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { forwardRef,
|
|
1
|
+
import React, { forwardRef, useRef, useCallback, useMemo } from 'react';
|
|
2
2
|
import { Image, type NativeSyntheticEvent, Platform } from 'react-native';
|
|
3
3
|
import NativeGraniteLottieView, {
|
|
4
4
|
Commands,
|
|
@@ -8,6 +8,39 @@ import NativeGraniteLottieView, {
|
|
|
8
8
|
} from './GraniteLottieViewNativeComponent';
|
|
9
9
|
import type { LottieViewProps, LottieViewRef, AnimationSource, AnimationObject } from './types';
|
|
10
10
|
|
|
11
|
+
type NativeLottieViewInstance = React.ElementRef<typeof NativeGraniteLottieView>;
|
|
12
|
+
type NativeLottieViewHandle = NativeLottieViewInstance & LottieViewRef;
|
|
13
|
+
|
|
14
|
+
function assignRef<T>(ref: React.ForwardedRef<T>, value: T | null) {
|
|
15
|
+
if (typeof ref === 'function') {
|
|
16
|
+
ref(value);
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (ref != null) {
|
|
21
|
+
ref.current = value;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function attachImperativeMethods(instance: NativeLottieViewInstance): NativeLottieViewHandle {
|
|
26
|
+
const handle = instance as NativeLottieViewHandle;
|
|
27
|
+
|
|
28
|
+
handle.play = (startFrame?: number, endFrame?: number) => {
|
|
29
|
+
Commands.play(instance, startFrame ?? -1, endFrame ?? -1);
|
|
30
|
+
};
|
|
31
|
+
handle.pause = () => {
|
|
32
|
+
Commands.pause(instance);
|
|
33
|
+
};
|
|
34
|
+
handle.resume = () => {
|
|
35
|
+
Commands.resume(instance);
|
|
36
|
+
};
|
|
37
|
+
handle.reset = () => {
|
|
38
|
+
Commands.reset(instance);
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return handle;
|
|
42
|
+
}
|
|
43
|
+
|
|
11
44
|
// Helper to resolve animation source
|
|
12
45
|
function resolveSource(source: AnimationSource): {
|
|
13
46
|
sourceName?: string;
|
|
@@ -85,31 +118,21 @@ export const LottieView = forwardRef<LottieViewRef, LottieViewProps>((props, ref
|
|
|
85
118
|
...restProps
|
|
86
119
|
} = props;
|
|
87
120
|
|
|
88
|
-
const nativeRef = useRef<
|
|
121
|
+
const nativeRef = useRef<NativeLottieViewInstance>(null);
|
|
89
122
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
pause: () => {
|
|
98
|
-
if (nativeRef.current) {
|
|
99
|
-
Commands.pause(nativeRef.current);
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
resume: () => {
|
|
103
|
-
if (nativeRef.current) {
|
|
104
|
-
Commands.resume(nativeRef.current);
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
reset: () => {
|
|
108
|
-
if (nativeRef.current) {
|
|
109
|
-
Commands.reset(nativeRef.current);
|
|
123
|
+
const handleRef = useCallback(
|
|
124
|
+
(instance: NativeLottieViewInstance | null) => {
|
|
125
|
+
nativeRef.current = instance;
|
|
126
|
+
|
|
127
|
+
if (instance == null) {
|
|
128
|
+
assignRef(ref, null);
|
|
129
|
+
return;
|
|
110
130
|
}
|
|
131
|
+
|
|
132
|
+
assignRef(ref, attachImperativeMethods(instance));
|
|
111
133
|
},
|
|
112
|
-
|
|
134
|
+
[ref]
|
|
135
|
+
);
|
|
113
136
|
|
|
114
137
|
// Resolve source
|
|
115
138
|
const resolvedSource = useMemo(() => resolveSource(source), [source]);
|
|
@@ -176,8 +199,7 @@ export const LottieView = forwardRef<LottieViewRef, LottieViewProps>((props, ref
|
|
|
176
199
|
nativeProps.textFiltersIOS = textFiltersIOS;
|
|
177
200
|
}
|
|
178
201
|
|
|
179
|
-
return <NativeGraniteLottieView ref={
|
|
180
|
-
|
|
202
|
+
return <NativeGraniteLottieView ref={handleRef} {...nativeProps} />;
|
|
181
203
|
});
|
|
182
204
|
|
|
183
205
|
LottieView.displayName = 'LottieView';
|