react-native-inapp-inspector 1.1.3 → 1.1.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.
@@ -58,8 +58,8 @@ const LogCard = React.memo(function LogCard({ item, onPress, timelineMinStart, t
58
58
 
59
59
  <Text style={styles.serialNumber}>#{item.id + 1}</Text>
60
60
 
61
- <View style={[styles.methodBadge, { backgroundColor: `${methodColor}15` }]}>
62
- <Text style={[styles.methodBadgeText, { color: methodColor }]}>
61
+ <View style={[styles.methodBadge, { backgroundColor: methodColor }]}>
62
+ <Text style={[styles.methodBadgeText, { color: '#FFFFFF' }]}>
63
63
  {item.method}
64
64
  </Text>
65
65
  </View>
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "1.1.3";
1
+ export declare const LIB_VERSION = "1.1.4";
@@ -1,3 +1,3 @@
1
1
  // AUTO-GENERATED FILE — do not edit by hand.
2
2
  // Regenerated from package.json on every build by scripts/gen-version.js.
3
- export const LIB_VERSION = '1.1.3';
3
+ export const LIB_VERSION = '1.1.4';
@@ -1,3 +1,8 @@
1
+ export interface InspectorStorage {
2
+ getItem: (key: string) => string | null | Promise<string | null>;
3
+ setItem: (key: string, value: string) => void | Promise<void>;
4
+ }
5
+ export declare function setCustomStorage(storage: InspectorStorage | null): void;
1
6
  export interface PersistedSettings {
2
7
  isDark?: boolean;
3
8
  modalHeightPercent?: number;
@@ -18,7 +23,6 @@ export interface PersistedSettings {
18
23
  showDuplicateLogs?: boolean;
19
24
  }
20
25
  export declare function loadSettings(): Promise<PersistedSettings>;
21
- /** Debounced save so rapid toggling doesn't hammer storage. */
22
26
  export declare function saveSettings(settings: PersistedSettings): void;
23
27
  export declare function clearPersistedSettings(): Promise<void>;
24
28
  export declare const isPersistentStorageAvailable: () => boolean;
@@ -1,27 +1,36 @@
1
1
  // #5 — Persistence layer for the inspector's settings selections.
2
2
  //
3
- // Backed by @react-native-async-storage/async-storage when the host app has it
4
- // installed (most RN apps do), with a transparent in-memory fallback so this
5
- // library never crashes and never forces a new native dependency.
6
- let storage = null;
7
- try {
8
- // Optional dependency — resolved only if the host app already ships it.
9
- const mod = require('@react-native-async-storage/async-storage');
10
- storage = mod?.default ?? mod ?? null;
11
- if (storage && typeof storage.getItem !== 'function')
12
- storage = null;
13
- }
14
- catch {
15
- storage = null;
16
- }
3
+ // Backed by iOS Settings (NSUserDefaults) for iOS, or custom storage if passed (e.g. AsyncStorage/MMKV).
4
+ // Contains an in-memory fallback for Android or Jest test environments.
5
+ import { Platform, Settings } from 'react-native';
17
6
  // In-memory fallback (settings survive for the app session only).
18
7
  const memory = new Map();
8
+ let customStorage = null;
9
+ export function setCustomStorage(storage) {
10
+ customStorage = storage;
11
+ }
19
12
  const SETTINGS_KEY = 'rn-inapp-inspector.settings.v1';
20
13
  export async function loadSettings() {
21
14
  try {
22
- const raw = storage
23
- ? await storage.getItem(SETTINGS_KEY)
24
- : memory.get(SETTINGS_KEY) ?? null;
15
+ if (customStorage) {
16
+ const raw = await customStorage.getItem(SETTINGS_KEY);
17
+ if (!raw)
18
+ return {};
19
+ const parsed = JSON.parse(raw);
20
+ return parsed && typeof parsed === 'object' ? parsed : {};
21
+ }
22
+ if (Platform.OS === 'ios') {
23
+ const raw = Settings.get(SETTINGS_KEY);
24
+ if (!raw)
25
+ return {};
26
+ if (typeof raw === 'string') {
27
+ const parsed = JSON.parse(raw);
28
+ return parsed && typeof parsed === 'object' ? parsed : {};
29
+ }
30
+ return raw && typeof raw === 'object' ? raw : {};
31
+ }
32
+ // Android/fallback: memory
33
+ const raw = memory.get(SETTINGS_KEY);
25
34
  if (!raw)
26
35
  return {};
27
36
  const parsed = JSON.parse(raw);
@@ -31,37 +40,45 @@ export async function loadSettings() {
31
40
  return {};
32
41
  }
33
42
  }
34
- let saveTimer = null;
35
- /** Debounced save so rapid toggling doesn't hammer storage. */
36
43
  export function saveSettings(settings) {
37
- if (saveTimer)
38
- clearTimeout(saveTimer);
39
- saveTimer = setTimeout(async () => {
40
- try {
41
- const raw = JSON.stringify(settings);
42
- if (storage) {
43
- await storage.setItem(SETTINGS_KEY, raw);
44
- }
45
- else {
46
- memory.set(SETTINGS_KEY, raw);
47
- }
44
+ try {
45
+ const raw = JSON.stringify(settings);
46
+ if (customStorage) {
47
+ customStorage.setItem(SETTINGS_KEY, raw);
48
+ return;
48
49
  }
49
- catch {
50
- // Persistence is best-effort — never crash the host app over it.
50
+ if (Platform.OS === 'ios') {
51
+ Settings.set({ [SETTINGS_KEY]: raw });
52
+ return;
51
53
  }
52
- }, 250);
54
+ // Android/fallback: memory
55
+ memory.set(SETTINGS_KEY, raw);
56
+ }
57
+ catch {
58
+ // ignore
59
+ }
53
60
  }
54
61
  export async function clearPersistedSettings() {
55
62
  try {
56
- if (storage) {
57
- await storage.removeItem(SETTINGS_KEY);
63
+ if (customStorage) {
64
+ if (typeof customStorage.removeItem === 'function') {
65
+ await customStorage.removeItem(SETTINGS_KEY);
66
+ }
67
+ else {
68
+ await customStorage.setItem(SETTINGS_KEY, '');
69
+ }
70
+ return;
58
71
  }
59
- else {
60
- memory.delete(SETTINGS_KEY);
72
+ if (Platform.OS === 'ios') {
73
+ Settings.set({ [SETTINGS_KEY]: null });
74
+ return;
61
75
  }
76
+ memory.delete(SETTINGS_KEY);
62
77
  }
63
78
  catch {
64
79
  // ignore
65
80
  }
66
81
  }
67
- export const isPersistentStorageAvailable = () => storage != null;
82
+ export const isPersistentStorageAvailable = () => {
83
+ return customStorage !== null || Platform.OS === 'ios';
84
+ };