-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
150 lines (133 loc) · 3.75 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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import React from 'react';
import {Text, View, ImageBackground} from 'react-native';
import {ScreenOrientation} from 'expo';
import {Clock} from './components/Clock'
import {BusTracker} from "./components/BusTracker";
import {Weather} from "./components/Weather";
import {News} from './components/News'
import {WeatherMini} from "./components/WeatherMini";
import {getImageString} from "./components/helpers"
import * as Font from 'expo-font'
import * as Brightness from 'expo-brightness';
import { activateKeepAwake } from 'expo-keep-awake';
const imgStyle = {
opacity: 0.3
};
const bigBoxStyle = {
boxSizing: 'border-box',
width: '100%',
height: '100%'
};
const column = {
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
alignItems: 'flex-start'
};
const leftBox = {
flex:1,
width: '75%'
};
const rightBox = {
width: '25%'
};
class App extends React.Component{
constructor(props) {
super(props);
this.state = {
dateString: new Date(Date.now()).toLocaleString(),
currWeatherIcon:'partly-cloudy-day',
currWeatherTemp: -999,
currWeatherFeelsLike: -999,
fontLoaded: false
}
activateKeepAwake();
}
changeCurrWeather = (icon, temp, feels) => {
this.setState({
currWeatherIcon: icon,
currWeatherTemp: temp,
currWeatherFeelsLike: feels,
showF: true,
});
};
async componentDidMount() {
ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE);
const { status } = await Brightness.requestPermissionsAsync();
if (status === 'granted') {
Brightness.setSystemBrightnessAsync(0.5);
}
await Font.loadAsync({
'product-sans': require('./assets/fonts/Product_Sans_Regular.ttf')
}).then(() => this.setState({fontLoaded:true}))
this.intervalID = setInterval(
() => this.setState({dateString: new Date(Date.now()).toLocaleString()}),
60000
);
this.intervalIDF = setInterval(
() => this.invertF(),
5000
);
}
componentWillUnmount() {
clearInterval(this.intervalID);
clearInterval(this.intervalIDF);
}
invertF = () => {
const {showF} = this.state;
this.setState({
showF: !showF
})
};
render() {
const {
dateString,
currWeatherIcon,
currWeatherTemp,
currWeatherFeelsLike,
showF, fontLoaded} = this.state;
if (!fontLoaded)
return (
<Text>Loading font {fontLoaded ? 'yup': 'nope'}</Text>
);
const now = new Date(Date.now());
if (now.getHours() > 6 && now.getHours() < 16)
Brightness.setSystemBrightnessAsync(1);
else
Brightness.setSystemBrightnessAsync(0.7);
return(
<ImageBackground
source={{uri: 'https://source.unsplash.com/featured/1600x900/?'.concat(getImageString(currWeatherIcon), '$dateString=', dateString)}}
imageStyle={imgStyle}
style={bigBoxStyle}>
<View>
<View style={column}>
<View style={leftBox}>
<View style={column}>
<View style={leftBox}>
<Clock/>
</View>
<View style={rightBox}>
<WeatherMini currWeatherIcon={currWeatherIcon}
currWeatherTemp={currWeatherTemp}
currWeatherFeelsLike={currWeatherFeelsLike}
showF={showF}
/>
</View>
<Weather
changeCurrWeather={this.changeCurrWeather.bind(this)}
showF={showF}
/>
</View>
<News/>
</View>
<View style={rightBox}>
<BusTracker/>
</View>
</View>
</View>
</ImageBackground>
)
}
}
export default App;