-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.android.js
79 lines (73 loc) · 1.6 KB
/
index.android.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
'use strict'
const Api = require('./src/api')
const React = require('react-native')
const {
AppRegistry,
View,
Text,
MapView,
StyleSheet
} = React
const APIKEY = "058e0caee9fe24d810aa10039a9fc8fb"
const Weather = React.createClass({
getInitialState: function() {
return {
pin: {
latitude: 37,
longitude: -95
},
city: '',
temperature: '',
description: ''
}
},
render: function() {
return(
<View style={styles.container}>
<MapView
annotations={[this.state.pin]}
onRegionChangeComplete={this.onRegionChangeComplete}
style={styles.map}>
</MapView>
<View style={styles.textWrapper}>
<Text style={styles.text}>{this.state.city}</Text>
<Text style={styles.text}>{this.state.temperature}</Text>
<Text style={styles.text}>{this.state.description}</Text>
</View>
</View>
)
},
onRegionChangeComplete: function(region) {
this.setState({
pin: {
latitude: region.latitude,
longitude: region.longitude
}
});
Api(region.latitude, region.longitude)
.then((data) => {
console.log(data)
this.setState(data);
});
}
})
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'stretch',
// backgroundColor: '#F5FCFF'
},
map: {
flex: 20,
marginTop: 30
},
textWrapper: {
flex: 10,
alignItems: 'center'
},
text: {
fontSize: 30
}
})
AppRegistry.registerComponent('weatherblah', () => Weather)