ikualo-ui-kit-mobile 2.0.12 → 2.0.14

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 CHANGED
@@ -3,7 +3,7 @@
3
3
  "name": "ikualo-app-2.0",
4
4
  "slug": "ikualo-app-20",
5
5
  "owner": "ikualo",
6
- "version": "2.0.12",
6
+ "version": "2.0.14",
7
7
  "orientation": "portrait",
8
8
  "icon": "./assets/icon.png",
9
9
  "userInterfaceStyle": "automatic",
@@ -28,7 +28,7 @@ const getStylesButtonContained = (theme: ITheme) =>
28
28
 
29
29
  'btn-contained--sm': {
30
30
  padding: 0,
31
- width: 158,
31
+ width: 'auto',
32
32
  },
33
33
  'btn-contained--md': {
34
34
  paddingVertical: 3,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ikualo-ui-kit-mobile",
3
- "version": "2.0.12",
3
+ "version": "2.0.14",
4
4
  "main": "src/index.ts",
5
5
  "scripts": {
6
6
  "start": "expo start",
@@ -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 de cola de diálogos global
9
- interface DialogQueueItem extends IDialogDown {
10
- id: string;
11
- priority: 0 | 1 | 2 | 3 | 4 | 5;
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(): DialogManager {
21
- if (!DialogManager.instance) {
22
- DialogManager.instance = new DialogManager();
14
+ static getInstance(): PriorityManager {
15
+ if (!PriorityManager.instance) {
16
+ PriorityManager.instance = new PriorityManager();
23
17
  }
24
- return DialogManager.instance;
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
- 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
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
- this.notify();
71
- }
72
-
73
- private closeCurrentDialog() {
74
- if (this.currentDialog) {
75
- this.currentDialog.onDismiss();
76
- this.currentDialog = null;
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
- private showNextDialog() {
81
- if (this.dialogs.length > 0) {
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(): DialogQueueItem | null {
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<DialogQueueItem | null>(null);
122
- const [dialogId, setDialogId] = useState<string | null>(null);
123
- const dialogManager = useRef(DialogManager.getInstance());
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 = dialogManager.current.subscribe(() => {
133
- const newCurrentDialog = dialogManager.current.getCurrentDialog();
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
- if (!dialogId) {
165
- // Generar nuevo ID cada vez que se muestra el diálogo
166
- const newDialogId = Math.random().toString(36).substring(2, 11);
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, currentDialog, priority, title]);
97
+ }, [isVisible, dialogId, priority, onDismiss]);
180
98
 
181
99
  // Cleanup al desmontar el componente
182
100
  useEffect(() => {
183
101
  return () => {
184
- if (dialogId) {
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
- if (dialogId) {
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 && dialogId && currentDialog && currentDialog.id === dialogId);
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}>