@@ -5,7 +5,8 @@ const PermissionsIOS = NativeModules.ReactNativePermissions
55
66type Status = 'authorized' | 'denied' | 'restricted' | 'undetermined'
77type 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
1011const 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 ] ,
0 commit comments