Skip to content

Commit 045f07b

Browse files
committed
fix: lazily get constants
1 parent 222e4f2 commit 045f07b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/methods.ios.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,14 @@ import type {
1111
} from './types';
1212
import {uniq} from './utils';
1313

14-
const available = NativeModule.getConstants().available;
14+
let available: string[] | undefined = undefined;
15+
16+
function getAvailable() {
17+
if (available === undefined) {
18+
available = NativeModule.getConstants().available;
19+
}
20+
return available;
21+
}
1522

1623
async function openLimitedPhotoLibraryPicker(): Promise<void> {
1724
await NativeModule.openLimitedPhotoLibraryPicker();
@@ -22,13 +29,13 @@ async function openSettings(): Promise<void> {
2229
}
2330

2431
async function check(permission: Permission): Promise<PermissionStatus> {
25-
return available?.includes(permission)
32+
return getAvailable()?.includes(permission)
2633
? (NativeModule.check(permission) as Promise<PermissionStatus>)
2734
: RESULTS.UNAVAILABLE;
2835
}
2936

3037
async function request(permission: Permission): Promise<PermissionStatus> {
31-
return available?.includes(permission)
38+
return getAvailable()?.includes(permission)
3239
? (NativeModule.request(permission) as Promise<PermissionStatus>)
3340
: RESULTS.UNAVAILABLE;
3441
}

0 commit comments

Comments
 (0)