-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.js
64 lines (60 loc) · 1.5 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import MapboxGL from '@mapbox/react-native-mapbox-gl';
export default class App extends Component<{}> {
constructor (props) {
super(props);
this.state = {
isFetchingAndroidPermission: Platform.OS === 'android',
isAndroidPermissionGranted: false,
};
}
async componentWillMount () {
if (Platform.OS === 'android') {
const isGranted = await MapboxGL.requestAndroidLocationPermissions();
this.setState({
isAndroidPermissionGranted: isGranted,
isFetchingAndroidPermission: false,
});
}
MapboxGL.setAccessToken("pk.NO_ACCESS_TOKEN");
}
render() {
if (Platform.OS === 'android' && !this.state.isAndroidPermissionGranted) {
if (this.state.isFetchingAndroidPermission) {
return null;
}
return (
<View style={{flex: 1}}>
<Text style={styles.noPermissionsText}>
You need to accept location permissions in order to use this example applications
</Text>
</View>
);
}
return (
<MapboxGL.MapView
zoomLevel={16}
centerCoordinate={[139.766403, 35.681262]}
styleURL="PATH TO YOUR style.json"
style={{flex: 1}}
/>
);
}
}
const styles = StyleSheet.create({
noPermissionsText: {
fontSize: 18,
fontWeight: 'bold',
},
});