-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCustomToast.js
More file actions
52 lines (46 loc) · 1.15 KB
/
Copy pathCustomToast.js
File metadata and controls
52 lines (46 loc) · 1.15 KB
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
import React, { useEffect, useRef } from 'react';
import { StyleSheet, Text, View, Animated, Easing } from 'react-native';
const CustomToast = ({ message, visible, onHide }) => {
const opacity = useRef(new Animated.Value(0)).current;
useEffect(() => {
if (visible) {
Animated.timing(opacity, {
toValue: 1,
duration: 300,
easing: Easing.ease,
useNativeDriver: true,
}).start();
} else {
Animated.timing(opacity, {
toValue: 0,
duration: 300,
easing: Easing.ease,
useNativeDriver: true,
}).start(onHide);
}
}, [visible, opacity, onHide]);
if (!visible) return null;
return (
<Animated.View style={[styles.toast, { opacity }]}>
<Text style={styles.toastText}>{message}</Text>
</Animated.View>
);
};
const styles = StyleSheet.create({
toast: {
position: 'absolute',
bottom: 50,
left: '50%',
transform: [{ translateX: -150 }],
backgroundColor: '#b38a58',
padding: 10,
borderRadius: 5,
width: 300,
alignItems: 'center',
},
toastText: {
color: '#fff',
fontWeight: 'bold',
},
});
export default CustomToast;