react-native-permission-handler 0.2.0 → 0.3.0
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/README.md +73 -6
- package/dist/chunk-EU3KPRTI.mjs +81 -0
- package/dist/chunk-EU3KPRTI.mjs.map +1 -0
- package/dist/engines/expo.d.mts +1 -1
- package/dist/engines/expo.d.ts +1 -1
- package/dist/engines/rnp.d.mts +19 -2
- package/dist/engines/rnp.d.ts +19 -2
- package/dist/engines/rnp.js +31 -0
- package/dist/engines/rnp.js.map +1 -1
- package/dist/engines/rnp.mjs +3 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +214 -62
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +166 -44
- package/dist/index.mjs.map +1 -1
- package/dist/{types-QXyq8VnD.d.mts → types-DwqbbLGD.d.mts} +6 -0
- package/dist/{types-QXyq8VnD.d.ts → types-DwqbbLGD.d.ts} +6 -0
- package/package.json +1 -1
- package/src/core/debug-logger.test.ts +67 -0
- package/src/core/debug-logger.ts +29 -0
- package/src/core/with-timeout.test.ts +82 -0
- package/src/core/with-timeout.ts +34 -0
- package/src/engines/rnp.test.ts +27 -1
- package/src/engines/rnp.ts +35 -0
- package/src/hooks/use-multiple-permissions.ts +71 -29
- package/src/hooks/use-permission-handler.ts +60 -14
- package/src/types.ts +6 -0
- package/dist/chunk-WZJOIVOM.mjs +0 -49
- package/dist/chunk-WZJOIVOM.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -26,11 +26,11 @@ npm install react-native-permissions
|
|
|
26
26
|
|
|
27
27
|
```tsx
|
|
28
28
|
import { usePermissionHandler } from "react-native-permission-handler";
|
|
29
|
-
import {
|
|
29
|
+
import { Permissions } from "react-native-permission-handler/rnp";
|
|
30
30
|
|
|
31
31
|
function QRScannerScreen() {
|
|
32
32
|
const camera = usePermissionHandler({
|
|
33
|
-
permission:
|
|
33
|
+
permission: Permissions.CAMERA,
|
|
34
34
|
prePrompt: {
|
|
35
35
|
title: "Camera Access",
|
|
36
36
|
message: "We need your camera to scan QR codes.",
|
|
@@ -209,6 +209,9 @@ The main hook. Manages the full permission lifecycle.
|
|
|
209
209
|
// Options
|
|
210
210
|
autoCheck?: boolean; // default: true — check on mount
|
|
211
211
|
recheckOnForeground?: boolean; // default: false
|
|
212
|
+
requestTimeout?: number; // timeout for request() in ms (opt-in)
|
|
213
|
+
onTimeout?: () => void; // called if request() times out
|
|
214
|
+
debug?: boolean | ((msg: string) => void); // log state transitions
|
|
212
215
|
}
|
|
213
216
|
```
|
|
214
217
|
|
|
@@ -239,7 +242,7 @@ The main hook. Manages the full permission lifecycle.
|
|
|
239
242
|
```tsx
|
|
240
243
|
function CameraScreen() {
|
|
241
244
|
const camera = usePermissionHandler({
|
|
242
|
-
permission:
|
|
245
|
+
permission: Permissions.CAMERA,
|
|
243
246
|
prePrompt: {
|
|
244
247
|
title: "Camera Access",
|
|
245
248
|
message: "We need your camera to scan QR codes.",
|
|
@@ -302,6 +305,9 @@ Orchestrates flows for features needing multiple permissions (e.g., video call =
|
|
|
302
305
|
|
|
303
306
|
engine?: PermissionEngine; // optional — overrides global/fallback
|
|
304
307
|
autoCheck?: boolean; // default: true — check all on mount
|
|
308
|
+
requestTimeout?: number; // timeout for request() in ms (opt-in)
|
|
309
|
+
onTimeout?: () => void; // called if any request() times out
|
|
310
|
+
debug?: boolean | ((msg: string) => void); // log state transitions
|
|
305
311
|
onAllGranted?: () => void;
|
|
306
312
|
}
|
|
307
313
|
```
|
|
@@ -323,12 +329,12 @@ function VideoCallScreen() {
|
|
|
323
329
|
const perms = useMultiplePermissions({
|
|
324
330
|
permissions: [
|
|
325
331
|
{
|
|
326
|
-
permission:
|
|
332
|
+
permission: Permissions.CAMERA,
|
|
327
333
|
prePrompt: { title: "Camera", message: "Needed for video." },
|
|
328
334
|
blockedPrompt: { title: "Camera Blocked", message: "Enable in Settings." },
|
|
329
335
|
},
|
|
330
336
|
{
|
|
331
|
-
permission:
|
|
337
|
+
permission: Permissions.MICROPHONE,
|
|
332
338
|
prePrompt: { title: "Microphone", message: "Needed for audio." },
|
|
333
339
|
blockedPrompt: { title: "Mic Blocked", message: "Enable in Settings." },
|
|
334
340
|
},
|
|
@@ -381,7 +387,7 @@ Declarative component that renders children only when permission is granted.
|
|
|
381
387
|
|
|
382
388
|
```tsx
|
|
383
389
|
<PermissionGate
|
|
384
|
-
permission={
|
|
390
|
+
permission={Permissions.CAMERA}
|
|
385
391
|
prePrompt={{ title: "Camera", message: "We need camera access." }}
|
|
386
392
|
blockedPrompt={{ title: "Blocked", message: "Enable in Settings." }}
|
|
387
393
|
fallback={<LoadingSpinner />}
|
|
@@ -464,6 +470,29 @@ You don't need to call this explicitly if `react-native-permissions` is installe
|
|
|
464
470
|
|
|
465
471
|
---
|
|
466
472
|
|
|
473
|
+
### `Permissions` (cross-platform constants)
|
|
474
|
+
|
|
475
|
+
The RNP entry point also exports cross-platform permission constants that resolve to the correct platform-specific string via `Platform.select`:
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
import { Permissions } from "react-native-permission-handler/rnp";
|
|
479
|
+
|
|
480
|
+
Permissions.CAMERA // ios: "ios.permission.CAMERA", android: "android.permission.CAMERA"
|
|
481
|
+
Permissions.MICROPHONE // ios: "ios.permission.MICROPHONE", android: "android.permission.RECORD_AUDIO"
|
|
482
|
+
Permissions.CONTACTS // ios: "ios.permission.CONTACTS", android: "android.permission.READ_CONTACTS"
|
|
483
|
+
Permissions.CALENDARS // ios: "ios.permission.CALENDARS", android: "android.permission.READ_CALENDAR"
|
|
484
|
+
Permissions.LOCATION_WHEN_IN_USE
|
|
485
|
+
Permissions.LOCATION_ALWAYS
|
|
486
|
+
Permissions.PHOTO_LIBRARY
|
|
487
|
+
Permissions.PHOTO_LIBRARY_ADD_ONLY
|
|
488
|
+
Permissions.BLUETOOTH
|
|
489
|
+
Permissions.NOTIFICATIONS // "notifications" (routed to notification-specific APIs by the engine)
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
For platform-specific permissions not in this map, pass the raw string directly (e.g., `"ios.permission.FACE_ID"`).
|
|
493
|
+
|
|
494
|
+
---
|
|
495
|
+
|
|
467
496
|
### `createExpoEngine(config)`
|
|
468
497
|
|
|
469
498
|
Create an engine adapter for Expo permission modules. Pass a map of permission keys to Expo modules.
|
|
@@ -515,6 +544,44 @@ The engine is responsible for:
|
|
|
515
544
|
- Handling special cases like notifications internally
|
|
516
545
|
- Opening the correct settings screen
|
|
517
546
|
|
|
547
|
+
## Debugging & Reliability
|
|
548
|
+
|
|
549
|
+
### Request Timeout
|
|
550
|
+
|
|
551
|
+
On Android 16, `request()` can hang indefinitely when a permission is in `never_ask_again` state ([facebook/react-native#53887](https://github.com/facebook/react-native/issues/53887)). Enable `requestTimeout` to recover:
|
|
552
|
+
|
|
553
|
+
```tsx
|
|
554
|
+
const camera = usePermissionHandler({
|
|
555
|
+
permission: Permissions.CAMERA,
|
|
556
|
+
requestTimeout: 15000, // 15 seconds
|
|
557
|
+
onTimeout: () => console.warn("Permission request timed out"),
|
|
558
|
+
prePrompt: { title: "Camera", message: "..." },
|
|
559
|
+
blockedPrompt: { title: "Blocked", message: "..." },
|
|
560
|
+
});
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
On timeout, the hook transitions to `blockedPrompt` (since the hanging bug only occurs for already-blocked permissions) and fires `onTimeout`.
|
|
564
|
+
|
|
565
|
+
### Debug Logging
|
|
566
|
+
|
|
567
|
+
Enable `debug` to log state transitions — useful for bug reports and support workflows:
|
|
568
|
+
|
|
569
|
+
```tsx
|
|
570
|
+
const camera = usePermissionHandler({
|
|
571
|
+
permission: Permissions.CAMERA,
|
|
572
|
+
debug: true,
|
|
573
|
+
// ...
|
|
574
|
+
});
|
|
575
|
+
// Console: [permission-handler] camera: idle → checking (CHECK)
|
|
576
|
+
// Console: [permission-handler] camera: checking → prePrompt (CHECK_RESULT:denied)
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
Pass a function to route logs to your own logger:
|
|
580
|
+
|
|
581
|
+
```tsx
|
|
582
|
+
debug: (msg) => Sentry.addBreadcrumb({ message: msg, category: "permissions" })
|
|
583
|
+
```
|
|
584
|
+
|
|
518
585
|
## Platform Notes
|
|
519
586
|
|
|
520
587
|
**iOS:**
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__esm,
|
|
3
|
+
__export
|
|
4
|
+
} from "./chunk-NFEGQTCC.mjs";
|
|
5
|
+
|
|
6
|
+
// src/engines/rnp.ts
|
|
7
|
+
var rnp_exports = {};
|
|
8
|
+
__export(rnp_exports, {
|
|
9
|
+
Permissions: () => Permissions,
|
|
10
|
+
createRNPEngine: () => createRNPEngine
|
|
11
|
+
});
|
|
12
|
+
import { Platform } from "react-native";
|
|
13
|
+
import {
|
|
14
|
+
check,
|
|
15
|
+
checkNotifications,
|
|
16
|
+
openSettings,
|
|
17
|
+
request,
|
|
18
|
+
requestNotifications
|
|
19
|
+
} from "react-native-permissions";
|
|
20
|
+
function p(ios, android) {
|
|
21
|
+
return Platform.select({ ios, android, default: ios }) ?? ios;
|
|
22
|
+
}
|
|
23
|
+
function createRNPEngine() {
|
|
24
|
+
return {
|
|
25
|
+
async check(permission) {
|
|
26
|
+
if (permission === "notifications") {
|
|
27
|
+
const result = await checkNotifications();
|
|
28
|
+
return result.status;
|
|
29
|
+
}
|
|
30
|
+
return await check(permission);
|
|
31
|
+
},
|
|
32
|
+
async request(permission) {
|
|
33
|
+
if (permission === "notifications") {
|
|
34
|
+
const result = await requestNotifications(["alert", "badge", "sound"]);
|
|
35
|
+
return result.status;
|
|
36
|
+
}
|
|
37
|
+
return await request(permission);
|
|
38
|
+
},
|
|
39
|
+
async openSettings() {
|
|
40
|
+
await openSettings();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var Permissions;
|
|
45
|
+
var init_rnp = __esm({
|
|
46
|
+
"src/engines/rnp.ts"() {
|
|
47
|
+
Permissions = {
|
|
48
|
+
CAMERA: p("ios.permission.CAMERA", "android.permission.CAMERA"),
|
|
49
|
+
MICROPHONE: p("ios.permission.MICROPHONE", "android.permission.RECORD_AUDIO"),
|
|
50
|
+
CONTACTS: p("ios.permission.CONTACTS", "android.permission.READ_CONTACTS"),
|
|
51
|
+
CALENDARS: p("ios.permission.CALENDARS", "android.permission.READ_CALENDAR"),
|
|
52
|
+
CALENDARS_WRITE_ONLY: p(
|
|
53
|
+
"ios.permission.CALENDARS_WRITE_ONLY",
|
|
54
|
+
"android.permission.WRITE_CALENDAR"
|
|
55
|
+
),
|
|
56
|
+
LOCATION_WHEN_IN_USE: p(
|
|
57
|
+
"ios.permission.LOCATION_WHEN_IN_USE",
|
|
58
|
+
"android.permission.ACCESS_FINE_LOCATION"
|
|
59
|
+
),
|
|
60
|
+
LOCATION_ALWAYS: p(
|
|
61
|
+
"ios.permission.LOCATION_ALWAYS",
|
|
62
|
+
"android.permission.ACCESS_BACKGROUND_LOCATION"
|
|
63
|
+
),
|
|
64
|
+
PHOTO_LIBRARY: p("ios.permission.PHOTO_LIBRARY", "android.permission.READ_MEDIA_IMAGES"),
|
|
65
|
+
PHOTO_LIBRARY_ADD_ONLY: p(
|
|
66
|
+
"ios.permission.PHOTO_LIBRARY_ADD_ONLY",
|
|
67
|
+
"android.permission.WRITE_EXTERNAL_STORAGE"
|
|
68
|
+
),
|
|
69
|
+
BLUETOOTH: p("ios.permission.BLUETOOTH", "android.permission.BLUETOOTH_CONNECT"),
|
|
70
|
+
NOTIFICATIONS: "notifications"
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
export {
|
|
76
|
+
Permissions,
|
|
77
|
+
createRNPEngine,
|
|
78
|
+
rnp_exports,
|
|
79
|
+
init_rnp
|
|
80
|
+
};
|
|
81
|
+
//# sourceMappingURL=chunk-EU3KPRTI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/engines/rnp.ts"],"sourcesContent":["import { Platform } from \"react-native\";\nimport {\n type Permission,\n check,\n checkNotifications,\n openSettings,\n request,\n requestNotifications,\n} from \"react-native-permissions\";\nimport type { PermissionEngine, PermissionStatus } from \"../types\";\n\nfunction p(ios: string, android: string): string {\n return Platform.select({ ios, android, default: ios }) ?? ios;\n}\n\n/**\n * Cross-platform permission constants for use with the RNP engine.\n * Each resolves to the correct platform-specific string at runtime.\n */\nexport const Permissions = {\n CAMERA: p(\"ios.permission.CAMERA\", \"android.permission.CAMERA\"),\n MICROPHONE: p(\"ios.permission.MICROPHONE\", \"android.permission.RECORD_AUDIO\"),\n CONTACTS: p(\"ios.permission.CONTACTS\", \"android.permission.READ_CONTACTS\"),\n CALENDARS: p(\"ios.permission.CALENDARS\", \"android.permission.READ_CALENDAR\"),\n CALENDARS_WRITE_ONLY: p(\n \"ios.permission.CALENDARS_WRITE_ONLY\",\n \"android.permission.WRITE_CALENDAR\",\n ),\n LOCATION_WHEN_IN_USE: p(\n \"ios.permission.LOCATION_WHEN_IN_USE\",\n \"android.permission.ACCESS_FINE_LOCATION\",\n ),\n LOCATION_ALWAYS: p(\n \"ios.permission.LOCATION_ALWAYS\",\n \"android.permission.ACCESS_BACKGROUND_LOCATION\",\n ),\n PHOTO_LIBRARY: p(\"ios.permission.PHOTO_LIBRARY\", \"android.permission.READ_MEDIA_IMAGES\"),\n PHOTO_LIBRARY_ADD_ONLY: p(\n \"ios.permission.PHOTO_LIBRARY_ADD_ONLY\",\n \"android.permission.WRITE_EXTERNAL_STORAGE\",\n ),\n BLUETOOTH: p(\"ios.permission.BLUETOOTH\", \"android.permission.BLUETOOTH_CONNECT\"),\n NOTIFICATIONS: \"notifications\",\n} as const;\n\nexport function createRNPEngine(): PermissionEngine {\n return {\n async check(permission: string): Promise<PermissionStatus> {\n if (permission === \"notifications\") {\n const result = await checkNotifications();\n return result.status as PermissionStatus;\n }\n return (await check(permission as Permission)) as PermissionStatus;\n },\n\n async request(permission: string): Promise<PermissionStatus> {\n if (permission === \"notifications\") {\n const result = await requestNotifications([\"alert\", \"badge\", \"sound\"]);\n return result.status as PermissionStatus;\n }\n return (await request(permission as Permission)) as PermissionStatus;\n },\n\n async openSettings(): Promise<void> {\n await openSettings();\n },\n };\n}\n"],"mappings":";;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAAS,gBAAgB;AACzB;AAAA,EAEE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAGP,SAAS,EAAE,KAAa,SAAyB;AAC/C,SAAO,SAAS,OAAO,EAAE,KAAK,SAAS,SAAS,IAAI,CAAC,KAAK;AAC5D;AAgCO,SAAS,kBAAoC;AAClD,SAAO;AAAA,IACL,MAAM,MAAM,YAA+C;AACzD,UAAI,eAAe,iBAAiB;AAClC,cAAM,SAAS,MAAM,mBAAmB;AACxC,eAAO,OAAO;AAAA,MAChB;AACA,aAAQ,MAAM,MAAM,UAAwB;AAAA,IAC9C;AAAA,IAEA,MAAM,QAAQ,YAA+C;AAC3D,UAAI,eAAe,iBAAiB;AAClC,cAAM,SAAS,MAAM,qBAAqB,CAAC,SAAS,SAAS,OAAO,CAAC;AACrE,eAAO,OAAO;AAAA,MAChB;AACA,aAAQ,MAAM,QAAQ,UAAwB;AAAA,IAChD;AAAA,IAEA,MAAM,eAA8B;AAClC,YAAM,aAAa;AAAA,IACrB;AAAA,EACF;AACF;AAnEA,IAmBa;AAnBb;AAAA;AAmBO,IAAM,cAAc;AAAA,MACzB,QAAQ,EAAE,yBAAyB,2BAA2B;AAAA,MAC9D,YAAY,EAAE,6BAA6B,iCAAiC;AAAA,MAC5E,UAAU,EAAE,2BAA2B,kCAAkC;AAAA,MACzE,WAAW,EAAE,4BAA4B,kCAAkC;AAAA,MAC3E,sBAAsB;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,MACA,sBAAsB;AAAA,QACpB;AAAA,QACA;AAAA,MACF;AAAA,MACA,iBAAiB;AAAA,QACf;AAAA,QACA;AAAA,MACF;AAAA,MACA,eAAe,EAAE,gCAAgC,sCAAsC;AAAA,MACvF,wBAAwB;AAAA,QACtB;AAAA,QACA;AAAA,MACF;AAAA,MACA,WAAW,EAAE,4BAA4B,sCAAsC;AAAA,MAC/E,eAAe;AAAA,IACjB;AAAA;AAAA;","names":[]}
|
package/dist/engines/expo.d.mts
CHANGED
package/dist/engines/expo.d.ts
CHANGED
package/dist/engines/rnp.d.mts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import { P as PermissionEngine } from '../types-
|
|
1
|
+
import { P as PermissionEngine } from '../types-DwqbbLGD.mjs';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Cross-platform permission constants for use with the RNP engine.
|
|
5
|
+
* Each resolves to the correct platform-specific string at runtime.
|
|
6
|
+
*/
|
|
7
|
+
declare const Permissions: {
|
|
8
|
+
readonly CAMERA: string;
|
|
9
|
+
readonly MICROPHONE: string;
|
|
10
|
+
readonly CONTACTS: string;
|
|
11
|
+
readonly CALENDARS: string;
|
|
12
|
+
readonly CALENDARS_WRITE_ONLY: string;
|
|
13
|
+
readonly LOCATION_WHEN_IN_USE: string;
|
|
14
|
+
readonly LOCATION_ALWAYS: string;
|
|
15
|
+
readonly PHOTO_LIBRARY: string;
|
|
16
|
+
readonly PHOTO_LIBRARY_ADD_ONLY: string;
|
|
17
|
+
readonly BLUETOOTH: string;
|
|
18
|
+
readonly NOTIFICATIONS: "notifications";
|
|
19
|
+
};
|
|
3
20
|
declare function createRNPEngine(): PermissionEngine;
|
|
4
21
|
|
|
5
|
-
export { createRNPEngine };
|
|
22
|
+
export { Permissions, createRNPEngine };
|
package/dist/engines/rnp.d.ts
CHANGED
|
@@ -1,5 +1,22 @@
|
|
|
1
|
-
import { P as PermissionEngine } from '../types-
|
|
1
|
+
import { P as PermissionEngine } from '../types-DwqbbLGD.js';
|
|
2
2
|
|
|
3
|
+
/**
|
|
4
|
+
* Cross-platform permission constants for use with the RNP engine.
|
|
5
|
+
* Each resolves to the correct platform-specific string at runtime.
|
|
6
|
+
*/
|
|
7
|
+
declare const Permissions: {
|
|
8
|
+
readonly CAMERA: string;
|
|
9
|
+
readonly MICROPHONE: string;
|
|
10
|
+
readonly CONTACTS: string;
|
|
11
|
+
readonly CALENDARS: string;
|
|
12
|
+
readonly CALENDARS_WRITE_ONLY: string;
|
|
13
|
+
readonly LOCATION_WHEN_IN_USE: string;
|
|
14
|
+
readonly LOCATION_ALWAYS: string;
|
|
15
|
+
readonly PHOTO_LIBRARY: string;
|
|
16
|
+
readonly PHOTO_LIBRARY_ADD_ONLY: string;
|
|
17
|
+
readonly BLUETOOTH: string;
|
|
18
|
+
readonly NOTIFICATIONS: "notifications";
|
|
19
|
+
};
|
|
3
20
|
declare function createRNPEngine(): PermissionEngine;
|
|
4
21
|
|
|
5
|
-
export { createRNPEngine };
|
|
22
|
+
export { Permissions, createRNPEngine };
|
package/dist/engines/rnp.js
CHANGED
|
@@ -20,10 +20,40 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/engines/rnp.ts
|
|
21
21
|
var rnp_exports = {};
|
|
22
22
|
__export(rnp_exports, {
|
|
23
|
+
Permissions: () => Permissions,
|
|
23
24
|
createRNPEngine: () => createRNPEngine
|
|
24
25
|
});
|
|
25
26
|
module.exports = __toCommonJS(rnp_exports);
|
|
27
|
+
var import_react_native = require("react-native");
|
|
26
28
|
var import_react_native_permissions = require("react-native-permissions");
|
|
29
|
+
function p(ios, android) {
|
|
30
|
+
return import_react_native.Platform.select({ ios, android, default: ios }) ?? ios;
|
|
31
|
+
}
|
|
32
|
+
var Permissions = {
|
|
33
|
+
CAMERA: p("ios.permission.CAMERA", "android.permission.CAMERA"),
|
|
34
|
+
MICROPHONE: p("ios.permission.MICROPHONE", "android.permission.RECORD_AUDIO"),
|
|
35
|
+
CONTACTS: p("ios.permission.CONTACTS", "android.permission.READ_CONTACTS"),
|
|
36
|
+
CALENDARS: p("ios.permission.CALENDARS", "android.permission.READ_CALENDAR"),
|
|
37
|
+
CALENDARS_WRITE_ONLY: p(
|
|
38
|
+
"ios.permission.CALENDARS_WRITE_ONLY",
|
|
39
|
+
"android.permission.WRITE_CALENDAR"
|
|
40
|
+
),
|
|
41
|
+
LOCATION_WHEN_IN_USE: p(
|
|
42
|
+
"ios.permission.LOCATION_WHEN_IN_USE",
|
|
43
|
+
"android.permission.ACCESS_FINE_LOCATION"
|
|
44
|
+
),
|
|
45
|
+
LOCATION_ALWAYS: p(
|
|
46
|
+
"ios.permission.LOCATION_ALWAYS",
|
|
47
|
+
"android.permission.ACCESS_BACKGROUND_LOCATION"
|
|
48
|
+
),
|
|
49
|
+
PHOTO_LIBRARY: p("ios.permission.PHOTO_LIBRARY", "android.permission.READ_MEDIA_IMAGES"),
|
|
50
|
+
PHOTO_LIBRARY_ADD_ONLY: p(
|
|
51
|
+
"ios.permission.PHOTO_LIBRARY_ADD_ONLY",
|
|
52
|
+
"android.permission.WRITE_EXTERNAL_STORAGE"
|
|
53
|
+
),
|
|
54
|
+
BLUETOOTH: p("ios.permission.BLUETOOTH", "android.permission.BLUETOOTH_CONNECT"),
|
|
55
|
+
NOTIFICATIONS: "notifications"
|
|
56
|
+
};
|
|
27
57
|
function createRNPEngine() {
|
|
28
58
|
return {
|
|
29
59
|
async check(permission) {
|
|
@@ -47,6 +77,7 @@ function createRNPEngine() {
|
|
|
47
77
|
}
|
|
48
78
|
// Annotate the CommonJS export names for ESM import in node:
|
|
49
79
|
0 && (module.exports = {
|
|
80
|
+
Permissions,
|
|
50
81
|
createRNPEngine
|
|
51
82
|
});
|
|
52
83
|
//# sourceMappingURL=rnp.js.map
|
package/dist/engines/rnp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/engines/rnp.ts"],"sourcesContent":["import {\n type Permission,\n check,\n checkNotifications,\n openSettings,\n request,\n requestNotifications,\n} from \"react-native-permissions\";\nimport type { PermissionEngine, PermissionStatus } from \"../types\";\n\nexport function createRNPEngine(): PermissionEngine {\n return {\n async check(permission: string): Promise<PermissionStatus> {\n if (permission === \"notifications\") {\n const result = await checkNotifications();\n return result.status as PermissionStatus;\n }\n return (await check(permission as Permission)) as PermissionStatus;\n },\n\n async request(permission: string): Promise<PermissionStatus> {\n if (permission === \"notifications\") {\n const result = await requestNotifications([\"alert\", \"badge\", \"sound\"]);\n return result.status as PermissionStatus;\n }\n return (await request(permission as Permission)) as PermissionStatus;\n },\n\n async openSettings(): Promise<void> {\n await openSettings();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sCAOO;
|
|
1
|
+
{"version":3,"sources":["../../src/engines/rnp.ts"],"sourcesContent":["import { Platform } from \"react-native\";\nimport {\n type Permission,\n check,\n checkNotifications,\n openSettings,\n request,\n requestNotifications,\n} from \"react-native-permissions\";\nimport type { PermissionEngine, PermissionStatus } from \"../types\";\n\nfunction p(ios: string, android: string): string {\n return Platform.select({ ios, android, default: ios }) ?? ios;\n}\n\n/**\n * Cross-platform permission constants for use with the RNP engine.\n * Each resolves to the correct platform-specific string at runtime.\n */\nexport const Permissions = {\n CAMERA: p(\"ios.permission.CAMERA\", \"android.permission.CAMERA\"),\n MICROPHONE: p(\"ios.permission.MICROPHONE\", \"android.permission.RECORD_AUDIO\"),\n CONTACTS: p(\"ios.permission.CONTACTS\", \"android.permission.READ_CONTACTS\"),\n CALENDARS: p(\"ios.permission.CALENDARS\", \"android.permission.READ_CALENDAR\"),\n CALENDARS_WRITE_ONLY: p(\n \"ios.permission.CALENDARS_WRITE_ONLY\",\n \"android.permission.WRITE_CALENDAR\",\n ),\n LOCATION_WHEN_IN_USE: p(\n \"ios.permission.LOCATION_WHEN_IN_USE\",\n \"android.permission.ACCESS_FINE_LOCATION\",\n ),\n LOCATION_ALWAYS: p(\n \"ios.permission.LOCATION_ALWAYS\",\n \"android.permission.ACCESS_BACKGROUND_LOCATION\",\n ),\n PHOTO_LIBRARY: p(\"ios.permission.PHOTO_LIBRARY\", \"android.permission.READ_MEDIA_IMAGES\"),\n PHOTO_LIBRARY_ADD_ONLY: p(\n \"ios.permission.PHOTO_LIBRARY_ADD_ONLY\",\n \"android.permission.WRITE_EXTERNAL_STORAGE\",\n ),\n BLUETOOTH: p(\"ios.permission.BLUETOOTH\", \"android.permission.BLUETOOTH_CONNECT\"),\n NOTIFICATIONS: \"notifications\",\n} as const;\n\nexport function createRNPEngine(): PermissionEngine {\n return {\n async check(permission: string): Promise<PermissionStatus> {\n if (permission === \"notifications\") {\n const result = await checkNotifications();\n return result.status as PermissionStatus;\n }\n return (await check(permission as Permission)) as PermissionStatus;\n },\n\n async request(permission: string): Promise<PermissionStatus> {\n if (permission === \"notifications\") {\n const result = await requestNotifications([\"alert\", \"badge\", \"sound\"]);\n return result.status as PermissionStatus;\n }\n return (await request(permission as Permission)) as PermissionStatus;\n },\n\n async openSettings(): Promise<void> {\n await openSettings();\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,0BAAyB;AACzB,sCAOO;AAGP,SAAS,EAAE,KAAa,SAAyB;AAC/C,SAAO,6BAAS,OAAO,EAAE,KAAK,SAAS,SAAS,IAAI,CAAC,KAAK;AAC5D;AAMO,IAAM,cAAc;AAAA,EACzB,QAAQ,EAAE,yBAAyB,2BAA2B;AAAA,EAC9D,YAAY,EAAE,6BAA6B,iCAAiC;AAAA,EAC5E,UAAU,EAAE,2BAA2B,kCAAkC;AAAA,EACzE,WAAW,EAAE,4BAA4B,kCAAkC;AAAA,EAC3E,sBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAAA,EACA,sBAAsB;AAAA,IACpB;AAAA,IACA;AAAA,EACF;AAAA,EACA,iBAAiB;AAAA,IACf;AAAA,IACA;AAAA,EACF;AAAA,EACA,eAAe,EAAE,gCAAgC,sCAAsC;AAAA,EACvF,wBAAwB;AAAA,IACtB;AAAA,IACA;AAAA,EACF;AAAA,EACA,WAAW,EAAE,4BAA4B,sCAAsC;AAAA,EAC/E,eAAe;AACjB;AAEO,SAAS,kBAAoC;AAClD,SAAO;AAAA,IACL,MAAM,MAAM,YAA+C;AACzD,UAAI,eAAe,iBAAiB;AAClC,cAAM,SAAS,UAAM,oDAAmB;AACxC,eAAO,OAAO;AAAA,MAChB;AACA,aAAQ,UAAM,uCAAM,UAAwB;AAAA,IAC9C;AAAA,IAEA,MAAM,QAAQ,YAA+C;AAC3D,UAAI,eAAe,iBAAiB;AAClC,cAAM,SAAS,UAAM,sDAAqB,CAAC,SAAS,SAAS,OAAO,CAAC;AACrE,eAAO,OAAO;AAAA,MAChB;AACA,aAAQ,UAAM,yCAAQ,UAAwB;AAAA,IAChD;AAAA,IAEA,MAAM,eAA8B;AAClC,gBAAM,8CAAa;AAAA,IACrB;AAAA,EACF;AACF;","names":[]}
|
package/dist/engines/rnp.mjs
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
|
+
Permissions,
|
|
2
3
|
createRNPEngine,
|
|
3
4
|
init_rnp
|
|
4
|
-
} from "../chunk-
|
|
5
|
+
} from "../chunk-EU3KPRTI.mjs";
|
|
5
6
|
import "../chunk-NFEGQTCC.mjs";
|
|
6
7
|
init_rnp();
|
|
7
8
|
export {
|
|
9
|
+
Permissions,
|
|
8
10
|
createRNPEngine
|
|
9
11
|
};
|
|
10
12
|
//# sourceMappingURL=rnp.mjs.map
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PermissionEngine, a as PermissionFlowState, b as PermissionFlowEvent, c as PermissionHandlerConfig, d as PermissionHandlerResult, M as MultiplePermissionsConfig, e as MultiplePermissionsResult, f as PermissionCallbacks, g as PrePromptConfig, B as BlockedPromptConfig } from './types-
|
|
2
|
-
export { h as MultiPermissionEntry, i as PermissionStatus } from './types-
|
|
1
|
+
import { P as PermissionEngine, a as PermissionFlowState, b as PermissionFlowEvent, c as PermissionHandlerConfig, d as PermissionHandlerResult, M as MultiplePermissionsConfig, e as MultiplePermissionsResult, f as PermissionCallbacks, g as PrePromptConfig, B as BlockedPromptConfig } from './types-DwqbbLGD.mjs';
|
|
2
|
+
export { h as MultiPermissionEntry, i as PermissionStatus } from './types-DwqbbLGD.mjs';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PermissionEngine, a as PermissionFlowState, b as PermissionFlowEvent, c as PermissionHandlerConfig, d as PermissionHandlerResult, M as MultiplePermissionsConfig, e as MultiplePermissionsResult, f as PermissionCallbacks, g as PrePromptConfig, B as BlockedPromptConfig } from './types-
|
|
2
|
-
export { h as MultiPermissionEntry, i as PermissionStatus } from './types-
|
|
1
|
+
import { P as PermissionEngine, a as PermissionFlowState, b as PermissionFlowEvent, c as PermissionHandlerConfig, d as PermissionHandlerResult, M as MultiplePermissionsConfig, e as MultiplePermissionsResult, f as PermissionCallbacks, g as PrePromptConfig, B as BlockedPromptConfig } from './types-DwqbbLGD.js';
|
|
2
|
+
export { h as MultiPermissionEntry, i as PermissionStatus } from './types-DwqbbLGD.js';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
import { ReactNode } from 'react';
|
|
5
5
|
|