react-native-inapp-inspector 2.2.2 → 2.2.4

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.
Files changed (159) hide show
  1. package/dist/commonjs/components/AnalyticsDetail.js +5 -1
  2. package/dist/commonjs/components/AnalyticsEventCard.js +2 -1
  3. package/dist/commonjs/components/DiffViewer.js +1 -1
  4. package/dist/commonjs/components/Inspector/BundleTab.js +22 -0
  5. package/dist/commonjs/components/Inspector/DeviceInfoTab.d.ts +3 -0
  6. package/dist/commonjs/components/Inspector/DeviceInfoTab.js +835 -0
  7. package/dist/commonjs/components/Inspector/InspectorHeader.js +12 -14
  8. package/dist/commonjs/components/Inspector/LogDetail.js +6 -3
  9. package/dist/commonjs/components/Inspector/MainScreen.js +7 -3
  10. package/dist/commonjs/components/Inspector/NetworkTab.js +92 -15
  11. package/dist/commonjs/components/Inspector/PerformanceTab.js +38 -12
  12. package/dist/commonjs/components/Inspector/SettingsPanel.js +440 -229
  13. package/dist/commonjs/components/Inspector/StorageTab.d.ts +3 -0
  14. package/dist/commonjs/components/Inspector/StorageTab.js +892 -0
  15. package/dist/commonjs/components/Inspector/TabBar.js +14 -0
  16. package/dist/commonjs/components/Inspector/TelemetryConsentModal.js +11 -2
  17. package/dist/commonjs/components/Inspector/UpdateAvailableModal.js +4 -1
  18. package/dist/commonjs/components/NetworkIcons.d.ts +6 -0
  19. package/dist/commonjs/components/NetworkIcons.js +30 -1
  20. package/dist/commonjs/constants/version.d.ts +1 -1
  21. package/dist/commonjs/constants/version.js +1 -1
  22. package/dist/commonjs/customHooks/bundleAnalyzer.js +44 -22
  23. package/dist/commonjs/customHooks/storageInspector.d.ts +67 -0
  24. package/dist/commonjs/customHooks/storageInspector.js +486 -0
  25. package/dist/commonjs/i18n/locales/en.json +8 -2
  26. package/dist/commonjs/index.d.ts +1 -0
  27. package/dist/commonjs/index.js +16 -1
  28. package/dist/commonjs/storage.d.ts +5 -0
  29. package/dist/commonjs/storage.js +18 -0
  30. package/dist/commonjs/types/enums.d.ts +5 -0
  31. package/dist/commonjs/types/enums.js +5 -0
  32. package/dist/esm/components/AnalyticsDetail.js +6 -2
  33. package/dist/esm/components/AnalyticsEventCard.js +2 -1
  34. package/dist/esm/components/DiffViewer.js +1 -1
  35. package/dist/esm/components/Inspector/BundleTab.js +22 -0
  36. package/dist/esm/components/Inspector/DeviceInfoTab.d.ts +3 -0
  37. package/dist/esm/components/Inspector/DeviceInfoTab.js +796 -0
  38. package/dist/esm/components/Inspector/InspectorHeader.js +13 -15
  39. package/dist/esm/components/Inspector/LogDetail.js +7 -4
  40. package/dist/esm/components/Inspector/MainScreen.js +7 -3
  41. package/dist/esm/components/Inspector/NetworkTab.js +93 -16
  42. package/dist/esm/components/Inspector/PerformanceTab.js +39 -13
  43. package/dist/esm/components/Inspector/SettingsPanel.js +441 -230
  44. package/dist/esm/components/Inspector/StorageTab.d.ts +3 -0
  45. package/dist/esm/components/Inspector/StorageTab.js +853 -0
  46. package/dist/esm/components/Inspector/TabBar.js +15 -1
  47. package/dist/esm/components/Inspector/TelemetryConsentModal.js +11 -2
  48. package/dist/esm/components/Inspector/UpdateAvailableModal.js +4 -1
  49. package/dist/esm/components/NetworkIcons.d.ts +6 -0
  50. package/dist/esm/components/NetworkIcons.js +23 -0
  51. package/dist/esm/constants/version.d.ts +1 -1
  52. package/dist/esm/constants/version.js +1 -1
  53. package/dist/esm/customHooks/bundleAnalyzer.js +44 -22
  54. package/dist/esm/customHooks/storageInspector.d.ts +67 -0
  55. package/dist/esm/customHooks/storageInspector.js +469 -0
  56. package/dist/esm/i18n/locales/en.json +8 -2
  57. package/dist/esm/index.d.ts +1 -0
  58. package/dist/esm/index.js +5 -0
  59. package/dist/esm/storage.d.ts +5 -0
  60. package/dist/esm/storage.js +5 -0
  61. package/dist/esm/types/enums.d.ts +5 -0
  62. package/dist/esm/types/enums.js +5 -0
  63. package/package.json +9 -1
  64. package/src/analytics.ts +35 -0
  65. package/src/bundle.ts +25 -0
  66. package/src/components/AnalyticsDetail.tsx +870 -0
  67. package/src/components/AnalyticsEventCard.tsx +442 -0
  68. package/src/components/AnalyticsGraph.tsx +583 -0
  69. package/src/components/AnimatedEntrance.tsx +64 -0
  70. package/src/components/AppHeaderLogo.tsx +109 -0
  71. package/src/components/BrandCircleIcon.tsx +144 -0
  72. package/src/components/BrandSquareIcon.tsx +144 -0
  73. package/src/components/CodeSnippet.tsx +725 -0
  74. package/src/components/ConsoleLogCard.tsx +628 -0
  75. package/src/components/CopyButton.tsx +87 -0
  76. package/src/components/DiffViewer.tsx +82 -0
  77. package/src/components/DomainHeader.tsx +237 -0
  78. package/src/components/EmptyState.tsx +73 -0
  79. package/src/components/EndOfListFooter.tsx +100 -0
  80. package/src/components/ErrorBoundary.tsx +688 -0
  81. package/src/components/HeadersSection.tsx +192 -0
  82. package/src/components/HighlightText.tsx +100 -0
  83. package/src/components/Inspector/AnalyticsFilterModal.tsx +1250 -0
  84. package/src/components/Inspector/AnalyticsTab.tsx +1336 -0
  85. package/src/components/Inspector/BundleTab.tsx +4760 -0
  86. package/src/components/Inspector/ConsoleTab.tsx +702 -0
  87. package/src/components/Inspector/CrashDetail.tsx +941 -0
  88. package/src/components/Inspector/CrashFilterModal.tsx +721 -0
  89. package/src/components/Inspector/CrashTab.tsx +871 -0
  90. package/src/components/Inspector/DeviceInfoTab.tsx +1204 -0
  91. package/src/components/Inspector/FabLauncher.tsx +80 -0
  92. package/src/components/Inspector/InspectorContext.tsx +28 -0
  93. package/src/components/Inspector/InspectorHeader.tsx +972 -0
  94. package/src/components/Inspector/LogDetail.tsx +1431 -0
  95. package/src/components/Inspector/MainScreen.tsx +262 -0
  96. package/src/components/Inspector/NavigationTracker.tsx +13 -0
  97. package/src/components/Inspector/NetworkDetail.tsx +794 -0
  98. package/src/components/Inspector/NetworkTab.tsx +1183 -0
  99. package/src/components/Inspector/NpmUpdateToast.tsx +392 -0
  100. package/src/components/Inspector/PerformanceTab.tsx +1928 -0
  101. package/src/components/Inspector/ReduxDetail.tsx +1651 -0
  102. package/src/components/Inspector/ReduxTab.tsx +954 -0
  103. package/src/components/Inspector/SettingsPanel.tsx +3447 -0
  104. package/src/components/Inspector/StorageTab.tsx +1048 -0
  105. package/src/components/Inspector/TabBar.tsx +207 -0
  106. package/src/components/Inspector/TelemetryConsentModal.tsx +416 -0
  107. package/src/components/Inspector/UpdateAvailableModal.tsx +557 -0
  108. package/src/components/JsonViewer.tsx +486 -0
  109. package/src/components/LogCard.tsx +491 -0
  110. package/src/components/LogSyntaxHighlighter.tsx +178 -0
  111. package/src/components/MetaAccordion.tsx +340 -0
  112. package/src/components/MiniBarChart.tsx +42 -0
  113. package/src/components/MiniLineChart.tsx +33 -0
  114. package/src/components/NetworkIcons.tsx +2221 -0
  115. package/src/components/SectionHeader.tsx +113 -0
  116. package/src/components/SegmentedTabs.tsx +83 -0
  117. package/src/components/Slider.tsx +300 -0
  118. package/src/components/SourcePageCard.tsx +148 -0
  119. package/src/components/Toast.tsx +131 -0
  120. package/src/components/TouchableScale.tsx +91 -0
  121. package/src/components/TreeNode.tsx +186 -0
  122. package/src/console.ts +24 -0
  123. package/src/constants/index.ts +38 -0
  124. package/src/constants/version.ts +3 -0
  125. package/src/crash.ts +32 -0
  126. package/src/customHooks/analyticsLogger.ts +336 -0
  127. package/src/customHooks/bundleAnalyzer.ts +1256 -0
  128. package/src/customHooks/consoleLogger.ts +497 -0
  129. package/src/customHooks/crashHandler.ts +944 -0
  130. package/src/customHooks/logFilters.ts +32 -0
  131. package/src/customHooks/networkLogger.ts +419 -0
  132. package/src/customHooks/performanceTracker.ts +1014 -0
  133. package/src/customHooks/reduxLogger.ts +406 -0
  134. package/src/customHooks/storageInspector.ts +509 -0
  135. package/src/customHooks/useAccordion.tsx +60 -0
  136. package/src/decorators/index.ts +184 -0
  137. package/src/helpers/gaAnalyticsRegistry.ts +204 -0
  138. package/src/helpers/index.ts +860 -0
  139. package/src/helpers/memoryManager.ts +138 -0
  140. package/src/helpers/searchQueryParser.ts +283 -0
  141. package/src/helpers/settingsStore.ts +171 -0
  142. package/src/helpers/telemetry.ts +505 -0
  143. package/src/helpers/toast.ts +17 -0
  144. package/src/i18n/index.ts +69 -0
  145. package/src/i18n/locales/en.json +1058 -0
  146. package/src/index.tsx +2356 -0
  147. package/src/native/NativeInspector.ts +397 -0
  148. package/src/native/NativeNetworkInspector.ts +24 -0
  149. package/src/network.ts +22 -0
  150. package/src/performance.ts +38 -0
  151. package/src/redux.ts +23 -0
  152. package/src/storage.ts +18 -0
  153. package/src/styles/AppColors.ts +408 -0
  154. package/src/styles/AppFonts.ts +8 -0
  155. package/src/styles/common.ts +209 -0
  156. package/src/styles/index.ts +1570 -0
  157. package/src/types/enums.ts +199 -0
  158. package/src/types/index.ts +34 -0
  159. package/src/types/interfaces.ts +515 -0
@@ -0,0 +1,509 @@
1
+ // Universal In-App Storage Inspector Adapter for AsyncStorage & MMKV
2
+ // Supports automatic module resolution, NativeModules SQLite fallback, custom instances, and full CRUD operations.
3
+
4
+ import {NativeModules} from 'react-native';
5
+
6
+ export interface StorageEntry {
7
+ key: string;
8
+ value: string;
9
+ parsedValue?: any;
10
+ type: 'json' | 'string' | 'number' | 'boolean' | 'null';
11
+ byteSize: number;
12
+ }
13
+
14
+ export type StorageDriver = 'asyncStorage' | 'mmkv';
15
+
16
+ // In-memory registered storage references
17
+ let customAsyncStorage: any = null;
18
+ const customMMKVInstances = new Map<string, any>();
19
+
20
+ // Listeners for storage mutations
21
+ const changeListeners = new Set<() => void>();
22
+
23
+ const notifyChange = () => {
24
+ changeListeners.forEach(listener => {
25
+ try {
26
+ listener();
27
+ } catch {}
28
+ });
29
+ };
30
+
31
+ /**
32
+ * Register an AsyncStorage instance with the inspector (optional override).
33
+ */
34
+ export const connectAsyncStorage = (storageInstance: any) => {
35
+ if (storageInstance) {
36
+ customAsyncStorage = storageInstance;
37
+ notifyChange();
38
+ }
39
+ };
40
+
41
+ /**
42
+ * Register an MMKV instance with the inspector (optional override).
43
+ */
44
+ export const connectMMKV = (mmkvInstance: any, id: string = 'default') => {
45
+ if (mmkvInstance) {
46
+ customMMKVInstances.set(id, mmkvInstance);
47
+ notifyChange();
48
+ }
49
+ };
50
+
51
+ /**
52
+ * Native Bridge Fallback for AsyncStorage:
53
+ * Directly interfaces with NativeModules.RNCAsyncStorage without needing JS package imports.
54
+ */
55
+ const getNativeAsyncStorageBridge = (): any => {
56
+ const nativeModule =
57
+ NativeModules.RNCAsyncStorage ||
58
+ NativeModules.RNC_AsyncSQLiteDBStorage ||
59
+ NativeModules.AsyncSQLiteDBStorage;
60
+
61
+ if (nativeModule) {
62
+ return {
63
+ getAllKeys: (): Promise<string[]> => {
64
+ return new Promise((resolve, reject) => {
65
+ if (typeof nativeModule.getAllKeys !== 'function') {
66
+ resolve([]);
67
+ return;
68
+ }
69
+ nativeModule.getAllKeys((err: any, keys: string[]) => {
70
+ if (err) reject(err);
71
+ else resolve(keys || []);
72
+ });
73
+ });
74
+ },
75
+ multiGet: (keys: string[]): Promise<[string, string | null][]> => {
76
+ return new Promise((resolve, reject) => {
77
+ if (typeof nativeModule.multiGet !== 'function') {
78
+ resolve([]);
79
+ return;
80
+ }
81
+ nativeModule.multiGet(keys, (err: any, result: [string, string | null][]) => {
82
+ if (err) reject(err);
83
+ else resolve(result || []);
84
+ });
85
+ });
86
+ },
87
+ getItem: (key: string): Promise<string | null> => {
88
+ return new Promise((resolve, reject) => {
89
+ if (typeof nativeModule.multiGet !== 'function') {
90
+ resolve(null);
91
+ return;
92
+ }
93
+ nativeModule.multiGet([key], (err: any, result: [string, string | null][]) => {
94
+ if (err) reject(err);
95
+ else resolve(result?.[0]?.[1] ?? null);
96
+ });
97
+ });
98
+ },
99
+ setItem: (key: string, value: string): Promise<void> => {
100
+ return new Promise((resolve, reject) => {
101
+ if (typeof nativeModule.multiSet !== 'function') {
102
+ resolve();
103
+ return;
104
+ }
105
+ nativeModule.multiSet([[key, value]], (err: any) => {
106
+ if (err) reject(err);
107
+ else resolve();
108
+ });
109
+ });
110
+ },
111
+ removeItem: (key: string): Promise<void> => {
112
+ return new Promise((resolve, reject) => {
113
+ if (typeof nativeModule.multiRemove !== 'function') {
114
+ resolve();
115
+ return;
116
+ }
117
+ nativeModule.multiRemove([key], (err: any) => {
118
+ if (err) reject(err);
119
+ else resolve();
120
+ });
121
+ });
122
+ },
123
+ clear: (): Promise<void> => {
124
+ return new Promise((resolve, reject) => {
125
+ if (typeof nativeModule.clear !== 'function') {
126
+ resolve();
127
+ return;
128
+ }
129
+ nativeModule.clear((err: any) => {
130
+ if (err) reject(err);
131
+ else resolve();
132
+ });
133
+ });
134
+ },
135
+ };
136
+ }
137
+ return null;
138
+ };
139
+
140
+ /**
141
+ * Auto-detect AsyncStorage:
142
+ * 1. Explicit connection
143
+ * 2. Global instance
144
+ * 3. Dynamic require '@react-native-async-storage/async-storage'
145
+ * 4. Native Bridge Direct interface
146
+ */
147
+ export const getResolvedAsyncStorage = (): any => {
148
+ if (customAsyncStorage) return customAsyncStorage;
149
+
150
+ // 1. Global instances
151
+ try {
152
+ const maybeReq =
153
+ (globalThis as any)?.__inAppAsyncStorage ||
154
+ (globalThis as any)?.AsyncStorage ||
155
+ (global as any)?.AsyncStorage;
156
+ if (maybeReq && typeof maybeReq.getAllKeys === 'function') {
157
+ return maybeReq;
158
+ }
159
+ } catch {}
160
+
161
+ // 2. Dynamic runtime require
162
+ try {
163
+ const req =
164
+ typeof (globalThis as any)?.require === 'function'
165
+ ? (globalThis as any).require
166
+ : typeof require === 'function'
167
+ ? require
168
+ : null;
169
+
170
+ if (req) {
171
+ try {
172
+ const mod = req('@react-native-async-storage/async-storage');
173
+ const resolved = mod?.default || mod;
174
+ if (resolved && typeof resolved.getAllKeys === 'function') {
175
+ return resolved;
176
+ }
177
+ } catch {}
178
+
179
+ try {
180
+ const legacyMod = req('@react-native-community/async-storage');
181
+ const resolved = legacyMod?.default || legacyMod;
182
+ if (resolved && typeof resolved.getAllKeys === 'function') {
183
+ return resolved;
184
+ }
185
+ } catch {}
186
+ }
187
+ } catch {}
188
+
189
+ // 3. Native Bridge Fallback (Direct SQLite)
190
+ const nativeBridge = getNativeAsyncStorageBridge();
191
+ if (nativeBridge) {
192
+ return nativeBridge;
193
+ }
194
+
195
+ return null;
196
+ };
197
+
198
+ /**
199
+ * Auto-detect MMKV:
200
+ * 1. Explicit connection
201
+ * 2. Dynamic require 'react-native-mmkv' & instantiate default instance
202
+ * 3. Global MMKV / JSI instances
203
+ */
204
+ export const getResolvedMMKV = (id: string = 'default'): any => {
205
+ if (customMMKVInstances.has(id)) {
206
+ return customMMKVInstances.get(id);
207
+ }
208
+
209
+ // 1. Dynamic require
210
+ try {
211
+ const req =
212
+ typeof (globalThis as any)?.require === 'function'
213
+ ? (globalThis as any).require
214
+ : typeof require === 'function'
215
+ ? require
216
+ : null;
217
+
218
+ if (req) {
219
+ const mmkvMod = req('react-native-mmkv');
220
+ const MMKVClass = mmkvMod?.MMKV || mmkvMod?.default?.MMKV;
221
+ if (MMKVClass && typeof MMKVClass === 'function') {
222
+ if (!customMMKVInstances.has('default')) {
223
+ try {
224
+ const defaultInst = new MMKVClass();
225
+ customMMKVInstances.set('default', defaultInst);
226
+ } catch {}
227
+ }
228
+ }
229
+ }
230
+ } catch {}
231
+
232
+ // 2. Global references
233
+ try {
234
+ const globalMMKV =
235
+ (globalThis as any)?.mmkv ||
236
+ (global as any)?.mmkv ||
237
+ (globalThis as any)?.__MMKV__;
238
+ if (globalMMKV && typeof globalMMKV.getAllKeys === 'function') {
239
+ if (!customMMKVInstances.has('default')) {
240
+ customMMKVInstances.set('default', globalMMKV);
241
+ }
242
+ }
243
+ } catch {}
244
+
245
+ if (customMMKVInstances.has(id)) {
246
+ return customMMKVInstances.get(id);
247
+ }
248
+ if (customMMKVInstances.size > 0) {
249
+ return customMMKVInstances.values().next().value;
250
+ }
251
+ return null;
252
+ };
253
+
254
+ export const isAsyncStorageConnected = (): boolean => {
255
+ return Boolean(getResolvedAsyncStorage());
256
+ };
257
+
258
+ export const isMMKVConnected = (): boolean => {
259
+ return Boolean(getResolvedMMKV());
260
+ };
261
+
262
+ export const getRegisteredMMKVInstanceIds = (): string[] => {
263
+ getResolvedMMKV(); // trigger auto-discovery
264
+ return Array.from(customMMKVInstances.keys());
265
+ };
266
+
267
+ /**
268
+ * Calculate approximate byte size of a UTF-8 string
269
+ */
270
+ export const calculateByteSize = (str: string): number => {
271
+ if (!str) return 0;
272
+ return str.length * 2;
273
+ };
274
+
275
+ /**
276
+ * Determine type and format value safely
277
+ */
278
+ export const analyzeStorageValue = (
279
+ rawVal: any,
280
+ ): {
281
+ strVal: string;
282
+ parsedVal?: any;
283
+ type: 'json' | 'string' | 'number' | 'boolean' | 'null';
284
+ byteSize: number;
285
+ } => {
286
+ if (rawVal === null || rawVal === undefined) {
287
+ return {strVal: 'null', type: 'null', byteSize: 4};
288
+ }
289
+
290
+ const strVal = typeof rawVal === 'string' ? rawVal : String(rawVal);
291
+ const byteSize = calculateByteSize(strVal);
292
+
293
+ if (typeof rawVal === 'number') {
294
+ return {strVal, parsedVal: rawVal, type: 'number', byteSize};
295
+ }
296
+
297
+ if (typeof rawVal === 'boolean') {
298
+ return {strVal, parsedVal: rawVal, type: 'boolean', byteSize};
299
+ }
300
+
301
+ const trimmed = strVal.trim();
302
+ if (
303
+ (trimmed.startsWith('{') && trimmed.endsWith('}')) ||
304
+ (trimmed.startsWith('[') && trimmed.endsWith(']'))
305
+ ) {
306
+ try {
307
+ const parsed = JSON.parse(trimmed);
308
+ return {strVal, parsedVal: parsed, type: 'json', byteSize};
309
+ } catch {}
310
+ }
311
+
312
+ if (trimmed === 'true' || trimmed === 'false') {
313
+ return {strVal, parsedVal: trimmed === 'true', type: 'boolean', byteSize};
314
+ }
315
+
316
+ if (!isNaN(Number(trimmed)) && trimmed !== '') {
317
+ return {strVal, parsedVal: Number(trimmed), type: 'number', byteSize};
318
+ }
319
+
320
+ return {strVal, type: 'string', byteSize};
321
+ };
322
+
323
+ /**
324
+ * Fetch all storage entries for given driver
325
+ */
326
+ export const fetchStorageEntries = async (
327
+ driver: StorageDriver,
328
+ instanceId?: string,
329
+ ): Promise<StorageEntry[]> => {
330
+ const entries: StorageEntry[] = [];
331
+
332
+ if (driver === 'asyncStorage') {
333
+ const storage = getResolvedAsyncStorage();
334
+ if (!storage || typeof storage.getAllKeys !== 'function') {
335
+ return [];
336
+ }
337
+
338
+ try {
339
+ const keys: string[] = await storage.getAllKeys();
340
+ if (!keys || keys.length === 0) return [];
341
+
342
+ if (typeof storage.multiGet === 'function') {
343
+ const pairs: [string, string | null][] = await storage.multiGet(keys);
344
+ for (const [k, v] of pairs) {
345
+ const analysis = analyzeStorageValue(v);
346
+ entries.push({
347
+ key: k,
348
+ value: analysis.strVal,
349
+ parsedValue: analysis.parsedVal,
350
+ type: analysis.type,
351
+ byteSize: analysis.byteSize,
352
+ });
353
+ }
354
+ } else {
355
+ for (const k of keys) {
356
+ const v = await storage.getItem(k);
357
+ const analysis = analyzeStorageValue(v);
358
+ entries.push({
359
+ key: k,
360
+ value: analysis.strVal,
361
+ parsedValue: analysis.parsedVal,
362
+ type: analysis.type,
363
+ byteSize: analysis.byteSize,
364
+ });
365
+ }
366
+ }
367
+ } catch (err) {
368
+ console.warn('[StorageInspector] Error reading AsyncStorage keys:', err);
369
+ }
370
+ } else if (driver === 'mmkv') {
371
+ const mmkv = getResolvedMMKV(instanceId);
372
+ if (!mmkv || typeof mmkv.getAllKeys !== 'function') {
373
+ return [];
374
+ }
375
+
376
+ try {
377
+ const keys: string[] = mmkv.getAllKeys();
378
+ for (const k of keys) {
379
+ let rawVal: any = null;
380
+ if (typeof mmkv.getString === 'function') {
381
+ rawVal = mmkv.getString(k);
382
+ }
383
+ if (rawVal === undefined || rawVal === null) {
384
+ if (typeof mmkv.getNumber === 'function') {
385
+ const num = mmkv.getNumber(k);
386
+ if (num !== undefined && !isNaN(num)) rawVal = num;
387
+ }
388
+ }
389
+ if (rawVal === undefined || rawVal === null) {
390
+ if (typeof mmkv.getBoolean === 'function') {
391
+ const bool = mmkv.getBoolean(k);
392
+ if (bool !== undefined) rawVal = bool;
393
+ }
394
+ }
395
+
396
+ const analysis = analyzeStorageValue(rawVal);
397
+ entries.push({
398
+ key: k,
399
+ value: analysis.strVal,
400
+ parsedValue: analysis.parsedVal,
401
+ type: analysis.type,
402
+ byteSize: analysis.byteSize,
403
+ });
404
+ }
405
+ } catch (err) {
406
+ console.warn('[StorageInspector] Error reading MMKV keys:', err);
407
+ }
408
+ }
409
+
410
+ // Sort alphabetically by key
411
+ entries.sort((a, b) => a.key.localeCompare(b.key));
412
+ return entries;
413
+ };
414
+
415
+ /**
416
+ * Create or Update a key-value entry (CRUD: Create / Update)
417
+ */
418
+ export const setStorageEntry = async (
419
+ driver: StorageDriver,
420
+ key: string,
421
+ value: string,
422
+ instanceId?: string,
423
+ ): Promise<boolean> => {
424
+ if (!key.trim()) return false;
425
+
426
+ try {
427
+ if (driver === 'asyncStorage') {
428
+ const storage = getResolvedAsyncStorage();
429
+ if (!storage || typeof storage.setItem !== 'function') return false;
430
+ await storage.setItem(key.trim(), value);
431
+ notifyChange();
432
+ return true;
433
+ } else if (driver === 'mmkv') {
434
+ const mmkv = getResolvedMMKV(instanceId);
435
+ if (!mmkv || typeof mmkv.set !== 'function') return false;
436
+ mmkv.set(key.trim(), value);
437
+ notifyChange();
438
+ return true;
439
+ }
440
+ } catch (err) {
441
+ console.warn('[StorageInspector] Error setting storage item:', err);
442
+ }
443
+ return false;
444
+ };
445
+
446
+ /**
447
+ * Delete a single key (CRUD: Delete)
448
+ */
449
+ export const removeStorageEntry = async (
450
+ driver: StorageDriver,
451
+ key: string,
452
+ instanceId?: string,
453
+ ): Promise<boolean> => {
454
+ try {
455
+ if (driver === 'asyncStorage') {
456
+ const storage = getResolvedAsyncStorage();
457
+ if (!storage || typeof storage.removeItem !== 'function') return false;
458
+ await storage.removeItem(key);
459
+ notifyChange();
460
+ return true;
461
+ } else if (driver === 'mmkv') {
462
+ const mmkv = getResolvedMMKV(instanceId);
463
+ if (!mmkv || typeof mmkv.delete !== 'function') return false;
464
+ mmkv.delete(key);
465
+ notifyChange();
466
+ return true;
467
+ }
468
+ } catch (err) {
469
+ console.warn('[StorageInspector] Error removing storage item:', err);
470
+ }
471
+ return false;
472
+ };
473
+
474
+ /**
475
+ * Wipe all keys for given storage (CRUD: Clear All)
476
+ */
477
+ export const clearStorageDriver = async (
478
+ driver: StorageDriver,
479
+ instanceId?: string,
480
+ ): Promise<boolean> => {
481
+ try {
482
+ if (driver === 'asyncStorage') {
483
+ const storage = getResolvedAsyncStorage();
484
+ if (!storage || typeof storage.clear !== 'function') return false;
485
+ await storage.clear();
486
+ notifyChange();
487
+ return true;
488
+ } else if (driver === 'mmkv') {
489
+ const mmkv = getResolvedMMKV(instanceId);
490
+ if (!mmkv || typeof mmkv.clearAll !== 'function') return false;
491
+ mmkv.clearAll();
492
+ notifyChange();
493
+ return true;
494
+ }
495
+ } catch (err) {
496
+ console.warn('[StorageInspector] Error clearing storage:', err);
497
+ }
498
+ return false;
499
+ };
500
+
501
+ /**
502
+ * Subscribe to storage mutations
503
+ */
504
+ export const subscribeToStorageChanges = (listener: () => void): (() => void) => {
505
+ changeListeners.add(listener);
506
+ return () => {
507
+ changeListeners.delete(listener);
508
+ };
509
+ };
@@ -0,0 +1,60 @@
1
+ import {useCallback, useRef, useState} from 'react';
2
+ import {Animated} from 'react-native';
3
+
4
+ const useAccordion = (
5
+ initialOpen = false,
6
+ maxBodyHeight = 1200,
7
+ duration = 280,
8
+ ) => {
9
+ const [isOpen, setIsOpen] = useState(initialOpen);
10
+ const animVal = useRef(new Animated.Value(initialOpen ? 1 : 0)).current;
11
+
12
+ const toggleOpen = useCallback(() => {
13
+ const next = !isOpen;
14
+ setIsOpen(next);
15
+ Animated.timing(animVal, {
16
+ toValue: next ? 1 : 0,
17
+ duration,
18
+ useNativeDriver: false,
19
+ }).start();
20
+ }, [isOpen, animVal, duration]);
21
+
22
+ const forceOpen = useCallback(
23
+ (open: boolean) => {
24
+ setIsOpen(open);
25
+ Animated.timing(animVal, {
26
+ toValue: open ? 1 : 0,
27
+ duration,
28
+ useNativeDriver: false,
29
+ }).start();
30
+ },
31
+ [animVal, duration],
32
+ );
33
+
34
+ const chevronStyle = {
35
+ transform: [
36
+ {
37
+ rotate: animVal.interpolate({
38
+ inputRange: [0, 1],
39
+ outputRange: ['0deg', '180deg'],
40
+ }),
41
+ },
42
+ ],
43
+ };
44
+
45
+ const bodyStyle = {
46
+ maxHeight: animVal.interpolate({
47
+ inputRange: [0, 1],
48
+ outputRange: [0, maxBodyHeight],
49
+ }),
50
+ overflow: 'hidden' as const,
51
+ opacity: animVal.interpolate({
52
+ inputRange: [0, 0.4, 1],
53
+ outputRange: [0, 0.7, 1],
54
+ }),
55
+ };
56
+
57
+ return {isOpen, toggleOpen, forceOpen, chevronStyle, bodyStyle};
58
+ };
59
+
60
+ export default useAccordion;