react-native-permission-handler 0.3.0 → 0.3.1

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.
@@ -100,23 +100,53 @@ describe("createRNPEngine", () => {
100
100
  });
101
101
 
102
102
  describe("Permissions constants", () => {
103
- it("resolves to iOS strings (mocked platform)", () => {
103
+ it("resolves cross-platform permissions to iOS strings (mocked platform)", () => {
104
104
  expect(Permissions.CAMERA).toBe("ios.permission.CAMERA");
105
105
  expect(Permissions.MICROPHONE).toBe("ios.permission.MICROPHONE");
106
106
  expect(Permissions.LOCATION_WHEN_IN_USE).toBe("ios.permission.LOCATION_WHEN_IN_USE");
107
+ expect(Permissions.MEDIA_LIBRARY).toBe("ios.permission.MEDIA_LIBRARY");
108
+ expect(Permissions.SPEECH_RECOGNITION).toBe("ios.permission.SPEECH_RECOGNITION");
109
+ expect(Permissions.MOTION).toBe("ios.permission.MOTION");
107
110
  expect(Permissions.NOTIFICATIONS).toBe("notifications");
108
111
  });
109
112
 
110
- it("includes all expected cross-platform permissions", () => {
113
+ it("includes all cross-platform permissions", () => {
111
114
  const keys = Object.keys(Permissions);
112
- expect(keys).toContain("CAMERA");
113
- expect(keys).toContain("MICROPHONE");
114
- expect(keys).toContain("CONTACTS");
115
- expect(keys).toContain("CALENDARS");
116
- expect(keys).toContain("LOCATION_WHEN_IN_USE");
117
- expect(keys).toContain("LOCATION_ALWAYS");
118
- expect(keys).toContain("PHOTO_LIBRARY");
119
- expect(keys).toContain("BLUETOOTH");
120
- expect(keys).toContain("NOTIFICATIONS");
115
+ for (const key of [
116
+ "CAMERA",
117
+ "MICROPHONE",
118
+ "CONTACTS",
119
+ "CALENDARS",
120
+ "CALENDARS_WRITE_ONLY",
121
+ "LOCATION_WHEN_IN_USE",
122
+ "LOCATION_ALWAYS",
123
+ "PHOTO_LIBRARY",
124
+ "PHOTO_LIBRARY_ADD_ONLY",
125
+ "MEDIA_LIBRARY",
126
+ "BLUETOOTH",
127
+ "SPEECH_RECOGNITION",
128
+ "MOTION",
129
+ "NOTIFICATIONS",
130
+ ]) {
131
+ expect(keys).toContain(key);
132
+ }
133
+ });
134
+
135
+ it("includes iOS-only permissions", () => {
136
+ expect(Permissions.IOS.FACE_ID).toBe("ios.permission.FACE_ID");
137
+ expect(Permissions.IOS.APP_TRACKING_TRANSPARENCY).toBe(
138
+ "ios.permission.APP_TRACKING_TRANSPARENCY",
139
+ );
140
+ expect(Permissions.IOS.SIRI).toBe("ios.permission.SIRI");
141
+ expect(Permissions.IOS.REMINDERS).toBe("ios.permission.REMINDERS");
142
+ expect(Permissions.IOS.STOREKIT).toBe("ios.permission.STOREKIT");
143
+ });
144
+
145
+ it("includes Android-only permissions", () => {
146
+ expect(Permissions.ANDROID.BODY_SENSORS).toBe("android.permission.BODY_SENSORS");
147
+ expect(Permissions.ANDROID.CALL_PHONE).toBe("android.permission.CALL_PHONE");
148
+ expect(Permissions.ANDROID.READ_SMS).toBe("android.permission.READ_SMS");
149
+ expect(Permissions.ANDROID.BLUETOOTH_SCAN).toBe("android.permission.BLUETOOTH_SCAN");
150
+ expect(Permissions.ANDROID.READ_MEDIA_VIDEO).toBe("android.permission.READ_MEDIA_VIDEO");
121
151
  });
122
152
  });
@@ -14,10 +14,11 @@ function p(ios: string, android: string): string {
14
14
  }
15
15
 
16
16
  /**
17
- * Cross-platform permission constants for use with the RNP engine.
18
- * Each resolves to the correct platform-specific string at runtime.
17
+ * Cross-platform permission constants that resolve to the correct
18
+ * platform-specific string at runtime via Platform.select.
19
19
  */
20
20
  export const Permissions = {
21
+ // Cross-platform
21
22
  CAMERA: p("ios.permission.CAMERA", "android.permission.CAMERA"),
22
23
  MICROPHONE: p("ios.permission.MICROPHONE", "android.permission.RECORD_AUDIO"),
23
24
  CONTACTS: p("ios.permission.CONTACTS", "android.permission.READ_CONTACTS"),
@@ -39,8 +40,55 @@ export const Permissions = {
39
40
  "ios.permission.PHOTO_LIBRARY_ADD_ONLY",
40
41
  "android.permission.WRITE_EXTERNAL_STORAGE",
41
42
  ),
43
+ MEDIA_LIBRARY: p("ios.permission.MEDIA_LIBRARY", "android.permission.READ_MEDIA_AUDIO"),
42
44
  BLUETOOTH: p("ios.permission.BLUETOOTH", "android.permission.BLUETOOTH_CONNECT"),
45
+ SPEECH_RECOGNITION: p("ios.permission.SPEECH_RECOGNITION", "android.permission.RECORD_AUDIO"),
46
+ MOTION: p("ios.permission.MOTION", "android.permission.ACTIVITY_RECOGNITION"),
43
47
  NOTIFICATIONS: "notifications",
48
+
49
+ // iOS-only
50
+ IOS: {
51
+ APP_TRACKING_TRANSPARENCY: "ios.permission.APP_TRACKING_TRANSPARENCY",
52
+ FACE_ID: "ios.permission.FACE_ID",
53
+ REMINDERS: "ios.permission.REMINDERS",
54
+ SIRI: "ios.permission.SIRI",
55
+ STOREKIT: "ios.permission.STOREKIT",
56
+ },
57
+
58
+ // Android-only
59
+ ANDROID: {
60
+ ACCEPT_HANDOVER: "android.permission.ACCEPT_HANDOVER",
61
+ ACCESS_COARSE_LOCATION: "android.permission.ACCESS_COARSE_LOCATION",
62
+ ACCESS_MEDIA_LOCATION: "android.permission.ACCESS_MEDIA_LOCATION",
63
+ ADD_VOICEMAIL: "com.android.voicemail.permission.ADD_VOICEMAIL",
64
+ ANSWER_PHONE_CALLS: "android.permission.ANSWER_PHONE_CALLS",
65
+ BLUETOOTH_ADVERTISE: "android.permission.BLUETOOTH_ADVERTISE",
66
+ BLUETOOTH_SCAN: "android.permission.BLUETOOTH_SCAN",
67
+ BODY_SENSORS: "android.permission.BODY_SENSORS",
68
+ BODY_SENSORS_BACKGROUND: "android.permission.BODY_SENSORS_BACKGROUND",
69
+ CALL_PHONE: "android.permission.CALL_PHONE",
70
+ GET_ACCOUNTS: "android.permission.GET_ACCOUNTS",
71
+ NEARBY_WIFI_DEVICES: "android.permission.NEARBY_WIFI_DEVICES",
72
+ PROCESS_OUTGOING_CALLS: "android.permission.PROCESS_OUTGOING_CALLS",
73
+ READ_CALL_LOG: "android.permission.READ_CALL_LOG",
74
+ READ_EXTERNAL_STORAGE: "android.permission.READ_EXTERNAL_STORAGE",
75
+ READ_MEDIA_AUDIO: "android.permission.READ_MEDIA_AUDIO",
76
+ READ_MEDIA_IMAGES: "android.permission.READ_MEDIA_IMAGES",
77
+ READ_MEDIA_VIDEO: "android.permission.READ_MEDIA_VIDEO",
78
+ READ_MEDIA_VISUAL_USER_SELECTED: "android.permission.READ_MEDIA_VISUAL_USER_SELECTED",
79
+ READ_PHONE_NUMBERS: "android.permission.READ_PHONE_NUMBERS",
80
+ READ_PHONE_STATE: "android.permission.READ_PHONE_STATE",
81
+ READ_SMS: "android.permission.READ_SMS",
82
+ RECEIVE_MMS: "android.permission.RECEIVE_MMS",
83
+ RECEIVE_SMS: "android.permission.RECEIVE_SMS",
84
+ RECEIVE_WAP_PUSH: "android.permission.RECEIVE_WAP_PUSH",
85
+ SEND_SMS: "android.permission.SEND_SMS",
86
+ USE_SIP: "android.permission.USE_SIP",
87
+ UWB_RANGING: "android.permission.UWB_RANGING",
88
+ WRITE_CALL_LOG: "android.permission.WRITE_CALL_LOG",
89
+ WRITE_CONTACTS: "android.permission.WRITE_CONTACTS",
90
+ WRITE_EXTERNAL_STORAGE: "android.permission.WRITE_EXTERNAL_STORAGE",
91
+ },
44
92
  } as const;
45
93
 
46
94
  export function createRNPEngine(): PermissionEngine {
@@ -1,81 +0,0 @@
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
@@ -1 +0,0 @@
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":[]}