Explorar el Código

Check can now accept a string or an object

Mathieu Acthernoene hace 7 años
padre
commit
e3694e73a3
Se han modificado 5 ficheros con 28 adiciones y 16 borrados
  1. 2
    0
      .prettierignore
  2. 1
    1
      README.md
  3. 4
    3
      lib/permissions.android.js
  4. 18
    9
      lib/permissions.ios.js
  5. 3
    3
      package.json

+ 2
- 0
.prettierignore Ver fichero

1
+android/
2
+ios/
1
 example/node_modules/
3
 example/node_modules/

+ 1
- 1
README.md Ver fichero

10
 
10
 
11
 | Version | React Native Support |
11
 | Version | React Native Support |
12
 | ------- | -------------------- |
12
 | ------- | -------------------- |
13
-| 1.0.4   | 0.40 - 0.50          |
13
+| 1.0.5   | 0.40 - 0.51          |
14
 | 0.2.5   | 0.33 - 0.39          |
14
 | 0.2.5   | 0.33 - 0.39          |
15
 
15
 
16
 _Complies with
16
 _Complies with

+ 4
- 3
lib/permissions.android.js Ver fichero

4
 
4
 
5
 type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
5
 type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
6
 type Rationale = { title: string, message: string }
6
 type Rationale = { title: string, message: string }
7
-type Options = string | { type: string, rationale?: Rationale }
7
+type CheckOptions = string | { type: string }
8
+type RequestOptions = string | { type: string, rationale?: Rationale }
8
 
9
 
9
 const permissionTypes = {
10
 const permissionTypes = {
10
   location: PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
11
   location: PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
41
 
42
 
42
   getTypes: () => Array<string> = () => Object.keys(permissionTypes)
43
   getTypes: () => Array<string> = () => Object.keys(permissionTypes)
43
 
44
 
44
-  check = (permission: string, type?: string): Promise<Status> => {
45
+  check = (permission: string, options?: CheckOptions): Promise<Status> => {
45
     if (!permissionTypes[permission]) {
46
     if (!permissionTypes[permission]) {
46
       const error = new Error(
47
       const error = new Error(
47
         `ReactNativePermissions: ${
48
         `ReactNativePermissions: ${
71
     )
72
     )
72
   }
73
   }
73
 
74
 
74
-  request = (permission: string, options?: Options): Promise<Status> => {
75
+  request = (permission: string, options?: RequestOptions): Promise<Status> => {
75
     if (!permissionTypes[permission]) {
76
     if (!permissionTypes[permission]) {
76
       const error = new Error(
77
       const error = new Error(
77
         `ReactNativePermissions: ${
78
         `ReactNativePermissions: ${

+ 18
- 9
lib/permissions.ios.js Ver fichero

5
 
5
 
6
 type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
6
 type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
7
 type Rationale = { title: string, message: string }
7
 type Rationale = { title: string, message: string }
8
-type Options = string | { type: string, rationale?: Rationale }
8
+type CheckOptions = string | { type: string }
9
+type RequestOptions = string | { type: string, rationale?: Rationale }
9
 
10
 
10
 const permissionTypes = [
11
 const permissionTypes = [
11
   'location',
12
   'location',
34
 
35
 
35
   getTypes: () => Array<string> = () => permissionTypes
36
   getTypes: () => Array<string> = () => permissionTypes
36
 
37
 
37
-  check = (permission: string, type?: string): Promise<Status> => {
38
+  check = (permission: string, options?: CheckOptions): Promise<Status> => {
38
     if (!permissionTypes.includes(permission)) {
39
     if (!permissionTypes.includes(permission)) {
39
       const error = new Error(
40
       const error = new Error(
40
         `ReactNativePermissions: ${
41
         `ReactNativePermissions: ${
45
       return Promise.reject(error)
46
       return Promise.reject(error)
46
     }
47
     }
47
 
48
 
48
-    return PermissionsIOS.getPermissionStatus(
49
-      permission,
50
-      type || DEFAULTS[permission],
51
-    )
52
-  }
53
-
54
-  request = (permission: string, options?: Options): Promise<Status> => {
55
     let type
49
     let type
56
 
50
 
57
     if (typeof options === 'string') {
51
     if (typeof options === 'string') {
60
       type = options.type
54
       type = options.type
61
     }
55
     }
62
 
56
 
57
+    return PermissionsIOS.getPermissionStatus(
58
+      permission,
59
+      type || DEFAULTS[permission],
60
+    )
61
+  }
62
+
63
+  request = (permission: string, options?: RequestOptions): Promise<Status> => {
63
     if (!permissionTypes.includes(permission)) {
64
     if (!permissionTypes.includes(permission)) {
64
       const error = new Error(
65
       const error = new Error(
65
         `ReactNativePermissions: ${
66
         `ReactNativePermissions: ${
78
       return Promise.reject(error)
79
       return Promise.reject(error)
79
     }
80
     }
80
 
81
 
82
+    let type
83
+
84
+    if (typeof options === 'string') {
85
+      type = options
86
+    } else if (options && options.type) {
87
+      type = options.type
88
+    }
89
+
81
     return PermissionsIOS.requestPermission(
90
     return PermissionsIOS.requestPermission(
82
       permission,
91
       permission,
83
       type || DEFAULTS[permission],
92
       type || DEFAULTS[permission],

+ 3
- 3
package.json Ver fichero

1
 {
1
 {
2
   "name": "react-native-permissions",
2
   "name": "react-native-permissions",
3
-  "version": "1.0.4",
3
+  "version": "1.0.5",
4
   "description": "Check user permissions in React Native",
4
   "description": "Check user permissions in React Native",
5
   "author": "Yonah Forst <yonaforst@hotmail.com>",
5
   "author": "Yonah Forst <yonaforst@hotmail.com>",
6
   "homepage": "https://github.com/yonahforst/react-native-permissions",
6
   "homepage": "https://github.com/yonahforst/react-native-permissions",
21
   "devDependencies": {
21
   "devDependencies": {
22
     "flow-bin": "^0.57.3",
22
     "flow-bin": "^0.57.3",
23
     "husky": "^0.14.3",
23
     "husky": "^0.14.3",
24
-    "lint-staged": "^5.0.0",
25
-    "prettier": "^1.8.2"
24
+    "lint-staged": "^6.0.0",
25
+    "prettier": "^1.9.2"
26
   }
26
   }
27
 }
27
 }