-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.tsx
164 lines (155 loc) · 4.01 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
156
157
158
159
160
161
162
163
164
import React, { useRef, useState } from "react";
import {
StyleSheet,
Text,
View,
Animated,
TouchableOpacity,
Dimensions,
SafeAreaView,
} from "react-native";
import { AntDesign } from "@expo/vector-icons";
import { StatusBar } from "expo-status-bar";
export default function App() {
const windowHeight = Dimensions.get("window").height;
const [status, setStatus] = useState("");
const popAnim = useRef(new Animated.Value(windowHeight * -1)).current;
const successColor = "#6dcf81";
const successHeader = "Sucesso!";
const successMessage = "Tarefa concluida com sucesso!";
const failColor = "#bf6060";
const failHeader = "Algo deu errado!";
const failMessage = "Erro cod: 404";
const popIn = () => {
Animated.timing(popAnim, {
toValue: windowHeight * 0.35 * -1,
duration: 300,
useNativeDriver: true,
}).start(popOut());
};
const popOut: any = () => {
setTimeout(() => {
Animated.timing(popAnim, {
toValue: windowHeight * -1,
duration: 300,
useNativeDriver: true,
}).start();
}, 3000);
};
const instantPopOut = () => {
Animated.timing(popAnim, {
toValue: windowHeight * -1,
duration: 150,
useNativeDriver: true,
}).start();
};
return (
<SafeAreaView
style={{
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
}}
>
<View>
<Animated.View
style={[
styles.toastContainer,
{
transform: [{ translateY: popAnim }],
},
]}
>
<TouchableOpacity onPress={instantPopOut}>
<View style={styles.toastRow}>
<AntDesign
name={status === "success" ? "checkcircleo" : "closecircleo"}
size={24}
color={status === "success" ? successColor : failColor}
/>
<View style={styles.toastText}>
<Text style={{ fontWeight: "bold", fontSize: 15 }}>
{status === "success" ? successHeader : failHeader}
</Text>
<Text style={{ fontSize: 12 }}>
{status === "success" ? successMessage : failMessage}
</Text>
</View>
</View>
</TouchableOpacity>
</Animated.View>
<View
style={{
flexDirection: "row",
justifyContent: "space-around",
}}
>
<TouchableOpacity
onPress={() => {
setStatus("success");
popIn();
}}
style={{
marginTop: 30,
borderWidth: 1,
borderColor: "green",
padding: 10,
alignItems: "center",
justifyContent: "center",
borderRadius: 4,
}}
>
<Text>Sucess Toast</Text>
</TouchableOpacity>
<TouchableOpacity
onPress={() => {
setStatus("fail");
popIn();
}}
style={{
marginTop: 30,
borderWidth: 1,
borderColor: "red",
padding: 10,
alignItems: "center",
justifyContent: "center",
borderRadius: 4,
}}
>
<Text>Error Toast</Text>
</TouchableOpacity>
</View>
</View>
<StatusBar hidden />
</SafeAreaView>
);
}
const styles = StyleSheet.create({
toastContainer: {
height: 60,
width: 350,
backgroundColor: "#f5f5f5",
justifyContent: "center",
alignItems: "center",
borderRadius: 10,
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
toastRow: {
width: "90%",
flexDirection: "row",
alignItems: "center",
justifyContent: "space-evenly",
},
toastText: {
width: "70%",
padding: 2,
},
});