-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
65 lines (53 loc) · 1.77 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
65
import { StatusBar } from 'expo-status-bar';
import React, {useEffect,useState} from 'react'
import { StyleSheet, View, ImageBackground } from 'react-native';
import * as Location from 'expo-location';
import { useFonts, Scada_400Regular } from '@expo-google-fonts/scada';
import DateTime from './components/DateTime';
import WeatherScroll from './components/WeatherScroll';
const API_KEY = '1ea87fd965b57956c429979417f99052';
const img = require ('./assets/4.jpg')
export default function App() {
const [data, setData] = useState({});
useEffect(() => {
(async () => {
let { status } = await Location.requestForegroundPermissionsAsync();
if (status !== 'granted') {
fetchDataFromApi("40.7128", "-74.0060")
return;
}
let location = await Location.getCurrentPositionAsync({});
fetchDataFromApi(location.coords.latitude, location.coords.longitude);
})();
}, [])
const fetchDataFromApi = (latitude, longitude) => {
if(latitude && longitude) {
fetch(`https://api.openweathermap.org/data/2.5/onecall?lat=${latitude}&lon=${longitude}&exclude=hourly,minutely&units=metric&appid=${API_KEY}`).then(res => res.json()).then(data => {
// console.log(data)
setData(data)
})
}
}
let [fontsLoaded] = useFonts({
Scada_400Regular,
});
return (
<View style={styles.container}>
<ImageBackground source={img} style={styles.image}>
<DateTime current={data.current} timezone={data.timezone} lat={data.lat} lon={data.lon}/>
<WeatherScroll weatherData={data.daily}/>
</ImageBackground>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
fontFamily: 'Scada_400Regular',
},
image: {
flex:1,
resizeMode: "cover",
justifyContent: "center"
}
});