From 762ae29bf45b22cc1197894dc3817f3e9af46b59 Mon Sep 17 00:00:00 2001 From: Ceyhun Ozugur Date: Fri, 10 May 2019 18:51:18 +0200 Subject: [PATCH] [react-native] Improve PermissionsAndroid types (#35286) * Improve react-native PermissionsAndroid types * Add tests to react-native PermissionsAndroid types * End file with a newline --- types/react-native/index.d.ts | 5 +++-- types/react-native/test/index.tsx | 33 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/types/react-native/index.d.ts b/types/react-native/index.d.ts index a9a56f643a..89f7073513 100644 --- a/types/react-native/index.d.ts +++ b/types/react-native/index.d.ts @@ -21,6 +21,7 @@ // Francesco Moro // Wojciech Tyczynski // Jake Bloom +// Ceyhun Ozugur // 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; + request(permission: Permission, rationale?: Rationale): Promise; /** * 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): Promise<{ [permission: string]: PermissionStatus }>; + requestMultiple(permissions: Array): Promise<{ [key in Permission]: PermissionStatus }>; } export interface PushNotificationPermissions { diff --git a/types/react-native/test/index.tsx b/types/react-native/test/index.tsx index 9c8c3b89a0..bd4aa288e2 100644 --- a/types/react-native/test/index.tsx +++ b/types/react-native/test/index.tsx @@ -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; + } + }) +}