-
Notifications
You must be signed in to change notification settings - Fork 0
/
Weather.js
68 lines (65 loc) · 1.6 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
import React from "react";
import { StyleSheet, Text, View, 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-hail",
gradient: ["#0099F7", "#F11712"],
},
Clouds: {
iconName: "weather-cloudy",
gradient: ["#2980b9", "#2c3e50"],
},
Mist: {
iconName: "weather-fog",
gradient: ["#2980b9", "#2c3e50"],
},
Rain: {
iconName: "weather-rainy",
gradient: ["#2980b9", "#2c3e50"],
},
};
export default function Weather({ temp, condition }) {
const { gradient, iconName } = weatherOptions[condition];
return (
<LinearGradient colors={gradient} style={styles.container}>
<StatusBar barStyle="light-content" />
<View style={styles.halfContainer}>
<MaterialCommunityIcons
name={iconName || "weather-sunset"}
size={86}
color="white"
/>
<Text style={styles.temp}>{Math.round(temp)}º</Text>
</View>
<View style={styles.halfContainer}>
<Text style={styles.condition}>{condition}</Text>
</View>
</LinearGradient>
);
}
Weather.PropTypes = {
temp: PropTypes.number.isRequired,
};
const styles = StyleSheet.create({
container: {
alignItems: "center",
justifyContent: "center",
flex: 1,
},
temp: {
fontSize: 40,
color: "white",
},
condition: {
color: "white",
fontSize: 30,
},
halfContainer: {
justifyContent: "center",
alignItems: "center",
flex: 1,
},
});