11// @flow
22
3- import React , { Component } from 'react'
3+ import React , { Component } from 'react' ;
4+
45import {
56 StyleSheet ,
67 TouchableHighlight ,
@@ -9,38 +10,38 @@ import {
910 Alert ,
1011 AppState ,
1112 Platform ,
12- } from 'react-native'
13+ } from 'react-native' ;
1314
14- import Permissions from 'react-native-permissions'
15+ import Permissions from 'react-native-permissions' ;
1516
1617export default class App extends Component {
1718 state = {
1819 types : [ ] ,
1920 status : { } ,
20- }
21+ } ;
2122
2223 componentDidMount ( ) {
23- let types = Permissions . getTypes ( )
24- let canOpenSettings = Permissions . canOpenSettings ( )
24+ let types = Permissions . getTypes ( ) ;
25+ let canOpenSettings = Permissions . canOpenSettings ( ) ;
2526
26- this . setState ( { types, canOpenSettings } )
27- this . _updatePermissions ( types )
28- AppState . addEventListener ( 'change' , this . _handleAppStateChange )
27+ this . setState ( { types, canOpenSettings} ) ;
28+ this . _updatePermissions ( types ) ;
29+ AppState . addEventListener ( 'change' , this . _handleAppStateChange ) ;
2930 }
3031
3132 componentWillUnmount ( ) {
32- AppState . removeEventListener ( 'change' , this . _handleAppStateChange )
33+ AppState . removeEventListener ( 'change' , this . _handleAppStateChange ) ;
3334 }
3435
3536 //update permissions when app comes back from settings
3637 _handleAppStateChange = appState => {
3738 if ( appState == 'active' ) {
38- this . _updatePermissions ( this . state . types )
39+ this . _updatePermissions ( this . state . types ) ;
3940 }
40- }
41+ } ;
4142
4243 _openSettings = ( ) =>
43- Permissions . openSettings ( ) . then ( ( ) => alert ( 'back to app!!' ) )
44+ Permissions . openSettings ( ) . then ( ( ) => alert ( 'back to app!!' ) ) ;
4445
4546 _updatePermissions = types => {
4647 Permissions . checkMultiple ( types )
@@ -49,47 +50,47 @@ export default class App extends Component {
4950 return Permissions . check ( 'location' , 'always' ) . then ( location => ( {
5051 ...status ,
5152 location,
52- } ) )
53+ } ) ) ;
5354 }
54- return status
55+ return status ;
5556 } )
56- . then ( status => this . setState ( { status } ) )
57- }
57+ . then ( status => this . setState ( { status} ) ) ;
58+ } ;
5859
5960 _requestPermission = permission => {
60- var options
61+ var options ;
6162
6263 if ( permission == 'location' ) {
63- options = this . state . isAlways ? 'always' : 'whenInUse'
64+ options = this . state . isAlways ? 'always' : 'whenInUse' ;
6465 }
6566
6667 Permissions . request ( permission , options )
6768 . then ( res => {
6869 this . setState ( {
69- status : { ...this . state . status , [ permission ] : res } ,
70- } )
70+ status : { ...this . state . status , [ permission ] : res } ,
71+ } ) ;
7172 if ( res != 'authorized' ) {
72- var buttons = [ { text : 'Cancel' , style : 'cancel' } ]
73+ var buttons = [ { text : 'Cancel' , style : 'cancel' } ] ;
7374 if ( this . state . canOpenSettings )
7475 buttons . push ( {
7576 text : 'Open Settings' ,
7677 onPress : this . _openSettings ,
77- } )
78+ } ) ;
7879
7980 Alert . alert (
8081 'Whoops!' ,
8182 'There was a problem getting your permission. Please enable it from settings.' ,
8283 buttons ,
83- )
84+ ) ;
8485 }
8586 } )
86- . catch ( e => console . warn ( e ) )
87- }
87+ . catch ( e => console . warn ( e ) ) ;
88+ } ;
8889
8990 _onLocationSwitchChange = ( ) => {
90- this . setState ( { isAlways : ! this . state . isAlways } )
91- this . _updatePermissions ( this . state . types )
92- }
91+ this . setState ( { isAlways : ! this . state . isAlways } ) ;
92+ this . _updatePermissions ( this . state . types ) ;
93+ } ;
9394
9495 render ( ) {
9596 return (
@@ -98,8 +99,7 @@ export default class App extends Component {
9899 < TouchableHighlight
99100 style = { [ styles . button , styles [ this . state . status [ p ] ] ] }
100101 key = { p }
101- onPress = { ( ) => this . _requestPermission ( p ) }
102- >
102+ onPress = { ( ) => this . _requestPermission ( p ) } >
103103 < View >
104104 < Text style = { styles . text } >
105105 { Platform . OS == 'ios' && p == 'location'
@@ -113,8 +113,7 @@ export default class App extends Component {
113113 < View style = { styles . footer } >
114114 < TouchableHighlight
115115 style = { styles [ 'footer_' + Platform . OS ] }
116- onPress = { this . _onLocationSwitchChange }
117- >
116+ onPress = { this . _onLocationSwitchChange } >
118117 < Text style = { styles . text } > Toggle location type</ Text >
119118 </ TouchableHighlight >
120119
@@ -131,7 +130,7 @@ export default class App extends Component {
131130 crash. This is normal on iOS. Google "ios crash permission change"
132131 </ Text >
133132 </ View >
134- )
133+ ) ;
135134 }
136135}
137136
@@ -179,4 +178,4 @@ const styles = StyleSheet.create({
179178 height : 0 ,
180179 width : 0 ,
181180 } ,
182- } )
181+ } ) ;
0 commit comments