-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
128 lines (119 loc) · 3.67 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
import 'react-native-gesture-handler';
import { useEffect } from 'react';
import { StyleSheet, StatusBar, Button, View, Platform } from 'react-native';
import CategoryScreen from './screens/CategoryScreen';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { createDrawerNavigator } from '@react-navigation/drawer';
import MealsOverviewScreen from './screens/MealsOverviewScreen';
import MealDetailScreen from './screens/MealDetailScreen';
import FavoriteScreen from './screens/FavouriteScreen';
import { Provider } from 'react-redux'
import { store } from './store/redux/store';
import * as Notifications from 'expo-notifications';
//import FavoritesContextProvider from './store/context/favourite-context';
const Stack = createNativeStackNavigator();
const Drawer = createDrawerNavigator();
//runs when the app starts
Notifications.setNotificationHandler({
handleNotification: async () => {
return {
shouldPlaySound: false,
shouldSetBadge: false,
shouldShowAlert: true
};
}
});
function DrawerNavigator() {
return (
<>
<Drawer.Navigator screenOptions={{headerStyle: { backgroundColor: '#dea32c' }}}>
<Drawer.Screen name='Categories' component={CategoryScreen} options={{
title: 'All Categories'
}}/>
<Drawer.Screen name='Favourites' component={FavoriteScreen}/>
</Drawer.Navigator>
</>
)
}
export default function App() {
useEffect(() => {
const subscription = Notifications.addNotificationReceivedListener((notification) => {
console.log|('Notification received')
const userName = notification.request.content.data.userName;
});
const subscription2 =Notifications.addNotificationResponseReceivedListener((response) => {
console.log|('Notification Response received')
const userName = response.notification.request.content.data.userName;
console.log(userName)
});
return () => {
subscription.remove();
subscription2.remove();
}
}, []);
async function scheduleNotificationHandler(){
const { status } = await Notifications.requestPermissionsAsync();
if (status !== 'granted') {
alert('Permission not granted!');
return;
}
Notifications.scheduleNotificationAsync({
content: {
title: 'My first local notifications',
body: 'This is the body of the notifications',
data: { userName: 'Clara' }
},
trigger: {
seconds: 5
}
})
}
return (
<>
<StatusBar style='light' />
<Provider store={store}>
<NavigationContainer>
<View style={styles.container}>
<View style={styles.notificationButton}>
<Button title='Notifications' onPress={scheduleNotificationHandler} />
</View>
</View>
<Stack.Navigator screenOptions={{headerStyle: { backgroundColor: '#dea32c' }}}>
<Stack.Screen
name="DrawerScreen"
component={DrawerNavigator}
options={{
headerShown: false
}}
/>
<Stack.Screen
name="MealsOverview"
component={MealsOverviewScreen}
/>
<Stack.Screen
name="MealDetails"
component={MealDetailScreen}
options={{
title: 'About the Meal'
}}
/>
</Stack.Navigator>
</NavigationContainer>
</Provider>
</>
);
}
const styles = StyleSheet.create({
container: {
justifyContent: 'flex-start',
alignItems: 'center',
},
notificationButton: {
width: '80%',
margin: 20,
backgroundColor: '#FFB6C1',
borderRadius: 5,
marginTop: Platform.OS === 'ios' ? 50 : 20,
},
});