Browse Source

Use a object as second argument

matthieu.hocquart 7 years ago
parent
commit
c40e2ab6e3
2 changed files with 10 additions and 2 deletions
  1. 1
    1
      index.android.js
  2. 9
    1
      index.ios.js

+ 1
- 1
index.android.js View File

60
 	}
60
 	}
61
 
61
 
62
 
62
 
63
-	request(permission, rationale) {
63
+	request(permission, { rationale }) {
64
 		const androidPermission = RNPTypes[permission]
64
 		const androidPermission = RNPTypes[permission]
65
   	if (!androidPermission) return Promise.reject(`ReactNativePermissions: ${permission} is not a valid permission type on Android`);
65
   	if (!androidPermission) return Promise.reject(`ReactNativePermissions: ${permission} is not a valid permission type on Android`);
66
 
66
 

+ 9
- 1
index.ios.js View File

43
 		return RNPermissions.getPermissionStatus(permission, type);
43
 		return RNPermissions.getPermissionStatus(permission, type);
44
 	}
44
 	}
45
 
45
 
46
-	request(permission, type) {
46
+	request(permission, options) {
47
+		let type = null;
48
+		if (typeof options === 'string' || options instanceof Array) {
49
+			console.warn('[react-native-permissions] : You are using a deprecated version of request(). You should use an object as second parameter. Please check the documentation for more information : https://github.com/yonahforst/react-native-permissions');
50
+			type = options;
51
+		} else {
52
+			type = options.type;
53
+		}
54
+
47
 		if (!RNPTypes.includes(permission)) {
55
 		if (!RNPTypes.includes(permission)) {
48
 			return Promise.reject(`ReactNativePermissions: ${permission} is not a valid permission type on iOS`);
56
 			return Promise.reject(`ReactNativePermissions: ${permission} is not a valid permission type on iOS`);
49
 		}
57
 		}