-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAbout.js
260 lines (245 loc) · 6.63 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
import React, { useState, Component } from "react";
import {
TouchableOpacity,
Text,
StyleSheet,
Image,
View,
Button,
FlatList,
Modal,
fetch
} from "react-native";
import {
Container,
Header,
Content,
Footer,
FooterTab,
Button as Btn,
Icon,
Badge,
Left,
Right,
Card,
CardItem
} from "native-base";
import GoalItem from "./components/GoalItem";
import GoalInput from "./components/GoalInput";
import ToggleSwitch from "toggle-switch-react-native";
import { Notifications } from "expo";
import * as Permissions from "expo-permissions";
import { Actions } from "react-native-router-flux";
// import Switch from ".components/Switch";
const goToReward = () => {
Actions.reward();
};
const About = () => {
const [onMode, setIsOn] = useState(true)
const handleMode = (onMode) => setIsOn(!onMode)
// <Switch />;
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: "마라톤 경주 일정이 곧 찾아옵니다!",
body: "안전한 완주를 원하신다면 클릭하세요!:)"
});
console.log(notificationId); // can be saved in AsyncStorage or send to server
};
return (
<Container>
<Header style={styles.header}>
<Text style={styles.headerTextContent}>Plan-IT</Text>
<Right>
<Btn style={styles.btn}>
<Icon name="person" />
</Btn>
<Btn style={styles.btn}>
<Icon name="menu" />
</Btn>
</Right>
</Header>
<Content>
<View style={styles.screen}>
<Card>
<Text style={styles.txt1}>신영훈님의</Text>
<Text style={styles.txt2}>일정을 관리해보세요!</Text>
</Card>
<GoalInput
onAddGoal={addGoalHandler}
onCancel={cancelGoalAdditionHandler}
/>
<FlatList
keyExtractor={(item, index) => item.id}
data={courseGoals}
renderItem={itemData => (
<GoalItem
id={itemData.item.id}
onDelete={removeGoalHandler}
title={itemData.item.value}
/>
)}
/>
<View style={styles.toggle}>
<ToggleSwitch
isOn={onMode}
onPress={handleMode}
onColor="yellowgreen"
offColor="#595959"
style={styles.switch}
label="보험 스위치 ON/OFF"
labelStyle={styles.switchLabel}
size="small"
/>
</View>
{/* Push 알람 설정 동의 확인 창이 나오는 함수 */}
{/* 한번만 누르면 됨 */}
{/* <Text>Push 알람 설정</Text> */}
<View marginTop={30}>
<Button style={styles.pushbtn1}
title="Push 알람 설정에 동의하시나요?"
onPress={() => this.askPermissions()}
/>
{/* 버튼 누르면 바로 Push 알람 옵니다. */}
<Button style={styles.pushbtn2}
title="바로 Push 알람 받아보기"
onPress={() => this.sendNotificationImmediately()}
/>
</View>
</View>
</Content>
<Footer>
<FooterTab style={styles.footer}>
<Btn vertical onPress={goToReward}>
<Icon name="ribbon" />
<Text style={styles.footer_text}>리워드샵</Text>
</Btn>
<Btn active vertical style={styles.btn} onPress={goToHome}>
<Icon name="home" />
<Text style={styles.footer_text}>홈</Text>
</Btn>
<Btn vertical>
<Icon name="chatbubbles" />
<Text style={styles.footer_text}>커뮤니티</Text>
</Btn>
</FooterTab>
</Footer>
</Container>
);
};
const styles = StyleSheet.create({
header: {
backgroundColor: "dodgerblue",
textAlign: "auto"
},
headerTextContent: {
color: "white",
fontWeight: "900",
fontSize: 20,
textAlignVertical: "center"
},
screen: {
padding: 20,
},
txt1: {
color: "darkslategray",
textAlign: "left",
fontWeight: "bold",
fontSize: 25,
marginLeft: 27,
marginTop: 80
},
txt2: {
color: "darkslategray",
textAlign: "left",
fontWeight: "bold",
fontSize: 25,
marginLeft: 27,
marginBottom: 80
},
insuranceItem: {
padding: 10,
marginVertical: 10,
backgroundColor: "#ccc",
borderColor: "black",
borderWidth: 1
},
card: {
width: 300,
maxWidth: "80%",
alignItems: "center",
elevation: 8,
backgroundColor: "snow",
padding: 20,
borderRadius: 10
},
footer: {
backgroundColor: "dodgerblue"
},
btn: {
backgroundColor: "dodgerblue"
},
footer_text: {
color: "white",
textShadowColor: "black"
},
toggle: {
marginTop: 10,
marginStart: 175,
marginBottom: 10,
},
switch: {
color: "blue",
fontWeight: "bold",
textAlign: "right",
marginLeft: 40,
marginTop: 20,
marginBottom: 20,
},
switchLabel: {
color: "dodgerblue",
fontWeight: "bold",
},
pushbtn1 : {
marginTop: 30,
marginBottom: 10,
width: "97%",
// color: "blue"
},
});
export default About;