@teamnhz/rn-ui-toolkit 1.0.6 → 1.0.7
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/dist/utils/permissions.d.ts +7 -4
- package/dist/utils/permissions.js +56 -19
- package/package.json +1 -1
|
@@ -4,15 +4,18 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export declare const requestDocumentPermission: () => Promise<boolean>;
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* 📸 CAMERA PERMISSION
|
|
8
8
|
*/
|
|
9
9
|
export declare const cameraPermissions: (callback: (status: boolean) => void) => Promise<void>;
|
|
10
10
|
/**
|
|
11
|
-
* 🎤
|
|
11
|
+
* 🎤 MICROPHONE PERMISSION
|
|
12
12
|
*/
|
|
13
13
|
export declare const checkMicroPhonePermission: () => Promise<boolean>;
|
|
14
14
|
/**
|
|
15
|
-
* 🖼️
|
|
16
|
-
* ✅ Handles Android < 13 and >= 13
|
|
15
|
+
* 🖼️ GALLERY / STORAGE PERMISSION
|
|
17
16
|
*/
|
|
18
17
|
export declare const galleryPermissions: (callback: (status: boolean) => void) => Promise<void>;
|
|
18
|
+
/**
|
|
19
|
+
* 🔔 Show alert and open Settings if user accepts
|
|
20
|
+
*/
|
|
21
|
+
export declare const settingAlert: (message?: string) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Platform, PermissionsAndroid } from 'react-native';
|
|
1
|
+
import { Platform, PermissionsAndroid, Alert, Linking } from 'react-native';
|
|
2
2
|
import { request, PERMISSIONS, RESULTS } from 'react-native-permissions';
|
|
3
3
|
/**
|
|
4
4
|
* Request storage/doc access permissions cross-platform.
|
|
@@ -36,71 +36,108 @@ export const requestDocumentPermission = async () => {
|
|
|
36
36
|
}
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
|
-
*
|
|
39
|
+
* 📸 CAMERA PERMISSION
|
|
40
40
|
*/
|
|
41
41
|
export const cameraPermissions = async (callback) => {
|
|
42
42
|
try {
|
|
43
|
-
if (Platform.OS ===
|
|
43
|
+
if (Platform.OS === "ios") {
|
|
44
44
|
const result = await request(PERMISSIONS.IOS.CAMERA);
|
|
45
|
-
|
|
45
|
+
if (result === RESULTS.GRANTED)
|
|
46
|
+
return callback(true);
|
|
47
|
+
if (result === RESULTS.BLOCKED)
|
|
48
|
+
settingAlert("Camera access is blocked");
|
|
49
|
+
callback(false);
|
|
46
50
|
}
|
|
47
51
|
else {
|
|
48
52
|
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.CAMERA);
|
|
49
|
-
|
|
53
|
+
if (result === PermissionsAndroid.RESULTS.GRANTED) {
|
|
54
|
+
callback(true);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
settingAlert("Camera permission is required to take photos");
|
|
58
|
+
callback(false);
|
|
59
|
+
}
|
|
50
60
|
}
|
|
51
61
|
}
|
|
52
62
|
catch (error) {
|
|
53
|
-
console.log(
|
|
63
|
+
console.log("Camera Permission Error:", error);
|
|
54
64
|
callback(false);
|
|
55
65
|
}
|
|
56
66
|
};
|
|
57
67
|
/**
|
|
58
|
-
* 🎤
|
|
68
|
+
* 🎤 MICROPHONE PERMISSION
|
|
59
69
|
*/
|
|
60
70
|
export const checkMicroPhonePermission = async () => {
|
|
61
71
|
try {
|
|
62
|
-
if (Platform.OS ===
|
|
72
|
+
if (Platform.OS === "ios") {
|
|
63
73
|
const result = await request(PERMISSIONS.IOS.MICROPHONE);
|
|
74
|
+
if (result === RESULTS.BLOCKED)
|
|
75
|
+
settingAlert("Microphone is blocked");
|
|
64
76
|
return result === RESULTS.GRANTED;
|
|
65
77
|
}
|
|
66
78
|
else {
|
|
67
79
|
const result = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO);
|
|
80
|
+
if (result !== PermissionsAndroid.RESULTS.GRANTED)
|
|
81
|
+
settingAlert("Microphone permission is required for video recording");
|
|
68
82
|
return result === PermissionsAndroid.RESULTS.GRANTED;
|
|
69
83
|
}
|
|
70
84
|
}
|
|
71
85
|
catch (error) {
|
|
72
|
-
console.log(
|
|
86
|
+
console.log("Microphone Permission Error:", error);
|
|
73
87
|
return false;
|
|
74
88
|
}
|
|
75
89
|
};
|
|
76
90
|
/**
|
|
77
|
-
* 🖼️
|
|
78
|
-
* ✅ Handles Android < 13 and >= 13
|
|
91
|
+
* 🖼️ GALLERY / STORAGE PERMISSION
|
|
79
92
|
*/
|
|
80
93
|
export const galleryPermissions = async (callback) => {
|
|
81
94
|
try {
|
|
82
|
-
if (Platform.OS ===
|
|
95
|
+
if (Platform.OS === "ios") {
|
|
83
96
|
const result = await request(PERMISSIONS.IOS.PHOTO_LIBRARY);
|
|
84
|
-
|
|
97
|
+
if (result === RESULTS.GRANTED)
|
|
98
|
+
return callback(true);
|
|
99
|
+
if (result === RESULTS.BLOCKED)
|
|
100
|
+
settingAlert("Photo library access is blocked");
|
|
101
|
+
callback(false);
|
|
85
102
|
}
|
|
86
103
|
else {
|
|
87
104
|
const androidVersion = Platform.Version;
|
|
88
105
|
if (androidVersion >= 33) {
|
|
89
|
-
// 👉 Android 13+ requires READ_MEDIA permissions
|
|
90
106
|
const imagePermission = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_MEDIA_IMAGES);
|
|
91
107
|
const videoPermission = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_MEDIA_VIDEO);
|
|
92
|
-
|
|
93
|
-
videoPermission === PermissionsAndroid.RESULTS.GRANTED
|
|
108
|
+
const granted = imagePermission === PermissionsAndroid.RESULTS.GRANTED ||
|
|
109
|
+
videoPermission === PermissionsAndroid.RESULTS.GRANTED;
|
|
110
|
+
if (!granted)
|
|
111
|
+
settingAlert("Storage permission is required to select images");
|
|
112
|
+
callback(granted);
|
|
94
113
|
}
|
|
95
114
|
else {
|
|
96
|
-
// 👉 Below Android 13 needs old storage permission
|
|
97
115
|
const storagePermission = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.READ_EXTERNAL_STORAGE);
|
|
98
|
-
|
|
116
|
+
const granted = storagePermission === PermissionsAndroid.RESULTS.GRANTED;
|
|
117
|
+
if (!granted)
|
|
118
|
+
settingAlert("Storage permission is required to select images");
|
|
119
|
+
callback(granted);
|
|
99
120
|
}
|
|
100
121
|
}
|
|
101
122
|
}
|
|
102
123
|
catch (error) {
|
|
103
|
-
console.log(
|
|
124
|
+
console.log("Gallery Permission Error:", error);
|
|
104
125
|
callback(false);
|
|
105
126
|
}
|
|
106
127
|
};
|
|
128
|
+
/**
|
|
129
|
+
* 🔔 Show alert and open Settings if user accepts
|
|
130
|
+
*/
|
|
131
|
+
export const settingAlert = (message = "Permission is required") => {
|
|
132
|
+
Alert.alert("Permission Required", message + "\nPlease enable it from settings to continue.", [
|
|
133
|
+
{ text: "Cancel", style: "cancel" },
|
|
134
|
+
{
|
|
135
|
+
text: "Go to Settings",
|
|
136
|
+
onPress: () => {
|
|
137
|
+
Linking.openSettings().catch(() => {
|
|
138
|
+
Alert.alert("Error", "Unable to open settings");
|
|
139
|
+
});
|
|
140
|
+
},
|
|
141
|
+
},
|
|
142
|
+
]);
|
|
143
|
+
};
|