@@ -46,10 +46,7 @@ const PermissionRow = ({
4646 status : string ;
4747 onPress : ( ) => void ;
4848} ) => (
49- < TouchableRipple
50- onPress = { ( ) => {
51- onPress ( ) ;
52- } } >
49+ < TouchableRipple onPress = { onPress } >
5350 < List . Item
5451 right = { ( ) => < List . Icon color = { colors [ status ] } icon = { icons [ status ] } /> }
5552 title = { name }
@@ -59,33 +56,36 @@ const PermissionRow = ({
5956) ;
6057
6158interface State {
62- statuses : PermissionStatus [ ] ;
59+ statuses : Partial < Record < Permission , PermissionStatus > > ;
6360 notifications : NotificationsResponse ;
6461}
6562
66- function getSettingString ( setting : boolean | undefined ) {
67- return setting
68- ? RESULTS . GRANTED
69- : setting === false
70- ? RESULTS . DENIED
71- : RESULTS . UNAVAILABLE ;
63+ function toSettingString ( setting : boolean | undefined ) {
64+ switch ( setting ) {
65+ case true :
66+ return RESULTS . GRANTED ;
67+ case false :
68+ return RESULTS . DENIED ;
69+ default :
70+ return RESULTS . UNAVAILABLE ;
71+ }
7272}
7373
7474export default class App extends React . Component < { } , State > {
7575 state : State = {
76- statuses : [ ] ,
76+ statuses : { } ,
7777 notifications : { status : 'unavailable' , settings : { } } ,
7878 } ;
7979
8080 check = ( ) =>
81- Promise . all ( PERMISSIONS_VALUES . map ( ( _ ) => RNPermissions . check ( _ ) ) )
81+ RNPermissions . checkMultiple ( PERMISSIONS_VALUES )
8282 . then ( ( statuses ) => this . setState ( { statuses} ) )
8383 . then ( ( ) => RNPermissions . checkNotifications ( ) )
8484 . then ( ( notifications ) => this . setState ( { notifications} ) )
8585 . catch ( ( error ) => console . warn ( error ) ) ;
8686
8787 refresh = ( ) => {
88- this . setState ( { statuses : [ ] } , this . check ) ;
88+ this . setState ( { statuses : { } } , this . check ) ;
8989 } ;
9090
9191 componentDidMount ( ) {
@@ -124,7 +124,11 @@ export default class App extends React.Component<{}, State> {
124124 data = { Object . keys ( PLATFORM_PERMISSIONS ) }
125125 renderItem = { ( { item, index} ) => {
126126 const value = PERMISSIONS_VALUES [ index ] ;
127- const status = this . state . statuses [ index ] ;
127+ const status = this . state . statuses [ value ] ;
128+
129+ if ( ! status ) {
130+ return null ;
131+ }
128132
129133 return (
130134 < PermissionRow
@@ -133,7 +137,7 @@ export default class App extends React.Component<{}, State> {
133137 onPress = { ( ) => {
134138 RNPermissions . request ( value )
135139 . then ( ( ) => this . check ( ) )
136- . catch ( ( err ) => console . error ( err ) ) ;
140+ . catch ( ( error ) => console . error ( error ) ) ;
137141 } }
138142 />
139143 ) ;
@@ -149,7 +153,7 @@ export default class App extends React.Component<{}, State> {
149153 onPress = { ( ) => {
150154 RNPermissions . requestNotifications ( [ 'alert' , 'badge' , 'sound' ] )
151155 . then ( ( ) => this . check ( ) )
152- . catch ( ( err ) => console . error ( err ) ) ;
156+ . catch ( ( error ) => console . error ( error ) ) ;
153157 } } >
154158 < List . Item
155159 right = { ( ) => (
@@ -164,15 +168,15 @@ export default class App extends React.Component<{}, State> {
164168 </ TouchableRipple >
165169
166170 < Text style = { { margin : 15 , marginTop : 0 , color : '#777' } } >
167- { `alert: ${ getSettingString ( settings . alert ) } \n` }
168- { `badge: ${ getSettingString ( settings . badge ) } \n` }
169- { `sound: ${ getSettingString ( settings . sound ) } \n` }
170- { `lockScreen: ${ getSettingString ( settings . lockScreen ) } \n` }
171- { `notificationCenter: ${ getSettingString (
171+ { `alert: ${ toSettingString ( settings . alert ) } \n` }
172+ { `badge: ${ toSettingString ( settings . badge ) } \n` }
173+ { `sound: ${ toSettingString ( settings . sound ) } \n` }
174+ { `lockScreen: ${ toSettingString ( settings . lockScreen ) } \n` }
175+ { `notificationCenter: ${ toSettingString (
172176 settings . notificationCenter ,
173177 ) } \n`}
174- { `carPlay: ${ getSettingString ( settings . carPlay ) } \n` }
175- { `criticalAlert: ${ getSettingString ( settings . criticalAlert ) } \n` }
178+ { `carPlay: ${ toSettingString ( settings . carPlay ) } \n` }
179+ { `criticalAlert: ${ toSettingString ( settings . criticalAlert ) } \n` }
176180 </ Text >
177181 </ View >
178182 ) ;
0 commit comments