Skip to content

Commit e3694e7

Browse files
committed
Check can now accept a string or an object
1 parent 68e323c commit e3694e7

File tree

5 files changed

+28
-16
lines changed

5 files changed

+28
-16
lines changed

.prettierignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1+
android/
2+
ios/
13
example/node_modules/

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Request user permissions from React Native, iOS + Android
1010

1111
| Version | React Native Support |
1212
| ------- | -------------------- |
13-
| 1.0.4 | 0.40 - 0.50 |
13+
| 1.0.5 | 0.40 - 0.51 |
1414
| 0.2.5 | 0.33 - 0.39 |
1515

1616
_Complies with

lib/permissions.android.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import { AsyncStorage, NativeModules, PermissionsAndroid } from 'react-native'
44

55
type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
66
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 }
89

910
const permissionTypes = {
1011
location: PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
@@ -41,7 +42,7 @@ class ReactNativePermissions {
4142

4243
getTypes: () => Array<string> = () => Object.keys(permissionTypes)
4344

44-
check = (permission: string, type?: string): Promise<Status> => {
45+
check = (permission: string, options?: CheckOptions): Promise<Status> => {
4546
if (!permissionTypes[permission]) {
4647
const error = new Error(
4748
`ReactNativePermissions: ${
@@ -71,7 +72,7 @@ class ReactNativePermissions {
7172
)
7273
}
7374

74-
request = (permission: string, options?: Options): Promise<Status> => {
75+
request = (permission: string, options?: RequestOptions): Promise<Status> => {
7576
if (!permissionTypes[permission]) {
7677
const error = new Error(
7778
`ReactNativePermissions: ${

lib/permissions.ios.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ const PermissionsIOS = NativeModules.ReactNativePermissions
55

66
type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
77
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 }
910

1011
const permissionTypes = [
1112
'location',
@@ -34,7 +35,7 @@ class ReactNativePermissions {
3435

3536
getTypes: () => Array<string> = () => permissionTypes
3637

37-
check = (permission: string, type?: string): Promise<Status> => {
38+
check = (permission: string, options?: CheckOptions): Promise<Status> => {
3839
if (!permissionTypes.includes(permission)) {
3940
const error = new Error(
4041
`ReactNativePermissions: ${
@@ -45,13 +46,6 @@ class ReactNativePermissions {
4546
return Promise.reject(error)
4647
}
4748

48-
return PermissionsIOS.getPermissionStatus(
49-
permission,
50-
type || DEFAULTS[permission],
51-
)
52-
}
53-
54-
request = (permission: string, options?: Options): Promise<Status> => {
5549
let type
5650

5751
if (typeof options === 'string') {
@@ -60,6 +54,13 @@ class ReactNativePermissions {
6054
type = options.type
6155
}
6256

57+
return PermissionsIOS.getPermissionStatus(
58+
permission,
59+
type || DEFAULTS[permission],
60+
)
61+
}
62+
63+
request = (permission: string, options?: RequestOptions): Promise<Status> => {
6364
if (!permissionTypes.includes(permission)) {
6465
const error = new Error(
6566
`ReactNativePermissions: ${
@@ -78,6 +79,14 @@ class ReactNativePermissions {
7879
return Promise.reject(error)
7980
}
8081

82+
let type
83+
84+
if (typeof options === 'string') {
85+
type = options
86+
} else if (options && options.type) {
87+
type = options.type
88+
}
89+
8190
return PermissionsIOS.requestPermission(
8291
permission,
8392
type || DEFAULTS[permission],

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-permissions",
3-
"version": "1.0.4",
3+
"version": "1.0.5",
44
"description": "Check user permissions in React Native",
55
"author": "Yonah Forst <[email protected]>",
66
"homepage": "https://github.com/yonahforst/react-native-permissions",
@@ -21,7 +21,7 @@
2121
"devDependencies": {
2222
"flow-bin": "^0.57.3",
2323
"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"
2626
}
2727
}

0 commit comments

Comments
 (0)