-
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
Conversation
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why are you adding string
? @krizzu
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.
We have had exact declared 3 types:
Lines 39 to 41 in 803e993
private final String GRANTED = "granted"; | |
private final String DENIED = "denied"; | |
private final String NEVER_ASK_AGAIN = "never_ask_again"; |
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.
@retyui I've added it because of this method resolve with PermissionStatus
. I'm not quite sure if I could add literals in Spec, so I ended up with adding string
to the type.
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.
@krizzu
Now Spec
is source of truth
You should move PermissionStatus
type into Libraries/PermissionsAndroid/NativePermissionsAndroid.js
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.
@retyui
Gotcha. Done that.
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.
Code analysis results:
eslint
found some issues. Runyarn lint --fix
to automatically fix problems.
@@ -11,6 +11,9 @@ | |||
'use strict'; | |||
|
|||
const NativeModules = require('../BatchedBridge/NativeModules'); | |||
import NativePermissionsAndroid from './NativePermissionsAndroid'; | |||
|
|||
import type {PermissionStatus} from './NativePermissionsAndroid' |
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: Insert ;
@@ -11,6 +11,9 @@ | |||
'use strict'; | |||
|
|||
const NativeModules = require('../BatchedBridge/NativeModules'); | |||
import NativePermissionsAndroid from './NativePermissionsAndroid'; | |||
|
|||
import type {PermissionStatus} from './NativePermissionsAndroid' |
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.
semi: Missing semicolon.
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.
This is great! Thanks. 😁
permission: string, | ||
) => Promise<boolean>; | ||
|
||
+requestMultiplePermissions: (permissions: Array<string>) => Promise<Object>; |
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.
Promise<Object>
=> Promise<{[permission: string]: PermissionStatus}>
How about making more strict permission? |
@retyui I'm up for it. Moved permissions to |
78d5707
to
68d987c
Compare
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.
Code analysis results:
eslint
found some issues. Runyarn lint --fix
to automatically fix problems.
* @flow | ||
*/ | ||
|
||
'use strict'; |
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 ⏎
}); | ||
|
||
export type PermissionStatus = $Values<typeof PERMISSION_REQUEST_RESULT>; | ||
export type PermissionType = $Values<typeof 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: Insert ;
|
||
export type PermissionStatus = $Values<typeof PERMISSION_REQUEST_RESULT>; | ||
export type PermissionType = $Values<typeof 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: Insert ;
) => Promise<boolean>; | ||
|
||
+requestMultiplePermissions: ( | ||
permissions: Array<PermissionType>, |
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: Replace permissions:·Array<PermissionType>)·=>·Promise<{[permission:·PermissionType]:·PermissionStatus}>
with ⏎····permissions:·Array<PermissionType>,⏎··)·=>·Promise<{[permission:·PermissionType]:·PermissionStatus}>;
@@ -11,6 +11,15 @@ | |||
'use strict'; | |||
|
|||
const NativeModules = require('../BatchedBridge/NativeModules'); | |||
import NativePermissionsAndroid, { |
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: Replace PERMISSION_REQUEST_RESULT,·PERMISSIONS
with ⏎··PERMISSION_REQUEST_RESULT,⏎··PERMISSIONS,⏎
@@ -11,6 +11,15 @@ | |||
'use strict'; | |||
|
|||
const NativeModules = require('../BatchedBridge/NativeModules'); | |||
import NativePermissionsAndroid, { | |||
PERMISSION_REQUEST_RESULT, | |||
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: Replace PermissionStatus,·PermissionType}·from·'./NativePermissionsAndroid'
with ⏎··PermissionStatus,⏎··PermissionType,⏎}·from·'./NativePermissionsAndroid';
@@ -11,6 +11,15 @@ | |||
'use strict'; | |||
|
|||
const NativeModules = require('../BatchedBridge/NativeModules'); | |||
import NativePermissionsAndroid, { | |||
PERMISSION_REQUEST_RESULT, | |||
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.
semi: Missing semicolon.
Another question: This module is Android only. Would |
It would return null, so you may need to wait for that to land to use it, or go ahead and protect call sites perhaps.
Sent via Superhuman iOS ( https://sprh.mn/?vip=ericlewis777@gmail.com )
…On Fri, May 17 2019 at 5:25 AM, < ***@***.*** > wrote:
Another question: This module is Android only. Would TurboModuleRegistry.getEnforcing<Spec>('PermissionsAndroid')
throw/return null on iOS then?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub (
#24886?email_source=notifications&email_token=AAFEVR4NQT2HWSAXLD43KX3PVZ2XLA5CNFSM4HNKQI6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVUH3WA#issuecomment-493387224
) , or mute the thread (
https://github.com/notifications/unsubscribe-auth/AAFEVR63ROP4CNWQ46ODEB3PVZ2XLANCNFSM4HNKQI6A
).
|
@ericlewis You think that checking for the platform at the call site and returning negatively when it's not Android? |
Correct.
Sent via Superhuman iOS ( https://sprh.mn/?vip=ericlewis777@gmail.com )
…On Sun, May 19 2019 at 7:44 AM, < ***@***.*** > wrote:
@ericlewis ( https://github.com/ericlewis ) You think that checking for the
platform at the call site and returning negatively when it's Android?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub (
#24886?email_source=notifications&email_token=AAFEVRZCKEGMUBVZGJRGWQLPWE4SBA5CNFSM4HNKQI6KYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGODVXAMUQ#issuecomment-493749842
) , or mute the thread (
https://github.com/notifications/unsubscribe-auth/AAFEVRY2FT3FOH65V5VYSADPWE4SBANCNFSM4HNKQI6A
).
|
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.
Code analysis results:
eslint
found some issues. Runyarn lint --fix
to automatically fix problems.
@@ -77,11 +48,13 @@ class PermissionsAndroid { | |||
* | |||
* @deprecated | |||
*/ | |||
checkPermission(permission: string): Promise<boolean> { | |||
checkPermission(permission: PermissionType): Promise<boolean> { | |||
console.warn( | |||
'"PermissionsAndroid.checkPermission" is deprecated. Use "PermissionsAndroid.check" instead', | |||
); |
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.
curly: Expected { after 'if' condition.
@@ -90,8 +63,9 @@ 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 comment
The reason will be displayed to describe this comment to others. Learn more.
curly: Expected { after 'if' condition.
@@ -109,12 +83,14 @@ class PermissionsAndroid { | |||
* @deprecated | |||
*/ | |||
async requestPermission( | |||
permission: string, | |||
permission: PermissionType, | |||
rationale?: Rationale, | |||
): Promise<boolean> { |
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.
curly: Expected { after 'if' condition.
@@ -126,11 +102,13 @@ class PermissionsAndroid { | |||
* See https://facebook.github.io/react-native/docs/permissionsandroid.html#request | |||
*/ | |||
async request( |
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.
curly: Expected { after 'if' condition.
@@ -158,11 +134,11 @@ class PermissionsAndroid { | |||
* See https://facebook.github.io/react-native/docs/permissionsandroid.html#requestmultiple | |||
*/ | |||
requestMultiple( | |||
permissions: Array<string>, |
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.
curly: Expected { after 'if' condition.
7e82647
to
0e0e926
Compare
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.
Sorry for the confusion, but the typing should not add any cost to the JS bundle size. That said, let's just define union types inline, instead of defining a frozen object:
Instead of:
export const PERMISSION_REQUEST_RESULT = Object.freeze({
GRANTED: 'granted',
DENIED: 'denied',
NEVER_ASK_AGAIN: 'never_ask_again',
});
export type PermissionStatus = $Values<typeof PERMISSION_REQUEST_RESULT>;
do:
export type PermissionStatus = 'granted' | 'denied' | 'never_ask_again';
Also, can you run prettier formatter?
@fkgozali |
Cool, but for the purpose for using Flow type to generate the C++/ObjC/Java code, we need the type to be fully inline for enum (can't use $Values<> atm), so we'll have to create the types without modifying the usage of
|
I can get acquainted with your native code generator? |
to simplify, you could just use string type for the enums for the time being
|
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.
@fkgozali has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
This pull request was successfully merged by @krizzu in 82fe1b0. When will my fix make it into a release? | Upcoming Releases |
Summary: Part of facebook#24875 ## Changelog [General] [Added] - Add TurboModule spec for PermissionsAndroid Pull Request resolved: facebook#24886 Reviewed By: RSNara Differential Revision: D15542996 Pulled By: fkgozali fbshipit-source-id: cab02d97e70d65347f63e891cff98c17adc1fdba
Summary
Part of #24875
Changelog
[General] [Added] - Add TurboModule spec for PermissionsAndroid
Test Plan
Flow passes on root level