-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
152 lines (142 loc) · 4.66 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
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
151
152
import {
View,
Text,
StatusBar,
StyleSheet,
ImageBackground,
Image,
TouchableHighlight,
} from 'react-native'
import { useEffect, useState } from 'react'
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
import * as React from 'react'
import Phrase from './components/Phrase'
import Settings from './components/Settings'
import DailySaint from './components/Saints'
import {
scheduleAllYearlyNotifications,
getAllScheduledNotifications,
} from './utils/notifications'
import { blue, SHARE_CATEGORY } from './utils/consts'
import { useFonts, Poppins_400Regular } from '@expo-google-fonts/poppins'
import About from './components/About'
import * as Notifications from 'expo-notifications'
import { sharePhrase } from './utils/utils'
import { Loading } from './components/Loading'
import Debug from './components/Debug'
const styles = StyleSheet.create({
view: {
justifyContent: 'center',
alignItems: 'center',
},
logo: {
width: '90%',
height: '20%',
},
backgroundImage: {
width: '112%',
height: '112%',
alignItems: 'center',
justifyContent: 'center',
},
buttons: {
width: 200,
height: 50,
backgroundColor: '#11263B',
justifyContent: 'center',
padding: '2%',
borderRadius: 5,
},
buttonsText: {
color: 'white',
fontSize: 13,
fontFamily: 'Poppins_400Regular',
textAlign: 'center',
},
})
const Stack = createStackNavigator()
const HomeButton = ({ navigation, text }) => (
<TouchableHighlight
onPress={() => navigation.navigate(text.trim())}
style={styles.buttons}
>
<Text allowFontScaling={false} style={styles.buttonsText}>
{text}
</Text>
</TouchableHighlight>
)
const HomeButtonWithPadding = ({ _navigation, _text }) => (
<View style={{ marginTop: 5 }}>
<HomeButton navigation={_navigation} text={_text} />
</View>
)
const HomeScreen = ({ navigation }) => (
<View style={styles.view}>
<StatusBar
backgroundColor="#4a868c"
barStyle="dark-content"
animated={true}
translucent={true}
/>
<ImageBackground
source={require('./assets/background-original.jpg')}
resizeMode={'cover'}
style={styles.backgroundImage}
>
<Image source={require('./assets/logo.png')} style={styles.logo} />
<HomeButton navigation={navigation} text="Frase del día" />
<HomeButtonWithPadding
_navigation={navigation}
_text="Santos del día"
/>
<HomeButtonWithPadding _navigation={navigation} _text="Ajustes" />
<HomeButtonWithPadding
_navigation={navigation}
_text="¿Quiénes Somos?"
/>
{/* <HomeButtonWithPadding _navigation={navigation} _text="Debug" /> */}
</ImageBackground>
</View>
)
// :)
async function init() {
const scheduledNotifs = await getAllScheduledNotifications()
if (scheduledNotifs.length === 0) await scheduleAllYearlyNotifications()
}
export default function App() {
const [backgroundLoaded, setbackgroundLoaded] = useState(false)
const [fontsLoaded] = useFonts({ Poppins_400Regular })
useEffect(() => {
Notifications.addNotificationResponseReceivedListener(notification => {
if (notification.actionIdentifier == SHARE_CATEGORY)
sharePhrase(notification.notification.request.content.body)
})
if (!backgroundLoaded) init().then(_ => setbackgroundLoaded(true))
}, [])
return backgroundLoaded && fontsLoaded ? (
<NavigationContainer>
<Stack.Navigator
screenOptions={{
headerStyle: { backgroundColor: blue },
headerTintColor: 'white',
}}
>
<Stack.Screen
name="Home"
component={HomeScreen}
options={{
headerShown: false,
}}
/>
<Stack.Screen name="Frase del día" component={Phrase} />
<Stack.Screen name="Santos del día" component={DailySaint} />
<Stack.Screen name="Ajustes" component={Settings} />
<Stack.Screen name="¿Quiénes Somos?" component={About} />
{/* <Stack.Screen name="Debug" component={Debug} /> */}
</Stack.Navigator>
</NavigationContainer>
) : (
<Loading />
)
}