-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWeather.js
136 lines (132 loc) · 3.5 KB
/
Weather.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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import React from "react";
import { StyleSheet, View, Text, StatusBar } from "react-native";
import PropTypes from "prop-types";
import { MaterialCommunityIcons } from "@expo/vector-icons";
import { LinearGradient } from "expo-linear-gradient";
const weatherOptions = {
Haze: {
iconName: "weather-fog",
gradient: ["#4DA0B0", "#D39D38"],
subtitle: "Consider wearing a mask"
},
Thunderstorm: {
iconName: "weather-lightning",
gradient: ["#373B44", "#4286f4"],
subtitle: "Be aware!"
},
Drizzle: {
iconName: "weather-rainy",
gradient: ["#89F7FE", "#66A6FF"],
subtitle: "Maybe an extra jacket?"
},
Rain: {
iconName: "weather-pouring",
gradient: ["#00C6FB", "#005BEA"],
subtitle: "Take an umbrella with you"
},
Snow: {
iconName: "weather-snowy",
gradient: ["#7DE2FC", "#B9B6E5"],
subtitle: "Take out your winter boots!"
},
Atmosphere: {
iconName: "weather-cloudy",
gradient: ["#89F7FE", "#66A6FF"],
subtitle: "Look out the window"
},
Clear: {
iconName: "weather-sunny",
gradient: ["#FF7300", "#FEF253"],
subtitle: "Nice weather to go out!"
},
Clouds: {
iconName: "weather-cloudy",
gradient: ["#D7D2CC", "#304352"],
subtitle: "Who likes a cloudy weather?"
},
Mist: {
iconName: "weather-hail",
gradient: ["#4DA0B0", "#D39D38"],
subtitle: "Moist moist moist"
},
Dust: {
iconName: "weather-fog",
gradient: ["#4DA0B0", "#D39D38"],
subtitle: "Consider wearing a mask"
}
};
export default function Weather({ temp, condition }) {
return (
<LinearGradient
style={styles.container}
colors={weatherOptions[condition].gradient}>
<StatusBar barStyle="light-content" />
<View style={styles.topHalfContainer}>
<MaterialCommunityIcons
size={96}
name={weatherOptions[condition].iconName}
color="white" />
<Text style={styles.temp}>{temp}°</Text>
</View>
<View style={{...styles.bottomHalfContainer, ...styles.textContainer}}>
<Text style={styles.title}>{condition}</Text>
<Text style={styles.subtitle}>{weatherOptions[condition].subtitle}</Text>
</View>
</LinearGradient>
);
}
Weather.propTypes = {
temp: PropTypes.number.isRequired,
condition: PropTypes.oneOf([
"Thunderstorm",
"Drizzle",
"Rain",
"Snow",
"Atmosphere",
"Clear",
"Clouds",
"Mist",
"Haze",
"Smoke",
"Dust",
"Fog",
"Sand",
"Ash",
"Squall",
"Tornado",
]).isRequired,
};
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: "center",
alignItems: "center",
},
topHalfContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center"
},
bottomHalfContainer: {
flex: 1,
justifyContent: "center",
alignItems: "center"
},
temp: {
color: "white",
fontSize: 42
},
title: {
color: "white",
fontSize: 44,
fontWeight: "300",
marginBottom: 10
},
subtitle: {
color: "white",
fontSize: 24
},
textContainer: {
alignItems: "flex-start"
}
});