1
1
import React , { Component } from 'react' ;
2
2
import PropTypes from 'prop-types' ;
3
- import { View , PermissionsAndroid , Platform } from 'react-native' ;
4
3
import { connect } from 'react-redux' ;
5
4
import { Container } from 'native-base' ;
6
5
import Radar from 'react-native-radar' ;
7
6
import { Actions } from 'react-native-router-flux' ;
8
7
import RNAndroidLocationEnabler from 'react-native-android-location-enabler' ;
8
+ import {
9
+ View , PermissionsAndroid , Platform , StatusBar ,
10
+ } from 'react-native' ;
9
11
10
- import shallowCompare from 'src/utils/shallowCompare' ;
11
- import { updateLocation } from 'src/state/actions/app' ;
12
- import { getCategories , selectCategory , clearListings } from 'src/state/actions/listings' ;
13
12
import SearchBar from 'src/components/SearchBar' ;
14
13
import Salutation from 'src/components/Salutation' ;
14
+ import shallowCompare from 'src/utils/shallowCompare' ;
15
+ import { updateLocation } from 'src/state/actions/app' ;
15
16
import CategoriesList from 'src/components/CategoriesList' ;
16
17
import LoadingIndicator from 'src/components/LoadingIndicator' ;
17
18
import AnimatedContentWrapper from 'src/components/AnimatedContentWrapper' ;
19
+ import { getCategories , selectCategory , clearListings } from 'src/state/actions/listings' ;
18
20
21
+ import { colors } from 'src/theme' ;
19
22
import styles from './styles/HomeScreenStyles' ;
20
23
21
24
@@ -32,47 +35,50 @@ class HomeScreen extends Component {
32
35
33
36
componentDidMount ( ) {
34
37
let granted ;
35
- this . props . getCategories ( this . props . token ) ;
38
+ const { user , loading , catLoading } = this . props ;
36
39
37
- const locationSetup = ( ) => {
38
- // identify the user and request permissions
39
- const { user } = this . props ;
40
- const description = user . name || user . username ;
41
-
42
- Radar . setUserId ( String ( user . id ) ) ;
43
- Radar . setDescription ( description ) ;
44
- Radar . requestPermissions ( false ) ;
45
-
46
- // track the user's location once in the foreground
47
- Radar . trackOnce ( ) . then ( ( result ) => {
48
- // do something with result.events, result.user.geofences
49
- this . props . updateLocation ( result . location ) ;
50
- } ) . catch ( ( ) => {
51
- // optionally, do something with err
52
- } ) ;
53
-
54
- Radar . on ( 'location' , ( result ) => {
55
- this . props . updateLocation ( result . location ) ;
56
- } ) ;
57
- } ;
40
+ this . props . getCategories ( this . props . token ) ;
58
41
59
- if ( Platform . OS === 'android' ) {
60
- RNAndroidLocationEnabler
61
- . promptForEnableLocationIfNeeded ( { interval : 7000 , fastInterval : 3000 } )
62
- . then ( async ( ) => {
63
- // success => {alreadyEnabled: true, enabled: true, status: 'enabled'}
64
- granted = await PermissionsAndroid
65
- . request ( PermissionsAndroid . PERMISSIONS . ACCESS_FINE_LOCATION , {
66
- title : 'WAPI? App needs to access your location 📌' ,
67
- message : 'We need to access to your location '
68
- + 'so that we can personalize your experience. 🙂' ,
69
- } ) ;
70
- if ( granted && Object . keys ( this . props . user ) > 0 ) locationSetup ( ) ;
71
- } ) . catch ( ( ) => { } ) ;
42
+ if ( ! loading && ! catLoading ) {
43
+ const locationSetup = ( ) => {
44
+ // identify the user and request permissions
45
+ const description = user . name || user . username ;
46
+
47
+ Radar . setUserId ( String ( user . id ) ) ;
48
+ Radar . setDescription ( description ) ;
49
+ Radar . requestPermissions ( false ) ;
50
+
51
+ // track the user's location once in the foreground
52
+ Radar . trackOnce ( ) . then ( ( result ) => {
53
+ // do something with result.events, result.user.geofences
54
+ this . props . updateLocation ( result . location ) ;
55
+ } ) . catch ( ( ) => {
56
+ // optionally, do something with err
57
+ } ) ;
58
+
59
+ Radar . on ( 'location' , ( result ) => {
60
+ this . props . updateLocation ( result . location ) ;
61
+ } ) ;
62
+ } ;
63
+
64
+ if ( Platform . OS === 'android' ) {
65
+ RNAndroidLocationEnabler
66
+ . promptForEnableLocationIfNeeded ( { interval : 7000 , fastInterval : 3000 } )
67
+ . then ( async ( ) => {
68
+ // success => {alreadyEnabled: true, enabled: true, status: 'enabled'}
69
+ granted = await PermissionsAndroid
70
+ . request ( PermissionsAndroid . PERMISSIONS . ACCESS_FINE_LOCATION , {
71
+ title : 'WAPI? App needs to access your location 📌' ,
72
+ message : 'We need to access to your location '
73
+ + 'so that we can personalize your experience. 🙂' ,
74
+ } ) ;
75
+ if ( granted && Object . keys ( this . props . user ) . length > 0 ) locationSetup ( ) ;
76
+ } ) . catch ( ( ) => { } ) ;
77
+ }
78
+
79
+ if ( Platform . OS === 'ios' && Object . keys ( this . props . user ) . length > 0 ) locationSetup ( ) ;
72
80
}
73
81
74
- if ( Platform . OS === 'ios' && Object . keys ( this . props . user ) > 0 ) locationSetup ( ) ;
75
-
76
82
this . props . clearListings ( ) ;
77
83
}
78
84
@@ -116,6 +122,7 @@ class HomeScreen extends Component {
116
122
117
123
return (
118
124
< Container style = { styles . container } >
125
+ < StatusBar translucent barStyle = "light-content" backgroundColor = { colors . statusBarTranslucent } />
119
126
< AnimatedContentWrapper
120
127
headerTitle = "Discover"
121
128
showToolbarRightButton = { false }
0 commit comments