mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-05 15:27:05 +00:00
[react-native] Improve PermissionsAndroid types (#35286)
* Improve react-native PermissionsAndroid types * Add tests to react-native PermissionsAndroid types * End file with a newline
This commit is contained in:
committed by
Eloy Durán
parent
44022e0f1f
commit
762ae29bf4
Vendored
+3
-2
@@ -21,6 +21,7 @@
|
||||
// Francesco Moro <https://github.com/franzmoro>
|
||||
// Wojciech Tyczynski <https://github.com/tykus160>
|
||||
// Jake Bloom <https://github.com/jakebloom>
|
||||
// Ceyhun Ozugur <https://github.com/ceyhun>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.8
|
||||
|
||||
@@ -7965,13 +7966,13 @@ export interface PermissionsAndroidStatic {
|
||||
* (https://developer.android.com/training/permissions/requesting.html#explain)
|
||||
* and then shows the system permission dialog
|
||||
*/
|
||||
request(permission: Permission, rationale?: Rationale): Promise<string>;
|
||||
request(permission: Permission, rationale?: Rationale): Promise<PermissionStatus>;
|
||||
/**
|
||||
* Prompts the user to enable multiple permissions in the same dialog and
|
||||
* returns an object with the permissions as keys and strings as values
|
||||
* indicating whether the user allowed or denied the request
|
||||
*/
|
||||
requestMultiple(permissions: Array<string>): Promise<{ [permission: string]: PermissionStatus }>;
|
||||
requestMultiple(permissions: Array<Permission>): Promise<{ [key in Permission]: PermissionStatus }>;
|
||||
}
|
||||
|
||||
export interface PushNotificationPermissions {
|
||||
|
||||
@@ -88,6 +88,7 @@ import {
|
||||
requireNativeComponent,
|
||||
Keyboard,
|
||||
NetInfo,
|
||||
PermissionsAndroid,
|
||||
} from "react-native";
|
||||
|
||||
declare module "react-native" {
|
||||
@@ -876,3 +877,35 @@ const NetInfoTest = () => {
|
||||
const subscription = NetInfo.addEventListener('connectionChange', (result) => console.log(result));
|
||||
subscription.remove();
|
||||
}
|
||||
|
||||
const PermissionsAndroidTest = () => {
|
||||
PermissionsAndroid.request('android.permission.CAMERA').then(result => {
|
||||
switch (result) {
|
||||
case 'granted':
|
||||
break;
|
||||
case 'denied':
|
||||
break;
|
||||
case 'never_ask_again':
|
||||
break;
|
||||
}
|
||||
})
|
||||
|
||||
PermissionsAndroid.requestMultiple(['android.permission.CAMERA', 'android.permission.ACCESS_FINE_LOCATION']).then(results => {
|
||||
switch (results['android.permission.CAMERA']) {
|
||||
case 'granted':
|
||||
break;
|
||||
case 'denied':
|
||||
break;
|
||||
case 'never_ask_again':
|
||||
break;
|
||||
}
|
||||
switch (results['android.permission.ACCESS_FINE_LOCATION']) {
|
||||
case 'granted':
|
||||
break;
|
||||
case 'denied':
|
||||
break;
|
||||
case 'never_ask_again':
|
||||
break;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user