react-native-inapp-inspector 1.1.3 → 1.1.5

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/README.md CHANGED
@@ -16,6 +16,10 @@
16
16
 
17
17
  A self-contained in-app debugging overlay for React Native. Inspect network traffic, console output, analytics events, Redux state, and WebView activity directly inside your app.
18
18
 
19
+ <p align="center">
20
+ <img src="https://raw.githubusercontent.com/vengatmacuser/react-native-inapp-inspector/main/assets/walkthrough.gif" alt="React Native In-App Inspector Walkthrough" width="360" style="border-radius: 20px;" />
21
+ </p>
22
+
19
23
  ---
20
24
 
21
25
  ## Features
@@ -105,6 +109,22 @@ You can disable the overlay without removing it from your tree:
105
109
 
106
110
  ---
107
111
 
112
+ ## Settings Persistence
113
+
114
+ By default, the inspector preserves configuration preferences (such as dark mode, default landing tab, and module visibilities):
115
+ - **iOS:** Settings are persisted automatically using React Native's built-in `Settings` module (`NSUserDefaults`) with zero configuration or additional packages required.
116
+ - **Android / Custom:** To persist settings on Android (or to use a custom storage mechanism on both platforms), pass a storage instance such as `@react-native-async-storage/async-storage` or `react-native-mmkv` to the `storage` prop:
117
+
118
+ ```tsx
119
+ import AsyncStorage from '@react-native-async-storage/async-storage';
120
+
121
+ <NetworkInspector storage={AsyncStorage} />
122
+ ```
123
+
124
+ If no `storage` prop is passed, Android will fall back to an in-memory store (settings reset when the app is restarted).
125
+
126
+ ---
127
+
108
128
  ## Network Logging
109
129
 
110
130
  `setupNetworkLogger()` patches global `fetch`, the default axios instance, and future axios instances created with `axios.create()`.
Binary file
@@ -96,8 +96,8 @@ const LogCard = react_1.default.memo(function LogCard({ item, onPress, timelineM
96
96
 
97
97
  <react_native_1.Text style={styles_1.default.serialNumber}>#{item.id + 1}</react_native_1.Text>
98
98
 
99
- <react_native_1.View style={[styles_1.default.methodBadge, { backgroundColor: `${methodColor}15` }]}>
100
- <react_native_1.Text style={[styles_1.default.methodBadgeText, { color: methodColor }]}>
99
+ <react_native_1.View style={[styles_1.default.methodBadge, { backgroundColor: methodColor }]}>
100
+ <react_native_1.Text style={[styles_1.default.methodBadgeText, { color: '#FFFFFF' }]}>
101
101
  {item.method}
102
102
  </react_native_1.Text>
103
103
  </react_native_1.View>
@@ -1 +1 @@
1
- export declare const LIB_VERSION = "1.1.3";
1
+ export declare const LIB_VERSION = "1.1.5";
@@ -3,4 +3,4 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.LIB_VERSION = void 0;
4
4
  // AUTO-GENERATED FILE — do not edit by hand.
5
5
  // Regenerated from package.json on every build by scripts/gen-version.js.
6
- exports.LIB_VERSION = '1.1.3';
6
+ exports.LIB_VERSION = '1.1.5';
@@ -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,33 +1,43 @@
1
1
  "use strict";
2
2
  // #5 — Persistence layer for the inspector's settings selections.
3
3
  //
4
- // Backed by @react-native-async-storage/async-storage when the host app has it
5
- // installed (most RN apps do), with a transparent in-memory fallback so this
6
- // library never crashes and never forces a new native dependency.
4
+ // Backed by iOS Settings (NSUserDefaults) for iOS, or custom storage if passed (e.g. AsyncStorage/MMKV).
5
+ // Contains an in-memory fallback for Android or Jest test environments.
7
6
  Object.defineProperty(exports, "__esModule", { value: true });
8
7
  exports.isPersistentStorageAvailable = void 0;
8
+ exports.setCustomStorage = setCustomStorage;
9
9
  exports.loadSettings = loadSettings;
10
10
  exports.saveSettings = saveSettings;
11
11
  exports.clearPersistedSettings = clearPersistedSettings;
12
- let storage = null;
13
- try {
14
- // Optional dependency — resolved only if the host app already ships it.
15
- const mod = require('@react-native-async-storage/async-storage');
16
- storage = mod?.default ?? mod ?? null;
17
- if (storage && typeof storage.getItem !== 'function')
18
- storage = null;
19
- }
20
- catch {
21
- storage = null;
22
- }
12
+ const react_native_1 = require("react-native");
23
13
  // In-memory fallback (settings survive for the app session only).
24
14
  const memory = new Map();
15
+ let customStorage = null;
16
+ function setCustomStorage(storage) {
17
+ customStorage = storage;
18
+ }
25
19
  const SETTINGS_KEY = 'rn-inapp-inspector.settings.v1';
26
20
  async function loadSettings() {
27
21
  try {
28
- const raw = storage
29
- ? await storage.getItem(SETTINGS_KEY)
30
- : memory.get(SETTINGS_KEY) ?? null;
22
+ if (customStorage) {
23
+ const raw = await customStorage.getItem(SETTINGS_KEY);
24
+ if (!raw)
25
+ return {};
26
+ const parsed = JSON.parse(raw);
27
+ return parsed && typeof parsed === 'object' ? parsed : {};
28
+ }
29
+ if (react_native_1.Platform.OS === 'ios') {
30
+ const raw = react_native_1.Settings.get(SETTINGS_KEY);
31
+ if (!raw)
32
+ return {};
33
+ if (typeof raw === 'string') {
34
+ const parsed = JSON.parse(raw);
35
+ return parsed && typeof parsed === 'object' ? parsed : {};
36
+ }
37
+ return raw && typeof raw === 'object' ? raw : {};
38
+ }
39
+ // Android/fallback: memory
40
+ const raw = memory.get(SETTINGS_KEY);
31
41
  if (!raw)
32
42
  return {};
33
43
  const parsed = JSON.parse(raw);
@@ -37,38 +47,46 @@ async function loadSettings() {
37
47
  return {};
38
48
  }
39
49
  }
40
- let saveTimer = null;
41
- /** Debounced save so rapid toggling doesn't hammer storage. */
42
50
  function saveSettings(settings) {
43
- if (saveTimer)
44
- clearTimeout(saveTimer);
45
- saveTimer = setTimeout(async () => {
46
- try {
47
- const raw = JSON.stringify(settings);
48
- if (storage) {
49
- await storage.setItem(SETTINGS_KEY, raw);
50
- }
51
- else {
52
- memory.set(SETTINGS_KEY, raw);
53
- }
51
+ try {
52
+ const raw = JSON.stringify(settings);
53
+ if (customStorage) {
54
+ customStorage.setItem(SETTINGS_KEY, raw);
55
+ return;
54
56
  }
55
- catch {
56
- // Persistence is best-effort — never crash the host app over it.
57
+ if (react_native_1.Platform.OS === 'ios') {
58
+ react_native_1.Settings.set({ [SETTINGS_KEY]: raw });
59
+ return;
57
60
  }
58
- }, 250);
61
+ // Android/fallback: memory
62
+ memory.set(SETTINGS_KEY, raw);
63
+ }
64
+ catch {
65
+ // ignore
66
+ }
59
67
  }
60
68
  async function clearPersistedSettings() {
61
69
  try {
62
- if (storage) {
63
- await storage.removeItem(SETTINGS_KEY);
70
+ if (customStorage) {
71
+ if (typeof customStorage.removeItem === 'function') {
72
+ await customStorage.removeItem(SETTINGS_KEY);
73
+ }
74
+ else {
75
+ await customStorage.setItem(SETTINGS_KEY, '');
76
+ }
77
+ return;
64
78
  }
65
- else {
66
- memory.delete(SETTINGS_KEY);
79
+ if (react_native_1.Platform.OS === 'ios') {
80
+ react_native_1.Settings.set({ [SETTINGS_KEY]: null });
81
+ return;
67
82
  }
83
+ memory.delete(SETTINGS_KEY);
68
84
  }
69
85
  catch {
70
86
  // ignore
71
87
  }
72
88
  }
73
- const isPersistentStorageAvailable = () => storage != null;
89
+ const isPersistentStorageAvailable = () => {
90
+ return customStorage !== null || react_native_1.Platform.OS === 'ios';
91
+ };
74
92
  exports.isPersistentStorageAvailable = isPersistentStorageAvailable;