1 | import { Platform } from 'react-native';
|
2 |
|
3 | let memo = {};
|
4 | export function clearMemo() {
|
5 | memo = {};
|
6 | }
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function getSupportedFunction(supportedPlatforms, getter, defaultGetter) {
|
15 | let supportedMap = {};
|
16 | supportedPlatforms.filter(key => Platform.OS == key).forEach(key => supportedMap[key] = getter);
|
17 | return Platform.select({ ...supportedMap,
|
18 | default: defaultGetter
|
19 | });
|
20 | }
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 | export function getSupportedPlatformInfoSync({
|
28 | getter,
|
29 | supportedPlatforms,
|
30 | defaultValue,
|
31 | memoKey
|
32 | }) {
|
33 | if (memoKey && memo[memoKey] != undefined) {
|
34 | return memo[memoKey];
|
35 | } else {
|
36 | const output = getSupportedFunction(supportedPlatforms, getter, () => defaultValue)();
|
37 |
|
38 | if (memoKey) {
|
39 | memo[memoKey] = output;
|
40 | }
|
41 |
|
42 | return output;
|
43 | }
|
44 | }
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | export async function getSupportedPlatformInfoAsync({
|
51 | getter,
|
52 | supportedPlatforms,
|
53 | defaultValue,
|
54 | memoKey
|
55 | }) {
|
56 | if (memoKey && memo[memoKey] != undefined) {
|
57 | return memo[memoKey];
|
58 | } else {
|
59 | const output = await getSupportedFunction(supportedPlatforms, getter, () => Promise.resolve(defaultValue))();
|
60 |
|
61 | if (memoKey) {
|
62 | memo[memoKey] = output;
|
63 | }
|
64 |
|
65 | return output;
|
66 | }
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | export function getSupportedPlatformInfoFunctions({
|
74 | syncGetter,
|
75 | ...asyncParams
|
76 | }) {
|
77 | return [() => getSupportedPlatformInfoAsync(asyncParams), () => getSupportedPlatformInfoSync({ ...asyncParams,
|
78 | getter: syncGetter
|
79 | })];
|
80 | }
|
81 |
|
\ | No newline at end of file |