-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
/
utils.ts
37 lines (29 loc) · 830 Bytes
/
utils.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
import { Image } from 'react-native';
function parsePossibleSources(source):
| {
sourceURL?: string;
sourceJson?: string;
sourceName?: string;
sourceDotLottieURI?: string;
}
| undefined {
const uri = (source as any).uri;
if (typeof source === 'string') {
return { sourceName: source };
}
if (typeof source === 'object' && !uri) {
return { sourceJson: JSON.stringify(source) };
}
if (typeof source === 'object' && uri) {
// uri contains .lottie extension return sourceDotLottieURI
if (uri.includes('.lottie')) {
return { sourceDotLottieURI: uri };
}
return { sourceURL: uri };
}
if (typeof source === 'number') {
return { sourceDotLottieURI: Image.resolveAssetSource(source).uri };
}
return undefined;
}
export { parsePossibleSources };