/
DetailScreen.js
62 lines (53 loc) · 1.42 KB
/
DetailScreen.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
import React, { Component } from 'react';
import { Alert, ActivityIndicator, AppRegistry, Animated, Text, View, StyleSheet, Button, StatusBar, WebView } from 'react-native';
import { Font } from 'expo';
import {
createStackNavigator,
} from 'react-navigation';
import { keys } from './api';
import { styles } from './style';
class DetailsScreen extends Component {
static navigationOptions = {
header: null,
headerStyle: {
backgroundColor: '#000000',
},
headerTintColor: '#fff',
}
constructor(props){
super(props);
this.state ={ isLoading: true}
}
componentDidMount(){
return fetch('https://api.darksky.net/forecast/36da509268d347e6997fcb8983ced0a4/14.275078,120.996236')
.then((response) => response.json())
.then((responseJson) => {
this.setState({
isLoading: false,
currentForecast: responseJson.currently,
}, function(){
});
})
.catch((error) =>{
console.error(error);
});
}
render() {
if(this.state.isLoading){
return(
<View style={{flex: 1, padding: 20}}>
<ActivityIndicator/>
</View>
)
}
return (
<View style={styles.view}>
<View style={styles.forecastContainer}>
<Text style={styles.forecastCurrent}>
{this.state.currentForecast.summary}</Text>
</View>
</View>
);
}
}
export default DetailsScreen;