forked from ZyntariHQ/Invoisio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConnectivityToast.tsx
More file actions
66 lines (59 loc) · 1.67 KB
/
Copy pathConnectivityToast.tsx
File metadata and controls
66 lines (59 loc) · 1.67 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { useEffect, useRef } from "react";
import { Animated, Text, StyleSheet, Platform } from "react-native";
import { useConnectivity } from "../hooks/use-connectivity";
export function ConnectivityToast() {
const { isOffline, isDegraded } = useConnectivity();
const translateY = useRef(new Animated.Value(-100)).current;
useEffect(() => {
if (!isOffline && !isDegraded) {
// Online - hide toast
Animated.timing(translateY, {
toValue: -100,
duration: 300,
useNativeDriver: true,
}).start();
} else {
// Offline or degraded - show toast
Animated.spring(translateY, {
toValue: 0,
tension: 50,
friction: 7,
useNativeDriver: true,
}).start();
}
}, [isOffline, isDegraded]);
const getMessage = () => {
if (isOffline) return "📡 You are offline";
if (isDegraded) return "⚠️ Network is unstable";
return "";
};
const backgroundColor = isOffline ? "#DC2626" : "#F59E0B";
if (!isOffline && !isDegraded) return null;
return (
<Animated.View style={[styles.container, { backgroundColor, transform: [{ translateY }] }]}>
<Text style={styles.text}>{getMessage()}</Text>
</Animated.View>
);
}
const styles = StyleSheet.create({
container: {
position: "absolute",
top: Platform.OS === "ios" ? 50 : 30,
left: 16,
right: 16,
padding: 12,
borderRadius: 8,
alignItems: "center",
zIndex: 999,
shadowColor: "#000",
shadowOffset: { width: 0, height: 2 },
shadowOpacity: 0.1,
shadowRadius: 4,
elevation: 3,
},
text: {
color: "#FFFFFF",
fontSize: 14,
fontFamily: "Inter_600SemiBold",
},
});