-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
101 lines (91 loc) · 2.83 KB
/
App.tsx
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
import React, { useState, useEffect } from 'react';
import { StyleSheet, View, StatusBar, Dimensions, Platform, ScrollView } from 'react-native';
import { GestureHandlerRootView } from 'react-native-gesture-handler';
import Animated, { useAnimatedScrollHandler } from 'react-native-reanimated';
import { useFonts } from 'expo-font';
import { fetchWeatherForecast, WeatherForecast } from './app/services/weatherService';
import HomeScreen from './app/index';
import { SafeAreaProvider } from 'react-native-safe-area-context';
import { LinearGradient } from 'expo-linear-gradient';
const { height: SCREEN_HEIGHT } = Dimensions.get('window');
export default function App() {
const [forecasts, setForecasts] = useState<WeatherForecast[]>([]);
const [location, setLocation] = useState<string>('');
const [forecastTime, setForecastTime] = useState<string>('');
const [fontsLoaded] = useFonts({
'Inter-Bold': require('./assets/fonts/Inter-Bold.ttf'),
});
useEffect(() => {
const loadForecast = async () => {
try {
const data = await fetchWeatherForecast();
setForecasts(data.forecasts);
setLocation(data.location);
setForecastTime(data.forecastTime);
} catch (error: any) {
console.error('Error loading forecast:', error);
}
};
loadForecast();
}, []);
const scrollHandler = useAnimatedScrollHandler((event) => {
'worklet';
// Handle scroll events if needed
});
if (!fontsLoaded) {
return null;
}
const ScrollComponent = Platform.select({
web: ScrollView,
default: Animated.ScrollView,
});
return (
<SafeAreaProvider>
<View style={styles.container}>
<StatusBar barStyle="light-content" />
<LinearGradient
colors={['#0d1b2a', '#1b263b']}
style={StyleSheet.absoluteFillObject}
/>
<GestureHandlerRootView style={styles.gestureHandler}>
<ScrollComponent
onScroll={Platform.OS === 'web' ? undefined : scrollHandler}
scrollEventThrottle={16}
style={styles.scrollView}
contentContainerStyle={styles.scrollContent}
showsVerticalScrollIndicator={false}
>
<HomeScreen
forecasts={forecasts}
location={location}
forecastTime={forecastTime}
/>
</ScrollComponent>
</GestureHandlerRootView>
</View>
</SafeAreaProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#1b263b',
...(Platform.OS === 'web' ? {
height: '100vh',
overflow: 'auto',
} : {}),
},
gestureHandler: {
flex: 1,
},
scrollView: {
flex: 1,
},
scrollContent: {
flexGrow: 1,
backgroundColor: 'transparent',
...(Platform.OS === 'web' ? {
minHeight: '100%',
} : {}),
},
});