-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbout.js
156 lines (138 loc) · 4.34 KB
/
About.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
151
152
153
154
155
156
import React, {useState, Component} from 'react'
import { TouchableOpacity, Text, StyleSheet, View, Button, FlatList, Modal, fetch } from 'react-native'
import { Actions } from 'react-native-router-flux'
import GoalItem from './components/GoalItem'
import GoalInput from './components/GoalInput'
import ToggleSwitch from 'toggle-switch-react-native'
// Push notification 구현을 위해서 필요
import { Notifications } from 'expo'
import * as Permissions from 'expo-permissions'
import SwitchExample from '../SwitchExample'
const About = () => {
<SwitchExample/>
const goToHome = () => {
Actions.home()
}
//
const [courseGoals, setCourseGoals] = useState([])
const [isAddMode, setIsAddMode] = useState(false)
const addGoalHandler = goalTitle => {
setCourseGoals(currentGoals => [
...currentGoals,
{ id: Math.random().toString(), value: goalTitle }
])
setIsAddMode(false)
}
const removeGoalHandler = goalId => {
setCourseGoals(currentGoals => {
return currentGoals.filter((goal) => goal.id !== goalId )
})
}
const cancelGoalAdditionHandler = () => {
setIsAddMode(false)
}
// Push 알람 받을건지 묻는 함수
askPermissions = async () => {
const { status: existingStatus } = await Permissions.getAsync(
Permissions.NOTIFICATIONS
);
let finalStatus = existingStatus;
if (existingStatus !== "granted") {
const { status } = await Permissions.askAsync(Permissions.NOTIFICATIONS);
finalStatus = status;
}
if (finalStatus !== "granted") {
return false;
}
return true;
};
// 바로 Push 알람 보내는 함수
sendNotificationImmediately = async () => {
let notificationId = await Notifications.presentLocalNotificationAsync({
title: "This is crazy",
body: "Your mind will blow after reading this"
});
console.log(notificationId); // can be saved in AsyncStorage or send to server
};
return (
<View>
{/* <TouchableOpacity style = {{ margin: 128 }} onPress = {goToHome}>
<Text>달라짐?</Text>
</TouchableOpacity> */}
<View style={styles.screen} >
<View >
<Text style={styles.main}>Add your Plan, here!</Text>
</View>
<GoalInput
onAddGoal={addGoalHandler}
onCancel={cancelGoalAdditionHandler}
onChange={(modalon) => !modalon}
/>
<Switch/>
{/* <ToggleSwitch
isOn={false}
onColor="green"
offColor="red"
label="Example label"
labelStyle={{ color: "black", fontWeight: "900" }}
size="large"
onToggle={isOn => !isOn}
/> */}
{/* Push 알람 설정 동의 확인 창이 나오는 함수 */}
{/* 한번만 누르면 됨 */}
<Button
title="Please accept Notifications Permissions"
onPress={() => this.askPermissions()}
/>
{/* 버튼 누르면 바로 Push 알람 옵니다. */}
<Button
title="Send Notification immediately"
onPress={() => this.sendNotificationImmediately()}
/>
{/* 일단은 무시 */}
<Button
title="Dismiss All Notifications"
onPress={() => Notifications.dismissAllNotificationsAsync()}
/>
<Button
title="API"
onPress={() => getInfo()}
/>
<FlatList
keyExtractor={(item, index) => item.id}
data={courseGoals}
renderItem={itemData => <GoalItem id={itemData.item.id} onDelete={removeGoalHandler} title={itemData.item.value}/>}
/>
</View>
<TouchableOpacity style = {{ margin: 128 }}>
<Button title='[뒤로가기]' onPress = {goToHome}/>
</TouchableOpacity>
</View>
)
}
const styles = StyleSheet.create({
screen: {
padding: 50
},
main: {
alignContent: 'center',
fontSize: 20,
},
insuranceItem: {
padding: 10,
marginVertical: 10,
backgroundColor: '#ccc',
borderColor: 'black',
borderWidth: 1
},
card: {
width: 300,
maxWidth: '80%',
alignItems: 'center',
elevation: 8,//andriod에는 shadow안되므로
backgroundColor: 'white',
padding: 20,
borderRadius: 10,
},
})
export default About