@towsila/expo-ui-library 4.11.4 → 4.11.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,22 +1,18 @@
1
1
  import React, { useEffect, useRef } from "react";
2
- import {
3
- Animated,
4
- Modal,
5
- StyleSheet,
6
- Text,
7
- View,
8
- } from "react-native";
2
+ import { Animated, Modal, StyleSheet, Text, View } from "react-native";
3
+ import { useSafeAreaInsets } from "react-native-safe-area-context";
9
4
  import { useAppTheme } from "../../context/ThemeContext";
10
5
  import { Fonts, textSize } from "../../tokens/typography";
11
- import { useLanguage } from "../..";
6
+ import { useLanguage } from "../../context/LanguageContext"; // ← fixed
12
7
  import Close from "../../assets/icons/warning.svg";
13
8
  import CheckMark from "../../assets/icons/checkmark.svg";
14
9
  import Warning from "../../assets/icons/history.svg";
15
- import Information from "../../assets/icons/information-circle-outline.svg"
10
+ import Information from "../../assets/icons/information-circle-outline.svg";
11
+
16
12
  interface ToastProps {
17
13
  visible: boolean;
18
14
  message: string;
19
- type:"error"|"success"|"warning"|"info"
15
+ type: "error" | "success" | "warning" | "info";
20
16
  duration?: number;
21
17
  onHide?: () => void;
22
18
  }
@@ -29,11 +25,17 @@ export default function Toast({
29
25
  onHide,
30
26
  }: ToastProps) {
31
27
  const { colors } = useAppTheme();
32
- const {isRTL} = useLanguage();
28
+ const { isRTL } = useLanguage();
29
+ const insets = useSafeAreaInsets();
30
+
33
31
  const translateY = useRef(new Animated.Value(-200)).current;
34
32
  const opacity = useRef(new Animated.Value(0)).current;
35
33
 
36
34
  useEffect(() => {
35
+ // Reset every time it becomes visible so re-shows always animate
36
+ translateY.setValue(-200);
37
+ opacity.setValue(0);
38
+
37
39
  if (!visible) return;
38
40
 
39
41
  Animated.parallel([
@@ -67,33 +69,34 @@ export default function Toast({
67
69
  }, duration);
68
70
 
69
71
  return () => clearTimeout(timer);
70
- }, [visible]);
72
+ }, [visible, duration]);
71
73
 
72
74
  const contentColor = colors.text.primary;
73
- const iconColor = colors.background.card
74
- if (!visible) return null;
75
+ const iconColor = colors.background.card;
76
+
75
77
  const toastStyle = {
76
- success: {
77
- background: colors.semantic.success,
78
- text: contentColor,
79
- icon: <CheckMark width={20} height={20} color={iconColor} />,
80
- },
81
- error: {
82
- background: colors.semantic.error,
83
- text:contentColor,
84
- icon: <Close width={20} height={20} color={iconColor}/>,
85
- },
86
- warning: {
87
- background: colors.semantic.warning,
88
- text: contentColor,
89
- icon: <Warning width={20} height={20} color={iconColor}/>,
90
- },
91
- info: {
92
- background: colors.semantic.border,
93
- text: contentColor,
94
- icon: <Information width={20} height={20} color={iconColor}/>,
95
- },
96
- }[type];
78
+ success: {
79
+ background: colors.semantic.success,
80
+ text: contentColor,
81
+ icon: <CheckMark width={20} height={20} color={iconColor} />,
82
+ },
83
+ error: {
84
+ background: colors.semantic.error,
85
+ text: contentColor,
86
+ icon: <Close width={20} height={20} color={iconColor} />,
87
+ },
88
+ warning: {
89
+ background: colors.semantic.warning,
90
+ text: contentColor,
91
+ icon: <Warning width={20} height={20} color={iconColor} />,
92
+ },
93
+ info: {
94
+ background: colors.semantic.border,
95
+ text: contentColor,
96
+ icon: <Information width={20} height={20} color={iconColor} />,
97
+ },
98
+ }[type];
99
+
97
100
  return (
98
101
  <Modal
99
102
  visible={visible}
@@ -101,8 +104,10 @@ export default function Toast({
101
104
  animationType="none"
102
105
  statusBarTranslucent
103
106
  >
104
- <View style={styles.modal}>
107
+ {/* pointerEvents as a PROP, not a style — lets taps pass through */}
108
+ <View style={styles.modal} pointerEvents="box-none">
105
109
  <Animated.View
110
+ pointerEvents="none"
106
111
  style={[
107
112
  styles.container,
108
113
  {
@@ -110,17 +115,15 @@ export default function Toast({
110
115
  opacity,
111
116
  transform: [{ translateY }],
112
117
  flexDirection: isRTL ? "row-reverse" : "row",
118
+ top: insets.top + 12, // safe area, not magic 60
113
119
  },
114
120
  ]}
115
121
  >
116
- {toastStyle.icon}
122
+ {toastStyle.icon}
117
123
  <Text
118
124
  style={[
119
125
  styles.text,
120
- {
121
- color: toastStyle.text,
122
- textAlign: isRTL ? "right" :"left"
123
- },
126
+ { color: toastStyle.text, textAlign: isRTL ? "right" : "left" },
124
127
  ]}
125
128
  >
126
129
  {message}
@@ -134,35 +137,29 @@ export default function Toast({
134
137
  const styles = StyleSheet.create({
135
138
  modal: {
136
139
  flex: 1,
137
- pointerEvents: "box-none",
140
+ // pointerEvents removed — set as a prop on <View pointerEvents="box-none" />
138
141
  },
139
142
 
140
143
  container: {
141
- alignItems: "flex-start",
142
- gap:10,
144
+ alignItems: "center", // was "flex-start" — centers icon with text
145
+ gap: 10,
143
146
  position: "absolute",
144
- top: 60,
145
147
  left: 16,
146
148
  right: 16,
147
-
148
149
  borderRadius: 10,
149
150
  paddingVertical: 14,
150
151
  paddingHorizontal: 18,
151
-
152
152
  elevation: 20,
153
-
154
153
  shadowColor: "#000",
155
154
  shadowOpacity: 0.18,
156
155
  shadowRadius: 10,
157
- shadowOffset: {
158
- width: 0,
159
- height: 4,
160
- },
156
+ shadowOffset: { width: 0, height: 4 },
161
157
  },
162
158
 
163
159
  text: {
164
160
  fontFamily: Fonts.montserrat.semiBold,
165
161
  fontSize: textSize.sm,
162
+ lineHeight: textSize.sm * 1.4, // nicer wrapping on multi-line
166
163
  flex: 1,
167
164
  },
168
165
  });