-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
99 lines (93 loc) · 2.6 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import React, { useState, useEffect } from "react";
import {
StyleSheet,
KeyboardAvoidingView,
View,
Text,
Image
} from "react-native";
import CurrentWeather from "./components/currentWeather";
import DailyWeather from "./components/dailyWeather";
import Search from "./components/search";
import getData from "./helper";
export default function App() {
const [location, setLocation] = useState(null);
const [weather, setWeather] = useState({});
const [isLoading, setLoading] = useState(true);
useEffect(() => {
if (location) {
getData(location)
.then((weatherData) => setWeather(weatherData))
.catch((err) => console.log(err.message))
.finally(() => setLoading(false));
}
}, [location]);
const initialView = (
<View style={styles.isLoading}>
<Search setLocation={setLocation} style={styles.initialSearch} />
<View style={styles.messageView}>
<Image
source={require("./assets/initial.png")}
style={styles.initialImg}
></Image>
<Text style={styles.initialMessage}>
Search for a City to view Weather Info
</Text>
</View>
</View>
);
const weatherView = (
<>
<Search setLocation={setLocation} />
<CurrentWeather
style={styles.current}
weather={weather}
isLoading={isLoading}
/>
<DailyWeather
style={styles.daily}
weather={weather}
isLoading={isLoading}
/>
</>
);
return (
<KeyboardAvoidingView
style={styles.container}
enabled={Platform.OS === "ios"}
behavior={Platform.OS == "ios" ? "padding" : "height"}
keyboardVerticalOffset={Platform.OS == "ios" ? 0 : 20}
>
{!location ? initialView : weatherView}
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "white",
alignItems: "center",
},
isLoading: {
flex: 1,
alignItems: "center",
},
initialSearch: {
flex: 1,
},
messageView: {
flex: 7,
justifyContent: "center",
alignItems: "center",
paddingBottom: 70,
},
initialImg: {
height: "35%",
width: 350,
marginTop: 70,
},
initialMessage: {
flex: 1,
fontSize: 16,
},
});