-
Notifications
You must be signed in to change notification settings - Fork 2
/
app-components.js
109 lines (98 loc) · 3.34 KB
/
app-components.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
import React, {useRef, useState, useEffect} from 'react';
import RNLocation from 'react-native-location';
import {StyleSheet, View, ScrollView} from 'react-native';
import Mountain from './background-components/mountain';
import Husky from './husky';
import Temperature from './weather/temperature';
import Clouds from './weather/clouds';
import Stars from './stars/stars';
import SettingsIconButton from './background-components/settings-icon-button';
import {fullRelativeWidth, skyColor, darkSkyColor} from './assets/style_bits';
import {openWeatherRequest} from './constants/open-weather';
import DenyLocationModal from './deny-location-modal';
import Snow from 'react-native-snow';
import {SafeAreaView} from 'react-native-safe-area-context';
const AppComponents = ({
navigation,
refreshing,
weatherResponse,
temperatureUnit,
}) => {
const [modalVisible, setModalVisible] = useState(false);
const [avgTemp, setAvgTemp] = useState('--');
const [currentTemp, setCurrentTemp] = useState('--');
const [tempMin, setTempMin] = useState('--');
const [tempMax, setTempMax] = useState('--');
const [isThemeLight, setIsThemeLight] = useState(skyColor);
const [weatherConditions, setWeatherConditions] = useState('Clear');
const [currentWeatherIcon, setCurrentWeatherIcon] = useState('');
useEffect(() => {
if (weatherResponse.current !== undefined) {
setTemperatures(weatherResponse);
}
}, [weatherResponse]);
const setTemperatures = (response) => {
let averageTemp;
const weatherIcon = response.current.weather[0].icon;
const averageWeatherIcon = response.daily.weather[0].icon;
if (weatherIcon.includes('d')) {
setIsThemeLight(true);
setAvgTemp(Math.round(response.daily.temp.day));
setCurrentWeatherIcon(averageWeatherIcon.substring(0, 2) + 'd');
} else {
setIsThemeLight(false);
setAvgTemp(Math.round(response.daily.temp.night));
setCurrentWeatherIcon(averageWeatherIcon.substring(0, 2) + 'n');
}
setWeatherConditions(response.daily.weather[0].main);
setTempMax(response.daily.temp.max);
setTempMin(response.daily.temp.min);
const currentRoundedTemperature = Math.round(response.current.temp);
setCurrentTemp(currentRoundedTemperature);
};
const displaySkyColor = () => {
if (isThemeLight) {
return skyColor;
} else {
return darkSkyColor;
}
};
return (
<SafeAreaView
style={{
...styles.container,
backgroundColor: displaySkyColor(),
}}>
<DenyLocationModal
modalVisible={modalVisible}
setModalVisible={setModalVisible}
/>
{weatherConditions === 'Clouds' ? (
<Clouds isThemeLight={isThemeLight} />
) : null}
<Temperature
avgTemp={avgTemp}
currentTemp={currentTemp}
tempMax={tempMax}
tempMin={tempMin}
currentWeatherIcon={currentWeatherIcon}
isThemeLight={isThemeLight}
temperatureUnit={temperatureUnit}
/>
{!isThemeLight && <Stars />}
{weatherConditions === 'Snow' ? <Snow snowfall="medium" /> : null}
<Mountain />
<Husky />
<SettingsIconButton navigation={navigation} />
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
paddingTop: 30,
},
});
export default AppComponents;