Browse Source

Run new prettier config over the codebase

Mathieu Acthernoene 6 years ago
parent
commit
55634b4c80
6 changed files with 167 additions and 176 deletions
  1. 10
    10
      .github/CODE_OF_CONDUCT.md
  2. 7
    7
      .github/ISSUE_TEMPLATE.md
  3. 55
    56
      README.md
  4. 2
    2
      index.js
  5. 40
    44
      lib/permissions.android.js
  6. 53
    57
      lib/permissions.ios.js

+ 10
- 10
.github/CODE_OF_CONDUCT.md View File

14
 Examples of behavior that contributes to creating a positive environment
14
 Examples of behavior that contributes to creating a positive environment
15
 include:
15
 include:
16
 
16
 
17
-* Using welcoming and inclusive language
18
-* Being respectful of differing viewpoints and experiences
19
-* Gracefully accepting constructive criticism
20
-* Focusing on what is best for the community
21
-* Showing empathy towards other community members
17
+- Using welcoming and inclusive language
18
+- Being respectful of differing viewpoints and experiences
19
+- Gracefully accepting constructive criticism
20
+- Focusing on what is best for the community
21
+- Showing empathy towards other community members
22
 
22
 
23
 Examples of unacceptable behavior by participants include:
23
 Examples of unacceptable behavior by participants include:
24
 
24
 
25
-* The use of sexualized language or imagery and unwelcome sexual attention or
25
+- The use of sexualized language or imagery and unwelcome sexual attention or
26
   advances
26
   advances
27
-* Trolling, insulting/derogatory comments, and personal or political attacks
28
-* Public or private harassment
29
-* Publishing others' private information, such as a physical or electronic
27
+- Trolling, insulting/derogatory comments, and personal or political attacks
28
+- Public or private harassment
29
+- Publishing others' private information, such as a physical or electronic
30
   address, without explicit permission
30
   address, without explicit permission
31
-* Other conduct which could reasonably be considered inappropriate in a
31
+- Other conduct which could reasonably be considered inappropriate in a
32
   professional setting
32
   professional setting
33
 
33
 
34
 ## Our Responsibilities
34
 ## Our Responsibilities

+ 7
- 7
.github/ISSUE_TEMPLATE.md View File

9
 
9
 
10
 ### Describe your environment
10
 ### Describe your environment
11
 
11
 
12
-* React-Native version
13
-* Platform: iOS, Android, both?
14
-* Device (which one?), simulator?
15
-* OS version
16
-* react-native-permissions version
17
-* Devtools: Xcode? Android Studio version?
18
-* (Android only: buildToolsVersion)
12
+- react-native-permissions version
13
+- react-native version
14
+- Target platform: iOS, Android, both?
15
+- Device (which one?), simulator?
16
+- OS version
17
+- DevTools: Xcode version, Android Studio version
18
+- (Android only: buildToolsVersion)
19
 
19
 
20
 ### How to repeat issue and example
20
 ### How to repeat issue and example
21
 
21
 

+ 55
- 56
README.md View File

18
 
18
 
19
 ## ⚠️ Breaking changes in version 1.0.0
19
 ## ⚠️ Breaking changes in version 1.0.0
20
 
20
 
21
-* Now using React Native's own JS `PermissionsAndroid` module on Android, which
21
+- Now using React Native's own JS `PermissionsAndroid` module on Android, which
22
   is great because we no longer have to do any additional linking on Android
22
   is great because we no longer have to do any additional linking on Android
23
-* Updated API to be closer to React Native's `PermissionsAndroid`
24
-* Removed `openSettings()` support on Android (to stay linking-free). There are
23
+- Updated API to be closer to React Native's `PermissionsAndroid`
24
+- Removed `openSettings()` support on Android (to stay linking-free). There are
25
   several NPM modules available for this
25
   several NPM modules available for this
26
-* `restricted` status now supported on Android, although it means something
26
+- `restricted` status now supported on Android, although it means something
27
   different than iOS
27
   different than iOS
28
 
28
 
29
 ## Setup
29
 ## Setup
60
    folder ➜ `Add Files to <...>`
60
    folder ➜ `Add Files to <...>`
61
 2. Go to `node_modules` ➜ `react-native-permissions` ➜ select
61
 2. Go to `node_modules` ➜ `react-native-permissions` ➜ select
62
    `ReactNativePermissions.xcodeproj`
62
    `ReactNativePermissions.xcodeproj`
63
-3. Add `libReactNativePermissions.a` to `Build Phases` -> `Link Binary With
64
-   Libraries`
63
+3. Add `libReactNativePermissions.a` to `Build Phases` -> `Link Binary With Libraries`
65
 
64
 
66
 ## Using
65
 ## Using
67
 
66
 
68
 ```js
67
 ```js
69
-import Permissions from 'react-native-permissions'
68
+import Permissions from "react-native-permissions";
70
 // OR const Permissions = require('react-native-permissions').default
69
 // OR const Permissions = require('react-native-permissions').default
71
 // if you use CommonJS module system
70
 // if you use CommonJS module system
72
 
71
 
77
 
76
 
78
   // Check the status of a single permission
77
   // Check the status of a single permission
79
   componentDidMount() {
78
   componentDidMount() {
80
-    Permissions.check('photo').then(response => {
79
+    Permissions.check("photo").then(response => {
81
       // Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
80
       // Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
82
-      this.setState({ photoPermission: response })
83
-    })
81
+      this.setState({ photoPermission: response });
82
+    });
84
   }
83
   }
85
 
84
 
86
   // Request permission to access photos
85
   // Request permission to access photos
87
   _requestPermission = () => {
86
   _requestPermission = () => {
88
-    Permissions.request('photo').then(response => {
87
+    Permissions.request("photo").then(response => {
89
       // Returns once the user has chosen to 'allow' or to 'not allow' access
88
       // Returns once the user has chosen to 'allow' or to 'not allow' access
90
       // Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
89
       // Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
91
-      this.setState({ photoPermission: response })
92
-    })
93
-  }
90
+      this.setState({ photoPermission: response });
91
+    });
92
+  };
94
 
93
 
95
   // Check the status of multiple permissions
94
   // Check the status of multiple permissions
96
   _checkCameraAndPhotos = () => {
95
   _checkCameraAndPhotos = () => {
97
-    Permissions.checkMultiple(['camera', 'photo']).then(response => {
96
+    Permissions.checkMultiple(["camera", "photo"]).then(response => {
98
       //response is an object mapping type to permission
97
       //response is an object mapping type to permission
99
       this.setState({
98
       this.setState({
100
         cameraPermission: response.camera,
99
         cameraPermission: response.camera,
101
         photoPermission: response.photo,
100
         photoPermission: response.photo,
102
-      })
103
-    })
104
-  }
101
+      });
102
+    });
103
+  };
105
 
104
 
106
   // This is a common pattern when asking for permissions.
105
   // This is a common pattern when asking for permissions.
107
   // iOS only gives you once chance to show the permission dialog,
106
   // iOS only gives you once chance to show the permission dialog,
111
   // If the user already denied access, we can ask them to enable it from settings.
110
   // If the user already denied access, we can ask them to enable it from settings.
112
   _alertForPhotosPermission() {
111
   _alertForPhotosPermission() {
113
     Alert.alert(
112
     Alert.alert(
114
-      'Can we access your photos?',
115
-      'We need access so you can set your profile pic',
113
+      "Can we access your photos?",
114
+      "We need access so you can set your profile pic",
116
       [
115
       [
117
         {
116
         {
118
-          text: 'No way',
119
-          onPress: () => console.log('Permission denied'),
120
-          style: 'cancel',
117
+          text: "No way",
118
+          onPress: () => console.log("Permission denied"),
119
+          style: "cancel",
121
         },
120
         },
122
-        this.state.photoPermission == 'undetermined'
123
-          ? { text: 'OK', onPress: this._requestPermission }
124
-          : { text: 'Open Settings', onPress: Permissions.openSettings },
121
+        this.state.photoPermission == "undetermined"
122
+          ? { text: "OK", onPress: this._requestPermission }
123
+          : { text: "Open Settings", onPress: Permissions.openSettings },
125
       ],
124
       ],
126
-    )
125
+    );
127
   }
126
   }
128
 
127
 
129
   //...
128
   //...
139
 | Return value   | Notes                                                                                                                                                                                                                                                                  |
138
 | Return value   | Notes                                                                                                                                                                                                                                                                  |
140
 | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
139
 | -------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
141
 | `authorized`   | User has authorized this permission                                                                                                                                                                                                                                    |
140
 | `authorized`   | User has authorized this permission                                                                                                                                                                                                                                    |
142
-| `denied`       | User has denied this permission at least once. On iOS this means that the user will not be prompted again. Android users can be prompted multiple times until they select 'Never ask me again'                                                                          |
141
+| `denied`       | User has denied this permission at least once. On iOS this means that the user will not be prompted again. Android users can be prompted multiple times until they select 'Never ask me again'                                                                         |
143
 | `restricted`   | **iOS** - this means user is not able to grant this permission, either because it's not supported by the device or because it has been blocked by parental controls. **Android** - this means that the user has selected 'Never ask me again' while denying permission |
142
 | `restricted`   | **iOS** - this means user is not able to grant this permission, either because it's not supported by the device or because it has been blocked by parental controls. **Android** - this means that the user has selected 'Never ask me again' while denying permission |
144
 | `undetermined` | User has not yet been prompted with a permission dialog                                                                                                                                                                                                                |
143
 | `undetermined` | User has not yet been prompted with a permission dialog                                                                                                                                                                                                                |
145
 
144
 
180
 
179
 
181
 ### iOS Notes
180
 ### iOS Notes
182
 
181
 
183
-* Permission type `bluetooth` represents the status of the
182
+- Permission type `bluetooth` represents the status of the
184
   `CBPeripheralManager`. Don't use this if only need `CBCentralManager`
183
   `CBPeripheralManager`. Don't use this if only need `CBCentralManager`
185
-* Permission type `location` accepts a second parameter for `request()` and
184
+- Permission type `location` accepts a second parameter for `request()` and
186
   `check()`; the second parameter is a string, either `always` or `whenInUse`
185
   `check()`; the second parameter is a string, either `always` or `whenInUse`
187
   (default).
186
   (default).
188
-* Permission type `notification` accepts a second parameter for `request()`. The
187
+- Permission type `notification` accepts a second parameter for `request()`. The
189
   second parameter is an array with the desired alert types. Any combination of
188
   second parameter is an array with the desired alert types. Any combination of
190
   `alert`, `badge` and `sound` (default requests all three).
189
   `alert`, `badge` and `sound` (default requests all three).
191
-* If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project
190
+- If you are not requesting mediaLibrary then you can remove MediaPlayer.framework from the xcode project
192
 
191
 
193
 ```js
192
 ```js
194
 // example
193
 // example
195
-Permissions.check('location', { type: 'always' }).then(response => {
196
-  this.setState({ locationPermission: response })
197
-})
194
+Permissions.check("location", { type: "always" }).then(response => {
195
+  this.setState({ locationPermission: response });
196
+});
198
 
197
 
199
-Permissions.request('location', { type: 'always' }).then(response => {
200
-  this.setState({ locationPermission: response })
201
-})
198
+Permissions.request("location", { type: "always" }).then(response => {
199
+  this.setState({ locationPermission: response });
200
+});
202
 
201
 
203
-Permissions.request('notification', { type: ['alert', 'badge'] }).then(
202
+Permissions.request("notification", { type: ["alert", "badge"] }).then(
204
   response => {
203
   response => {
205
-    this.setState({ notificationPermission: response })
204
+    this.setState({ notificationPermission: response });
206
   },
205
   },
207
-)
206
+);
208
 ```
207
 ```
209
 
208
 
210
-* You cannot request microphone permissions on the simulator.
211
-* With Xcode 8, you now need to add usage descriptions for each permission you
209
+- You cannot request microphone permissions on the simulator.
210
+- With Xcode 8, you now need to add usage descriptions for each permission you
212
   will request. Open Xcode ➜ `Info.plist` ➜ Add a key (starting with "Privacy -
211
   will request. Open Xcode ➜ `Info.plist` ➜ Add a key (starting with "Privacy -
213
   ...") with your kit specific permission.
212
   ...") with your kit specific permission.
214
 
213
 
215
-Example: If you need Contacts permission you have to add the key `Privacy -
216
-Contacts Usage Description`.
214
+Example: If you need Contacts permission you have to add the key `Privacy - Contacts Usage Description`.
217
 
215
 
218
 <img width="338" alt="3cde3b44-7ffd-11e6-918b-63888e33f983" src="https://cloud.githubusercontent.com/assets/1440796/18713019/271be540-8011-11e6-87fb-c3828c172dfc.png">
216
 <img width="338" alt="3cde3b44-7ffd-11e6-918b-63888e33f983" src="https://cloud.githubusercontent.com/assets/1440796/18713019/271be540-8011-11e6-87fb-c3828c172dfc.png">
219
 
217
 
246
 <key>NSMotionUsageDescription</key>
244
 <key>NSMotionUsageDescription</key>
247
 <string>Some description</string>
245
 <string>Some description</string>
248
 ```
246
 ```
247
+
249
 This is required because during the phase of processing in the App Store
248
 This is required because during the phase of processing in the App Store
250
 submission, the system detects that you app contains code to request the
249
 submission, the system detects that you app contains code to request the
251
 permission `X` but don't have the `UsageDescription` key and then it rejects the
250
 permission `X` but don't have the `UsageDescription` key and then it rejects the
258
 
257
 
259
 ### Android Notes
258
 ### Android Notes
260
 
259
 
261
-* Uses React Native's own
260
+- Uses React Native's own
262
   [`PermissionsAndroid` JS API](http://facebook.github.io/react-native/docs/permissionsandroid.html).
261
   [`PermissionsAndroid` JS API](http://facebook.github.io/react-native/docs/permissionsandroid.html).
263
-* All required permissions also need to be included in the `AndroidManifest.xml`
262
+- All required permissions also need to be included in the `AndroidManifest.xml`
264
   file before they can be requested. Otherwise `request()` will immediately
263
   file before they can be requested. Otherwise `request()` will immediately
265
   return `denied`.
264
   return `denied`.
266
-* You can request write access to any of these types by also including the
265
+- You can request write access to any of these types by also including the
267
   appropriate write permission in the `AndroidManifest.xml` file. Read more
266
   appropriate write permission in the `AndroidManifest.xml` file. Read more
268
   [here](https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous).
267
   [here](https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous).
269
 
268
 
270
-* The optional rationale argument will show a dialog prompt.
269
+- The optional rationale argument will show a dialog prompt.
271
 
270
 
272
 ```js
271
 ```js
273
 // example
272
 // example
274
-Permissions.request('camera', {
273
+Permissions.request("camera", {
275
   rationale: {
274
   rationale: {
276
-    title: 'Cool Photo App Camera Permission',
275
+    title: "Cool Photo App Camera Permission",
277
     message:
276
     message:
278
-      'Cool Photo App needs access to your camera ' +
279
-      'so you can take awesome pictures.',
277
+      "Cool Photo App needs access to your camera " +
278
+      "so you can take awesome pictures.",
280
   },
279
   },
281
 }).then(response => {
280
 }).then(response => {
282
-  this.setState({ cameraPermission: response })
283
-})
281
+  this.setState({ cameraPermission: response });
282
+});
284
 ```
283
 ```
285
 
284
 
286
-* Permissions are automatically accepted for **targetSdkVersion < 23** but you
285
+- Permissions are automatically accepted for **targetSdkVersion < 23** but you
287
   can still use `check()` to check if the user has disabled them from Settings.
286
   can still use `check()` to check if the user has disabled them from Settings.
288
 
287
 
289
 You might need to elevate the **targetSdkVersion** version in your
288
 You might need to elevate the **targetSdkVersion** version in your

+ 2
- 2
index.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import Permissions from './lib/permissions'
4
-export default Permissions
3
+import Permissions from "./lib/permissions";
4
+export default Permissions;

+ 40
- 44
lib/permissions.android.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { AsyncStorage, NativeModules, PermissionsAndroid } from 'react-native'
3
+import { AsyncStorage, NativeModules, PermissionsAndroid } from "react-native";
4
 
4
 
5
-type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
6
-type Rationale = { title: string, message: string }
7
-type CheckOptions = string | { type: string }
8
-type RequestOptions = string | { type: string, rationale?: Rationale }
5
+type Status = "authorized" | "denied" | "restricted" | "undetermined";
6
+type Rationale = { title: string, message: string };
7
+type CheckOptions = string | { type: string };
8
+type RequestOptions = string | { type: string, rationale?: Rationale };
9
 
9
 
10
 const permissionTypes = {
10
 const permissionTypes = {
11
   location: PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
11
   location: PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
18
   callPhone: PermissionsAndroid.PERMISSIONS.CALL_PHONE,
18
   callPhone: PermissionsAndroid.PERMISSIONS.CALL_PHONE,
19
   readSms: PermissionsAndroid.PERMISSIONS.READ_SMS,
19
   readSms: PermissionsAndroid.PERMISSIONS.READ_SMS,
20
   receiveSms: PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
20
   receiveSms: PermissionsAndroid.PERMISSIONS.RECEIVE_SMS,
21
-}
21
+};
22
 
22
 
23
 const RESULTS = {
23
 const RESULTS = {
24
-  [PermissionsAndroid.RESULTS.GRANTED]: 'authorized',
25
-  [PermissionsAndroid.RESULTS.DENIED]: 'denied',
26
-  [PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN]: 'restricted',
27
-}
24
+  [PermissionsAndroid.RESULTS.GRANTED]: "authorized",
25
+  [PermissionsAndroid.RESULTS.DENIED]: "denied",
26
+  [PermissionsAndroid.RESULTS.NEVER_ASK_AGAIN]: "restricted",
27
+};
28
 
28
 
29
-const STORAGE_KEY = '@RNPermissions:didAskPermission:'
29
+const STORAGE_KEY = "@RNPermissions:didAskPermission:";
30
 
30
 
31
 const setDidAskOnce = (permission: string) =>
31
 const setDidAskOnce = (permission: string) =>
32
-  AsyncStorage.setItem(STORAGE_KEY + permission, 'true')
32
+  AsyncStorage.setItem(STORAGE_KEY + permission, "true");
33
 
33
 
34
 const getDidAskOnce = (permission: string) =>
34
 const getDidAskOnce = (permission: string) =>
35
-  AsyncStorage.getItem(STORAGE_KEY + permission).then(item => !!item)
35
+  AsyncStorage.getItem(STORAGE_KEY + permission).then(item => !!item);
36
 
36
 
37
 class ReactNativePermissions {
37
 class ReactNativePermissions {
38
-  canOpenSettings: () => Promise<boolean> = () => Promise.resolve(false)
38
+  canOpenSettings: () => Promise<boolean> = () => Promise.resolve(false);
39
 
39
 
40
   openSettings: () => Promise<*> = () =>
40
   openSettings: () => Promise<*> = () =>
41
-    Promise.reject(new Error("'openSettings' is deprecated on android"))
41
+    Promise.reject(new Error("'openSettings' is deprecated on android"));
42
 
42
 
43
-  getTypes: () => Array<string> = () => Object.keys(permissionTypes)
43
+  getTypes: () => Array<string> = () => Object.keys(permissionTypes);
44
 
44
 
45
   check = (permission: string, options?: CheckOptions): Promise<Status> => {
45
   check = (permission: string, options?: CheckOptions): Promise<Status> => {
46
     if (!permissionTypes[permission]) {
46
     if (!permissionTypes[permission]) {
47
       const error = new Error(
47
       const error = new Error(
48
-        `ReactNativePermissions: ${
49
-          permission
50
-        } is not a valid permission type on Android`,
51
-      )
48
+        `ReactNativePermissions: ${permission} is not a valid permission type on Android`,
49
+      );
52
 
50
 
53
-      return Promise.reject(error)
51
+      return Promise.reject(error);
54
     }
52
     }
55
 
53
 
56
     return PermissionsAndroid.check(permissionTypes[permission]).then(
54
     return PermissionsAndroid.check(permissionTypes[permission]).then(
57
       isAuthorized => {
55
       isAuthorized => {
58
         if (isAuthorized) {
56
         if (isAuthorized) {
59
-          return 'authorized'
57
+          return "authorized";
60
         }
58
         }
61
 
59
 
62
         return getDidAskOnce(permission).then(didAsk => {
60
         return getDidAskOnce(permission).then(didAsk => {
63
           if (didAsk) {
61
           if (didAsk) {
64
             return NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale(
62
             return NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale(
65
               permissionTypes[permission],
63
               permissionTypes[permission],
66
-            ).then(shouldShow => (shouldShow ? 'denied' : 'restricted'))
64
+            ).then(shouldShow => (shouldShow ? "denied" : "restricted"));
67
           }
65
           }
68
 
66
 
69
-          return 'undetermined'
70
-        })
67
+          return "undetermined";
68
+        });
71
       },
69
       },
72
-    )
73
-  }
70
+    );
71
+  };
74
 
72
 
75
   request = (permission: string, options?: RequestOptions): Promise<Status> => {
73
   request = (permission: string, options?: RequestOptions): Promise<Status> => {
76
     if (!permissionTypes[permission]) {
74
     if (!permissionTypes[permission]) {
77
       const error = new Error(
75
       const error = new Error(
78
-        `ReactNativePermissions: ${
79
-          permission
80
-        } is not a valid permission type on Android`,
81
-      )
76
+        `ReactNativePermissions: ${permission} is not a valid permission type on Android`,
77
+      );
82
 
78
 
83
-      return Promise.reject(error)
79
+      return Promise.reject(error);
84
     }
80
     }
85
 
81
 
86
-    let rationale
82
+    let rationale;
87
 
83
 
88
     if (options && options.rationale) {
84
     if (options && options.rationale) {
89
-      rationale = options.rationale
85
+      rationale = options.rationale;
90
     }
86
     }
91
 
87
 
92
     return PermissionsAndroid.request(
88
     return PermissionsAndroid.request(
95
     ).then(result => {
91
     ).then(result => {
96
       // PermissionsAndroid.request() to native module resolves to boolean
92
       // PermissionsAndroid.request() to native module resolves to boolean
97
       // rather than string if running on OS version prior to Android M
93
       // rather than string if running on OS version prior to Android M
98
-      if (typeof result === 'boolean') {
99
-        return result ? 'authorized' : 'denied'
94
+      if (typeof result === "boolean") {
95
+        return result ? "authorized" : "denied";
100
       }
96
       }
101
 
97
 
102
-      return setDidAskOnce(permission).then(() => RESULTS[result])
103
-    })
104
-  }
98
+      return setDidAskOnce(permission).then(() => RESULTS[result]);
99
+    });
100
+  };
105
 
101
 
106
   checkMultiple = (permissions: Array<string>): Promise<{ [string]: string }> =>
102
   checkMultiple = (permissions: Array<string>): Promise<{ [string]: string }> =>
107
     Promise.all(permissions.map(permission => this.check(permission))).then(
103
     Promise.all(permissions.map(permission => this.check(permission))).then(
108
       result =>
104
       result =>
109
         result.reduce((acc, value, index) => {
105
         result.reduce((acc, value, index) => {
110
-          const name = permissions[index]
111
-          acc[name] = value
112
-          return acc
106
+          const name = permissions[index];
107
+          acc[name] = value;
108
+          return acc;
113
         }, {}),
109
         }, {}),
114
-    )
110
+    );
115
 }
111
 }
116
 
112
 
117
-export default new ReactNativePermissions()
113
+export default new ReactNativePermissions();

+ 53
- 57
lib/permissions.ios.js View File

1
 // @flow
1
 // @flow
2
 
2
 
3
-import { NativeModules } from 'react-native'
4
-const PermissionsIOS = NativeModules.ReactNativePermissions
3
+import { NativeModules } from "react-native";
4
+const PermissionsIOS = NativeModules.ReactNativePermissions;
5
 
5
 
6
-type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
7
-type Rationale = { title: string, message: string }
8
-type CheckOptions = string | { type: string }
9
-type RequestOptions = string | { type: string, rationale?: Rationale }
6
+type Status = "authorized" | "denied" | "restricted" | "undetermined";
7
+type Rationale = { title: string, message: string };
8
+type CheckOptions = string | { type: string };
9
+type RequestOptions = string | { type: string, rationale?: Rationale };
10
 
10
 
11
 const permissionTypes = [
11
 const permissionTypes = [
12
-  'location',
13
-  'camera',
14
-  'microphone',
15
-  'photo',
16
-  'contacts',
17
-  'event',
18
-  'reminder',
19
-  'bluetooth',
20
-  'notification',
21
-  'backgroundRefresh',
22
-  'speechRecognition',
23
-  'mediaLibrary',
24
-  'motion'
25
-]
12
+  "location",
13
+  "camera",
14
+  "microphone",
15
+  "photo",
16
+  "contacts",
17
+  "event",
18
+  "reminder",
19
+  "bluetooth",
20
+  "notification",
21
+  "backgroundRefresh",
22
+  "speechRecognition",
23
+  "mediaLibrary",
24
+  "motion",
25
+];
26
 
26
 
27
 const DEFAULTS = {
27
 const DEFAULTS = {
28
-  location: 'whenInUse',
29
-  notification: ['alert', 'badge', 'sound'],
30
-}
28
+  location: "whenInUse",
29
+  notification: ["alert", "badge", "sound"],
30
+};
31
 
31
 
32
 class ReactNativePermissions {
32
 class ReactNativePermissions {
33
   canOpenSettings: () => Promise<boolean> = () =>
33
   canOpenSettings: () => Promise<boolean> = () =>
34
-    PermissionsIOS.canOpenSettings()
34
+    PermissionsIOS.canOpenSettings();
35
 
35
 
36
-  openSettings: () => Promise<*> = () => PermissionsIOS.openSettings()
36
+  openSettings: () => Promise<*> = () => PermissionsIOS.openSettings();
37
 
37
 
38
-  getTypes: () => Array<string> = () => permissionTypes
38
+  getTypes: () => Array<string> = () => permissionTypes;
39
 
39
 
40
   check = (permission: string, options?: CheckOptions): Promise<Status> => {
40
   check = (permission: string, options?: CheckOptions): Promise<Status> => {
41
     if (!permissionTypes.includes(permission)) {
41
     if (!permissionTypes.includes(permission)) {
42
       const error = new Error(
42
       const error = new Error(
43
-        `ReactNativePermissions: ${
44
-          permission
45
-        } is not a valid permission type on iOS`,
46
-      )
43
+        `ReactNativePermissions: ${permission} is not a valid permission type on iOS`,
44
+      );
47
 
45
 
48
-      return Promise.reject(error)
46
+      return Promise.reject(error);
49
     }
47
     }
50
 
48
 
51
-    let type
49
+    let type;
52
 
50
 
53
-    if (typeof options === 'string') {
54
-      type = options
51
+    if (typeof options === "string") {
52
+      type = options;
55
     } else if (options && options.type) {
53
     } else if (options && options.type) {
56
-      type = options.type
54
+      type = options.type;
57
     }
55
     }
58
 
56
 
59
     return PermissionsIOS.getPermissionStatus(
57
     return PermissionsIOS.getPermissionStatus(
60
       permission,
58
       permission,
61
       type || DEFAULTS[permission],
59
       type || DEFAULTS[permission],
62
-    )
63
-  }
60
+    );
61
+  };
64
 
62
 
65
   request = (permission: string, options?: RequestOptions): Promise<Status> => {
63
   request = (permission: string, options?: RequestOptions): Promise<Status> => {
66
     if (!permissionTypes.includes(permission)) {
64
     if (!permissionTypes.includes(permission)) {
67
       const error = new Error(
65
       const error = new Error(
68
-        `ReactNativePermissions: ${
69
-          permission
70
-        } is not a valid permission type on iOS`,
71
-      )
66
+        `ReactNativePermissions: ${permission} is not a valid permission type on iOS`,
67
+      );
72
 
68
 
73
-      return Promise.reject(error)
69
+      return Promise.reject(error);
74
     }
70
     }
75
 
71
 
76
-    if (permission == 'backgroundRefresh') {
72
+    if (permission == "backgroundRefresh") {
77
       const error = new Error(
73
       const error = new Error(
78
-        'ReactNativePermissions: You cannot request backgroundRefresh',
79
-      )
74
+        "ReactNativePermissions: You cannot request backgroundRefresh",
75
+      );
80
 
76
 
81
-      return Promise.reject(error)
77
+      return Promise.reject(error);
82
     }
78
     }
83
 
79
 
84
-    let type
80
+    let type;
85
 
81
 
86
-    if (typeof options === 'string') {
87
-      type = options
82
+    if (typeof options === "string") {
83
+      type = options;
88
     } else if (options && options.type) {
84
     } else if (options && options.type) {
89
-      type = options.type
85
+      type = options.type;
90
     }
86
     }
91
 
87
 
92
     return PermissionsIOS.requestPermission(
88
     return PermissionsIOS.requestPermission(
93
       permission,
89
       permission,
94
       type || DEFAULTS[permission],
90
       type || DEFAULTS[permission],
95
-    )
96
-  }
91
+    );
92
+  };
97
 
93
 
98
   checkMultiple = (permissions: Array<string>): Promise<{ [string]: string }> =>
94
   checkMultiple = (permissions: Array<string>): Promise<{ [string]: string }> =>
99
     Promise.all(permissions.map(permission => this.check(permission))).then(
95
     Promise.all(permissions.map(permission => this.check(permission))).then(
100
       result =>
96
       result =>
101
         result.reduce((acc, value, index) => {
97
         result.reduce((acc, value, index) => {
102
-          const name = permissions[index]
103
-          acc[name] = value
104
-          return acc
98
+          const name = permissions[index];
99
+          acc[name] = value;
100
+          return acc;
105
         }, {}),
101
         }, {}),
106
-    )
102
+    );
107
 }
103
 }
108
 
104
 
109
-export default new ReactNativePermissions()
105
+export default new ReactNativePermissions();