-
Notifications
You must be signed in to change notification settings - Fork 24.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TM] add spec for PermissionsAndroid #24886
Changes from 1 commit
cc751d1
eba4024
68d987c
0e0e926
bc1b5eb
e20c745
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @format | ||
* @flow | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import type {TurboModule} from 'RCTExport'; | ||
import * as TurboModuleRegistry from 'TurboModuleRegistry'; | ||
|
||
export interface Spec extends TurboModule { | ||
+checkPermission: (permission: string) => Promise<boolean>; | ||
|
||
+requestPermission: (permission: string) => Promise<string>; | ||
|
||
+shouldShowRequestPermissionRationale: ( | ||
permission: string, | ||
) => Promise<boolean>; | ||
|
||
+requestMultiplePermissions: (permissions: Array<string>) => Promise<Object>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} | ||
|
||
export default TurboModuleRegistry.getEnforcing<Spec>('PermissionsAndroid'); |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -11,6 +11,7 @@ | |||||||
'use strict'; | ||||||||
|
||||||||
const NativeModules = require('../BatchedBridge/NativeModules'); | ||||||||
import NativePermissionsAndroid from './NativePermissionsAndroid'; | ||||||||
|
||||||||
export type Rationale = { | ||||||||
title: string, | ||||||||
|
@@ -20,7 +21,7 @@ export type Rationale = { | |||||||
buttonNeutral?: string, | ||||||||
}; | ||||||||
|
||||||||
type PermissionStatus = 'granted' | 'denied' | 'never_ask_again'; | ||||||||
type PermissionStatus = 'granted' | 'denied' | 'never_ask_again' | string; | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you adding There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have had exact declared 3 types: Lines 39 to 41 in 803e993
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @retyui I've added it because of this method resolve with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @krizzu You should move There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @retyui |
||||||||
/** | ||||||||
* `PermissionsAndroid` provides access to Android M's new permissions model. | ||||||||
* | ||||||||
|
@@ -81,7 +82,7 @@ class PermissionsAndroid { | |||||||
console.warn( | ||||||||
'"PermissionsAndroid.checkPermission" is deprecated. Use "PermissionsAndroid.check" instead', | ||||||||
); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curly: Expected { after 'if' condition. |
||||||||
return NativeModules.PermissionsAndroid.checkPermission(permission); | ||||||||
return NativePermissionsAndroid.checkPermission(permission); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
|
@@ -91,7 +92,7 @@ class PermissionsAndroid { | |||||||
* See https://facebook.github.io/react-native/docs/permissionsandroid.html#check | ||||||||
*/ | ||||||||
check(permission: string): Promise<boolean> { | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curly: Expected { after 'if' condition. |
||||||||
return NativeModules.PermissionsAndroid.checkPermission(permission); | ||||||||
return NativePermissionsAndroid.checkPermission(permission); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
|
@@ -130,7 +131,7 @@ class PermissionsAndroid { | |||||||
rationale?: Rationale, | ||||||||
): Promise<PermissionStatus> { | ||||||||
if (rationale) { | ||||||||
const shouldShowRationale = await NativeModules.PermissionsAndroid.shouldShowRequestPermissionRationale( | ||||||||
const shouldShowRationale = await NativePermissionsAndroid.shouldShowRequestPermissionRationale( | ||||||||
permission, | ||||||||
); | ||||||||
|
||||||||
|
@@ -140,14 +141,12 @@ class PermissionsAndroid { | |||||||
rationale, | ||||||||
() => reject(new Error('Error showing rationale')), | ||||||||
() => | ||||||||
resolve( | ||||||||
NativeModules.PermissionsAndroid.requestPermission(permission), | ||||||||
), | ||||||||
resolve(NativePermissionsAndroid.requestPermission(permission)), | ||||||||
); | ||||||||
}); | ||||||||
} | ||||||||
} | ||||||||
return NativeModules.PermissionsAndroid.requestPermission(permission); | ||||||||
return NativePermissionsAndroid.requestPermission(permission); | ||||||||
} | ||||||||
|
||||||||
/** | ||||||||
|
@@ -160,9 +159,7 @@ class PermissionsAndroid { | |||||||
requestMultiple( | ||||||||
permissions: Array<string>, | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. curly: Expected { after 'if' condition. |
||||||||
): Promise<{[permission: string]: PermissionStatus}> { | ||||||||
return NativeModules.PermissionsAndroid.requestMultiplePermissions( | ||||||||
permissions, | ||||||||
); | ||||||||
return NativePermissionsAndroid.requestMultiplePermissions(permissions); | ||||||||
} | ||||||||
} | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prettier/prettier: Delete
⏎