ikualo-ui-kit-mobile 2.0.12 → 2.0.13
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 +37 -126
package/app.json
CHANGED
package/package.json
CHANGED
|
@@ -5,23 +5,17 @@ import { useEffect, useState, useRef } from 'react';
|
|
|
5
5
|
import useStore from '../../store';
|
|
6
6
|
import { IDialogDown } from '../../models';
|
|
7
7
|
|
|
8
|
-
// Sistema
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
class DialogManager {
|
|
15
|
-
private static instance: DialogManager;
|
|
16
|
-
private dialogs: DialogQueueItem[] = [];
|
|
17
|
-
private currentDialog: DialogQueueItem | null = null;
|
|
8
|
+
// Sistema simple de prioridades global
|
|
9
|
+
class PriorityManager {
|
|
10
|
+
private static instance: PriorityManager;
|
|
11
|
+
private currentDialog: { id: string; priority: number; onDismiss: () => void } | null = null;
|
|
18
12
|
private readonly listeners: Set<() => void> = new Set();
|
|
19
13
|
|
|
20
|
-
static getInstance():
|
|
21
|
-
if (!
|
|
22
|
-
|
|
14
|
+
static getInstance(): PriorityManager {
|
|
15
|
+
if (!PriorityManager.instance) {
|
|
16
|
+
PriorityManager.instance = new PriorityManager();
|
|
23
17
|
}
|
|
24
|
-
return
|
|
18
|
+
return PriorityManager.instance;
|
|
25
19
|
}
|
|
26
20
|
|
|
27
21
|
subscribe(listener: () => void) {
|
|
@@ -33,84 +27,39 @@ class DialogManager {
|
|
|
33
27
|
this.listeners.forEach((listener) => listener());
|
|
34
28
|
}
|
|
35
29
|
|
|
36
|
-
|
|
37
|
-
//
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
|
45
|
-
|
|
46
|
-
if (shouldCloseCurrent) {
|
|
47
|
-
this.closeCurrentDialog();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// Agregar a la cola
|
|
52
|
-
this.dialogs.push(dialog);
|
|
53
|
-
|
|
54
|
-
// Siempre mostrar el siguiente diálogo (por prioridad)
|
|
55
|
-
this.showNextDialog();
|
|
56
|
-
|
|
57
|
-
this.notify();
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
removeDialog(id: string) {
|
|
61
|
-
// Remover de la cola
|
|
62
|
-
this.dialogs = this.dialogs.filter((dialog) => dialog.id !== id);
|
|
63
|
-
|
|
64
|
-
// Si el diálogo que se está removiendo es el actual, limpiar y mostrar el siguiente
|
|
65
|
-
if (this.currentDialog?.id === id) {
|
|
66
|
-
this.currentDialog = null;
|
|
67
|
-
this.showNextDialog();
|
|
30
|
+
showDialog(id: string, priority: number, onDismiss: () => void) {
|
|
31
|
+
// Si hay un diálogo actual y el nuevo tiene mayor prioridad, cerrar el actual
|
|
32
|
+
if (this.currentDialog && priority > this.currentDialog.priority) {
|
|
33
|
+
this.currentDialog.onDismiss();
|
|
34
|
+
this.currentDialog = null; // Eliminar completamente de memoria
|
|
68
35
|
}
|
|
69
36
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
37
|
+
// Si no hay diálogo actual o el nuevo tiene mayor prioridad, mostrarlo
|
|
38
|
+
if (!this.currentDialog || priority > this.currentDialog.priority) {
|
|
39
|
+
this.currentDialog = { id, priority, onDismiss };
|
|
40
|
+
this.notify();
|
|
41
|
+
} else {
|
|
42
|
+
// Si el diálogo no puede mostrarse por prioridad menor, eliminarlo completamente
|
|
43
|
+
// No mantener referencia alguna al diálogo rechazado
|
|
77
44
|
}
|
|
78
45
|
}
|
|
79
46
|
|
|
80
|
-
|
|
81
|
-
if (this.
|
|
82
|
-
// Ordenar por prioridad (mayor prioridad primero)
|
|
83
|
-
this.dialogs.sort((a, b) => b.priority - a.priority);
|
|
84
|
-
this.currentDialog = this.dialogs[0];
|
|
85
|
-
} else {
|
|
47
|
+
hideDialog(id: string) {
|
|
48
|
+
if (this.currentDialog?.id === id) {
|
|
86
49
|
this.currentDialog = null;
|
|
50
|
+
this.notify();
|
|
87
51
|
}
|
|
88
52
|
}
|
|
89
53
|
|
|
90
|
-
getCurrentDialog()
|
|
54
|
+
getCurrentDialog() {
|
|
91
55
|
return this.currentDialog;
|
|
92
56
|
}
|
|
93
57
|
|
|
58
|
+
// Método para limpiar completamente la memoria
|
|
94
59
|
clear() {
|
|
95
|
-
console.log('DialogManager: Clearing all dialogs');
|
|
96
|
-
this.dialogs = [];
|
|
97
60
|
this.currentDialog = null;
|
|
98
61
|
this.notify();
|
|
99
62
|
}
|
|
100
|
-
|
|
101
|
-
// Método para forzar la limpieza de un diálogo específico
|
|
102
|
-
forceRemoveDialog(id: string) {
|
|
103
|
-
console.log('DialogManager: Force removing dialog', { id });
|
|
104
|
-
this.dialogs = this.dialogs.filter((dialog) => dialog.id !== id);
|
|
105
|
-
|
|
106
|
-
if (this.currentDialog?.id === id) {
|
|
107
|
-
this.currentDialog = null;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
// Mostrar el siguiente diálogo si hay alguno
|
|
111
|
-
this.showNextDialog();
|
|
112
|
-
this.notify();
|
|
113
|
-
}
|
|
114
63
|
}
|
|
115
64
|
|
|
116
65
|
export const DialogDown = (props: IDialogDown & { priority?: 0 | 1 | 2 | 3 | 4 | 5 }) => {
|
|
@@ -118,9 +67,9 @@ export const DialogDown = (props: IDialogDown & { priority?: 0 | 1 | 2 | 3 | 4 |
|
|
|
118
67
|
const stylesDialog = getStylesDialog(theme);
|
|
119
68
|
const { isVisible, title, children, onDismiss, image, showCloseButton = true, priority = 0 } = props;
|
|
120
69
|
const slideAnim = useRef(new Animated.Value(0)).current;
|
|
121
|
-
const [currentDialog, setCurrentDialog] = useState<
|
|
122
|
-
const [dialogId
|
|
123
|
-
const
|
|
70
|
+
const [currentDialog, setCurrentDialog] = useState<{ id: string; priority: number } | null>(null);
|
|
71
|
+
const [dialogId] = useState(() => Math.random().toString(36).substring(2, 11));
|
|
72
|
+
const priorityManager = useRef(PriorityManager.getInstance());
|
|
124
73
|
|
|
125
74
|
const handleDismissKeyboard = () => {
|
|
126
75
|
Keyboard.dismiss();
|
|
@@ -129,8 +78,8 @@ export const DialogDown = (props: IDialogDown & { priority?: 0 | 1 | 2 | 3 | 4 |
|
|
|
129
78
|
|
|
130
79
|
// Suscribirse a cambios en el diálogo actual
|
|
131
80
|
useEffect(() => {
|
|
132
|
-
const unsubscribe =
|
|
133
|
-
const newCurrentDialog =
|
|
81
|
+
const unsubscribe = priorityManager.current.subscribe(() => {
|
|
82
|
+
const newCurrentDialog = priorityManager.current.getCurrentDialog();
|
|
134
83
|
setCurrentDialog(newCurrentDialog);
|
|
135
84
|
});
|
|
136
85
|
return () => {
|
|
@@ -138,52 +87,19 @@ export const DialogDown = (props: IDialogDown & { priority?: 0 | 1 | 2 | 3 | 4 |
|
|
|
138
87
|
};
|
|
139
88
|
}, []);
|
|
140
89
|
|
|
141
|
-
// Función helper para agregar diálogo al manager
|
|
142
|
-
const addDialogToManager = (dialogId: string) => {
|
|
143
|
-
dialogManager.current.addDialog({
|
|
144
|
-
...props,
|
|
145
|
-
id: dialogId,
|
|
146
|
-
priority: priority || 0,
|
|
147
|
-
onDismiss: () => {
|
|
148
|
-
Animated.timing(slideAnim, {
|
|
149
|
-
toValue: 0,
|
|
150
|
-
duration: 200,
|
|
151
|
-
useNativeDriver: true,
|
|
152
|
-
}).start(() => {
|
|
153
|
-
dialogManager.current.removeDialog(dialogId);
|
|
154
|
-
setDialogId(null);
|
|
155
|
-
onDismiss();
|
|
156
|
-
});
|
|
157
|
-
},
|
|
158
|
-
});
|
|
159
|
-
};
|
|
160
|
-
|
|
161
90
|
// Manejar cuando se debe mostrar/ocultar el diálogo
|
|
162
91
|
useEffect(() => {
|
|
163
92
|
if (isVisible) {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
setDialogId(newDialogId);
|
|
168
|
-
} else if (dialogId && !currentDialog) {
|
|
169
|
-
// Si ya tiene ID pero no está en el manager, agregarlo
|
|
170
|
-
addDialogToManager(dialogId);
|
|
171
|
-
} else if (dialogId && currentDialog && currentDialog.id !== dialogId) {
|
|
172
|
-
// Si ya tiene ID pero hay otro diálogo actual, agregarlo (el manager manejará prioridades)
|
|
173
|
-
addDialogToManager(dialogId);
|
|
174
|
-
}
|
|
175
|
-
} else if (dialogId) {
|
|
176
|
-
dialogManager.current.removeDialog(dialogId);
|
|
177
|
-
setDialogId(null);
|
|
93
|
+
priorityManager.current.showDialog(dialogId, priority, onDismiss);
|
|
94
|
+
} else {
|
|
95
|
+
priorityManager.current.hideDialog(dialogId);
|
|
178
96
|
}
|
|
179
|
-
}, [isVisible, dialogId,
|
|
97
|
+
}, [isVisible, dialogId, priority, onDismiss]);
|
|
180
98
|
|
|
181
99
|
// Cleanup al desmontar el componente
|
|
182
100
|
useEffect(() => {
|
|
183
101
|
return () => {
|
|
184
|
-
|
|
185
|
-
dialogManager.current.removeDialog(dialogId);
|
|
186
|
-
}
|
|
102
|
+
priorityManager.current.hideDialog(dialogId);
|
|
187
103
|
};
|
|
188
104
|
}, [dialogId]);
|
|
189
105
|
|
|
@@ -214,17 +130,12 @@ export const DialogDown = (props: IDialogDown & { priority?: 0 | 1 | 2 | 3 | 4 |
|
|
|
214
130
|
}, []);
|
|
215
131
|
|
|
216
132
|
const handleDismiss = () => {
|
|
217
|
-
|
|
218
|
-
dialogManager.current.removeDialog(dialogId);
|
|
219
|
-
// Limpiar el dialogId inmediatamente después de remover
|
|
220
|
-
setDialogId(null);
|
|
221
|
-
}
|
|
222
|
-
// Llamar onDismiss para que el componente padre cambie isVisible a false
|
|
133
|
+
priorityManager.current.hideDialog(dialogId);
|
|
223
134
|
onDismiss();
|
|
224
135
|
};
|
|
225
136
|
|
|
226
137
|
// Solo renderizar si este diálogo es el actual
|
|
227
|
-
const isCurrentDialog = Boolean(isVisible &&
|
|
138
|
+
const isCurrentDialog = Boolean(isVisible && currentDialog && currentDialog.id === dialogId);
|
|
228
139
|
|
|
229
140
|
return (
|
|
230
141
|
<Modal visible={isCurrentDialog} transparent={true} animationType="none" onRequestClose={handleDismiss}>
|