cdslibrary 1.2.101 → 1.2.102

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,11 +1,12 @@
1
1
  import React, { useEffect } from "react";
2
- import { StyleSheet, Text, TouchableOpacity, } from "react-native";
2
+ import { StyleSheet, Text, TouchableOpacity, } from "react-native";
3
3
  import Animated, {
4
4
  useSharedValue,
5
5
  useAnimatedStyle,
6
6
  withSpring,
7
7
  withTiming,
8
- runOnJS
8
+ runOnJS,
9
+ interpolate
9
10
  } from "react-native-reanimated";
10
11
  import { GestureDetector, Gesture, } from "react-native-gesture-handler";
11
12
  import { useTheme } from "../context/CDSThemeContext";
@@ -13,61 +14,59 @@ import { useTheme } from "../context/CDSThemeContext";
13
14
 
14
15
  export const CDSSnackBar = ({ message, visible, onDismiss, action }) => {
15
16
  const { theme } = useTheme();
16
- const translateY = useSharedValue(100); // Empezamos fuera de pantalla
17
+ const translateY = useSharedValue(150); // Empezamos ocultos abajo
17
18
 
18
- // Sincronizar visibilidad con animación
19
+ // 1. UN SOLO useEffect para controlar la entrada y salida
19
20
  useEffect(() => {
20
- if (visible) {
21
- translateY.value = withSpring(0, { damping: 15 });
22
- } else {
23
- translateY.value = withTiming(150);
24
- }
21
+ translateY.value = withTiming(visible ? 0 : 150, {
22
+ duration: 300
23
+ });
25
24
  }, [visible]);
26
25
 
27
- // Lógica de auto-ocultado
26
+ // 2. Timer de auto-ocultado (solo si es visible)
28
27
  useEffect(() => {
29
- let timer;
30
- if (visible) {
31
- timer = setTimeout(() => {
32
- if (onDismiss) onDismiss();
33
- }, 4000);
34
- }
28
+ if (!visible) return;
29
+
30
+ const timer = setTimeout(() => {
31
+ if (onDismiss) onDismiss();
32
+ }, 4000);
33
+
35
34
  return () => clearTimeout(timer);
36
35
  }, [visible, onDismiss]);
37
36
 
38
- // Configuración del Gesto (Pan Gesture)
39
37
  const gesture = Gesture.Pan()
40
38
  .onUpdate((event) => {
41
- // Solo permitimos arrastrar hacia abajo (valores positivos de Y)
42
- if (event.translationY > 0) {
43
- translateY.value = event.translationY;
44
- }
39
+ if (event.translationY > 0) translateY.value = event.translationY;
45
40
  })
46
41
  .onEnd((event) => {
47
- // Si se arrastró más de 50px o la velocidad es alta, cerramos
48
42
  if (event.translationY > 50 || event.velocityY > 500) {
49
43
  translateY.value = withTiming(150, {}, () => {
50
44
  if (onDismiss) runOnJS(onDismiss)();
51
45
  });
52
46
  } else {
53
- // Si no, regresa a su posición original
54
47
  translateY.value = withSpring(0);
55
48
  }
56
49
  });
57
50
 
58
- const animatedStyle = useAnimatedStyle(() => {
59
- return {
60
- transform: [
61
- { translateY: translateY.value }
62
- ],
63
- };
64
- });
51
+ const animatedStyle = useAnimatedStyle(() => ({
52
+ transform: [{ translateY: translateY.value }],
53
+ // OPCIONAL: Añadimos opacidad para que no se vea el "fantasma" si se queda trabado
54
+ opacity: interpolate(translateY.value, [0, 100], [1, 0]),
55
+ }));
65
56
 
66
- useEffect(() => {
67
- translateY.value = withTiming(visible ? 0 : 150, { duration: 400 });
68
- }, [visible]);
57
+ // IMPORTANTE: Eliminamos el "if (!visible) return null" manual para dejar
58
+ // que Reanimated maneje la salida. Si quieres optimizar, usa un estado local:
59
+ const [shouldRender, setShouldRender] = React.useState(visible);
69
60
 
70
- if (!visible && translateY.value >= 100) return null;
61
+ useEffect(() => {
62
+ if (visible) setShouldRender(true);
63
+ else {
64
+ const timer = setTimeout(() => setShouldRender(false), 400);
65
+ return () => clearTimeout(timer);
66
+ }
67
+ }, [visible]);
68
+
69
+ if (!shouldRender) return null;
71
70
 
72
71
  return (
73
72
  <GestureDetector gesture={gesture}>
@@ -83,18 +82,12 @@ export const CDSSnackBar = ({ message, visible, onDismiss, action }) => {
83
82
  }
84
83
  ]}
85
84
  >
86
- <Text style={[
87
- theme.typography.regular.sm,
88
- { color: theme.text.neutral.contrast, flex: 1 }
89
- ]}>
85
+ <Text style={[theme.typography.regular.sm, { color: theme.text.neutral.contrast, flex: 1 }]}>
90
86
  {message}
91
87
  </Text>
92
-
93
88
  {action && (
94
89
  <TouchableOpacity onPress={onDismiss} style={styles.actionButton}>
95
- <Text style={[theme.typography.label, {
96
- color: theme.text.neutral.contrast,
97
- }]}>
90
+ <Text style={[theme.typography.label, { color: theme.text.neutral.contrast }]}>
98
91
  {action}
99
92
  </Text>
100
93
  </TouchableOpacity>
@@ -113,8 +106,8 @@ const styles = StyleSheet.create({
113
106
  flexDirection: 'row',
114
107
  alignItems: 'center',
115
108
  justifyContent: 'space-between',
116
- bottom: 40,
117
- zIndex: 9999,
109
+ bottom: 40,
110
+ zIndex: 9999,
118
111
  elevation: 10,
119
112
  },
120
113
  actionButton: {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "cdslibrary",
3
3
  "license": "0BSD",
4
- "version": "1.2.101",
4
+ "version": "1.2.102",
5
5
  "main": "index.js",
6
6
  "author": "Nat Viramontes",
7
7
  "description": "A library of components for the CDS project",