ikualo-ui-kit-mobile 2.0.6 → 2.0.8
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.
- package/app.json +1 -1
- package/package.json +1 -1
- package/src/elements/dialogs/DialogDown.tsx +42 -19
package/app.json
CHANGED
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@ import { IDialogDown } from '../../models';
|
|
|
8
8
|
// Sistema de cola de diálogos global
|
|
9
9
|
interface DialogQueueItem extends IDialogDown {
|
|
10
10
|
id: string;
|
|
11
|
-
priority: 0 |1 | 2 | 3 | 4 | 5;
|
|
11
|
+
priority: 0 | 1 | 2 | 3 | 4 | 5;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
class DialogManager {
|
|
@@ -33,18 +33,23 @@ class DialogManager {
|
|
|
33
33
|
this.listeners.forEach((listener) => listener());
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
addDialog(dialog:
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
addDialog(dialog: DialogQueueItem) {
|
|
37
|
+
// Lógica de cierre del diálogo actual:
|
|
38
|
+
// 1. Si el nuevo NO tiene prioridad (0): cierra si el anterior tampoco tiene prioridad
|
|
39
|
+
// 2. Si el nuevo SÍ tiene prioridad (1-5): cierra si el anterior no tiene prioridad O si tiene prioridad menor o igual
|
|
40
|
+
if (this.currentDialog) {
|
|
41
|
+
const shouldCloseCurrent =
|
|
42
|
+
(dialog.priority === 0 && this.currentDialog.priority === 0) || // Ambos sin prioridad: cierra el anterior
|
|
43
|
+
(dialog.priority > 0 && this.currentDialog.priority === 0) || // Nuevo con prioridad, anterior sin: cierra
|
|
44
|
+
(dialog.priority > 0 && dialog.priority >= this.currentDialog.priority); // Ambos con prioridad: si nueva es mayor o igual
|
|
39
45
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.closeCurrentDialog();
|
|
46
|
+
if (shouldCloseCurrent) {
|
|
47
|
+
this.closeCurrentDialog();
|
|
48
|
+
}
|
|
44
49
|
}
|
|
45
50
|
|
|
46
51
|
// Agregar a la cola
|
|
47
|
-
this.dialogs.push(
|
|
52
|
+
this.dialogs.push(dialog);
|
|
48
53
|
|
|
49
54
|
// Si no hay diálogo actual, mostrar el nuevo
|
|
50
55
|
if (!this.currentDialog) {
|
|
@@ -91,12 +96,13 @@ class DialogManager {
|
|
|
91
96
|
}
|
|
92
97
|
}
|
|
93
98
|
|
|
94
|
-
export const DialogDown = (props: IDialogDown) => {
|
|
99
|
+
export const DialogDown = (props: IDialogDown & { priority?: 0 | 1 | 2 | 3 | 4 | 5 }) => {
|
|
95
100
|
const theme = useStore().theme;
|
|
96
101
|
const stylesDialog = getStylesDialog(theme);
|
|
97
|
-
const { isVisible, title, children, onDismiss, image, showCloseButton = true, priority } = props;
|
|
102
|
+
const { isVisible, title, children, onDismiss, image, showCloseButton = true, priority = 0 } = props;
|
|
98
103
|
const slideAnim = useRef(new Animated.Value(0)).current;
|
|
99
104
|
const [currentDialog, setCurrentDialog] = useState<DialogQueueItem | null>(null);
|
|
105
|
+
const [dialogId, setDialogId] = useState<string | null>(null);
|
|
100
106
|
const dialogManager = useRef(DialogManager.getInstance());
|
|
101
107
|
|
|
102
108
|
const handleDismissKeyboard = () => {
|
|
@@ -117,8 +123,12 @@ export const DialogDown = (props: IDialogDown) => {
|
|
|
117
123
|
// Manejar cuando se debe mostrar/ocultar el diálogo
|
|
118
124
|
useEffect(() => {
|
|
119
125
|
if (isVisible) {
|
|
126
|
+
const newDialogId = Math.random().toString(36).substr(2, 9);
|
|
127
|
+
setDialogId(newDialogId);
|
|
128
|
+
|
|
120
129
|
dialogManager.current.addDialog({
|
|
121
130
|
...props,
|
|
131
|
+
id: newDialogId,
|
|
122
132
|
priority: priority || 0, // Si no se especifica prioridad, usar 0 (sin prioridad)
|
|
123
133
|
onDismiss: () => {
|
|
124
134
|
Animated.timing(slideAnim, {
|
|
@@ -126,21 +136,22 @@ export const DialogDown = (props: IDialogDown) => {
|
|
|
126
136
|
duration: 200,
|
|
127
137
|
useNativeDriver: true,
|
|
128
138
|
}).start(() => {
|
|
129
|
-
dialogManager.current.removeDialog(
|
|
139
|
+
dialogManager.current.removeDialog(newDialogId);
|
|
130
140
|
onDismiss();
|
|
131
141
|
});
|
|
132
142
|
},
|
|
133
143
|
});
|
|
134
144
|
} else {
|
|
135
|
-
if (
|
|
136
|
-
dialogManager.current.removeDialog(
|
|
145
|
+
if (dialogId) {
|
|
146
|
+
dialogManager.current.removeDialog(dialogId);
|
|
147
|
+
setDialogId(null);
|
|
137
148
|
}
|
|
138
149
|
}
|
|
139
150
|
}, [isVisible, priority]);
|
|
140
151
|
|
|
141
152
|
// Animación basada en si este diálogo es el actual
|
|
142
153
|
useEffect(() => {
|
|
143
|
-
const isCurrentDialog = currentDialog?.id ===
|
|
154
|
+
const isCurrentDialog = currentDialog?.id === dialogId;
|
|
144
155
|
if (isCurrentDialog) {
|
|
145
156
|
Animated.timing(slideAnim, {
|
|
146
157
|
toValue: 1,
|
|
@@ -150,7 +161,7 @@ export const DialogDown = (props: IDialogDown) => {
|
|
|
150
161
|
} else {
|
|
151
162
|
slideAnim.setValue(0);
|
|
152
163
|
}
|
|
153
|
-
}, [currentDialog, slideAnim,
|
|
164
|
+
}, [currentDialog, slideAnim, dialogId]);
|
|
154
165
|
|
|
155
166
|
useEffect(() => {
|
|
156
167
|
const keyboardDidShowListener = Keyboard.addListener('keyboardDidShow', () => setIsKeyboardVisible(true));
|
|
@@ -165,13 +176,25 @@ export const DialogDown = (props: IDialogDown) => {
|
|
|
165
176
|
}, []);
|
|
166
177
|
|
|
167
178
|
const handleDismiss = () => {
|
|
168
|
-
if (
|
|
169
|
-
dialogManager.current.removeDialog(
|
|
179
|
+
if (dialogId) {
|
|
180
|
+
dialogManager.current.removeDialog(dialogId);
|
|
170
181
|
}
|
|
171
182
|
};
|
|
172
183
|
|
|
173
184
|
// Solo renderizar si este diálogo es el actual
|
|
174
|
-
const isCurrentDialog = Boolean(currentDialog && currentDialog.
|
|
185
|
+
const isCurrentDialog = Boolean(currentDialog && currentDialog.id === dialogId);
|
|
186
|
+
|
|
187
|
+
// Debug logging
|
|
188
|
+
console.log('DialogDown Debug:', {
|
|
189
|
+
title,
|
|
190
|
+
dialogId,
|
|
191
|
+
currentDialogId: currentDialog?.id,
|
|
192
|
+
currentPriority: currentDialog?.priority,
|
|
193
|
+
newPriority: priority,
|
|
194
|
+
isCurrentDialog,
|
|
195
|
+
isVisible,
|
|
196
|
+
shouldShow: isCurrentDialog && isVisible,
|
|
197
|
+
});
|
|
175
198
|
|
|
176
199
|
return (
|
|
177
200
|
<Modal visible={isCurrentDialog} transparent={true} animationType="none" onRequestClose={handleDismiss}>
|