-
Notifications
You must be signed in to change notification settings - Fork 1
/
App.tsx
155 lines (150 loc) · 3.96 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
153
154
155
import { MaterialCommunityIcons } from "@expo/vector-icons";
import React, { useState } from "react";
import { SafeAreaView, StyleSheet, Text, View } from "react-native";
import { GestureHandlerRootView } from "react-native-gesture-handler";
import Animated, { SlideInDown, SlideInUp } from "react-native-reanimated";
import { AnimatedButton, SwipeableCard } from "./components";
const tasks = [
"Drink 5 glasses of water",
"Read a book",
"Go for a walk",
"Eat a healthy meal",
"Sleep for 8 hours",
];
export default function App() {
const [todos, setTodos] = useState<any[]>([...tasks, ...tasks, ...tasks]);
const [swipeDirection, setSwipeDirection] = useState<"LEFT" | "RIGHT" | "">(
""
);
const updateTodos = () => {
setTodos(todos.slice(1));
};
return (
<GestureHandlerRootView
style={{
flex: 1,
}}
>
<SafeAreaView
style={{
backgroundColor: "#98B9D4",
}}
/>
<View style={styles.container}>
<Text style={styles.heading}>Goals</Text>
<View
style={{
alignItems: "center",
justifyContent: "center",
height: todos.length === 0 ? "100%" : "auto",
}}
>
{todos.length === 0 ? (
<Animated.Text
style={{
fontSize: 28,
fontWeight: "bold",
color: "#f1f1f1",
}}
entering={SlideInDown}
exiting={SlideInUp}
>
Swiped all the cards! 🎉
</Animated.Text>
) : (
<SwipeableCard
todos={todos}
swipeDirection={swipeDirection}
setSwipeDirection={setSwipeDirection}
/>
)}
</View>
{todos.length > 0 ? (
<View style={styles.ctaWrapper}>
<AnimatedButton
onPress={() => setSwipeDirection("LEFT")}
_animatedWrapperStyle={[
StyleSheet.absoluteFill,
styles.animatedWrapper,
{
top: -40,
left: -40,
},
]}
style={[
{
alignItems: "flex-start",
},
]}
>
<MaterialCommunityIcons
name="keyboard-backspace"
size={36}
color="#f1f1f1"
/>
<Text style={styles.buttonText}>Save it later</Text>
</AnimatedButton>
<AnimatedButton
onPress={() => setSwipeDirection("RIGHT")}
_animatedWrapperStyle={[
StyleSheet.absoluteFill,
styles.animatedWrapper,
{
top: -40,
left: 5,
},
]}
style={[
{
alignItems: "flex-end",
},
]}
>
<MaterialCommunityIcons
name="keyboard-backspace"
size={36}
style={{
transform: [{ rotateY: "180deg" }],
}}
color="#f1f1f1"
/>
<Text style={styles.buttonText}>Complete</Text>
</AnimatedButton>
</View>
) : null}
</View>
</GestureHandlerRootView>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: "#98B9D4",
flex: 1,
},
buttonText: {
color: "#f1f1f1",
fontSize: 18,
fontWeight: "bold",
},
animatedWrapper: {
backgroundColor: "#fff",
borderRadius: 999,
height: 120,
width: 120,
opacity: 0.3,
},
heading: {
fontSize: 28,
fontWeight: "bold",
color: "#f1f1f1",
textAlign: "center",
marginVertical: 32,
},
ctaWrapper: {
justifyContent: "space-between",
flexDirection: "row",
width: "100%",
paddingHorizontal: 24,
marginTop: 72,
},
});