react-native-in-app-debugger 1.0.47 → 1.0.49

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/index.jsx CHANGED
@@ -8,7 +8,7 @@ import {
8
8
  Dimensions,
9
9
  } from "react-native";
10
10
  import Text from "./Text";
11
- import X from './X';
11
+ import X from "./X";
12
12
 
13
13
  let DeviceInfo;
14
14
  try {
@@ -19,7 +19,8 @@ try {
19
19
 
20
20
  let LocalStorage;
21
21
  try {
22
- LocalStorage = require("@react-native-async-storage/async-storage/src").default;
22
+ LocalStorage =
23
+ require("@react-native-async-storage/async-storage/src").default;
23
24
  } catch (error) {
24
25
  // console.error("Error importing LocalStorage:", error);
25
26
  }
@@ -28,6 +29,7 @@ import useAnimation from "./useAnimation";
28
29
  import Variables from "./Variables";
29
30
  import Api from "./Api";
30
31
  import useApiInterceptor from "./useApiInterceptor";
32
+ import useStateRef from "./useStateRef";
31
33
 
32
34
  const dimension = Dimensions.get("window");
33
35
 
@@ -60,34 +62,42 @@ export default ({
60
62
  interceptResponse,
61
63
  tabs = [],
62
64
  }) => {
63
- const [blacklists, setB] = useState([]);
65
+ const [blacklists, setB, blacklistRef] = useStateRef([]);
64
66
 
65
- const setBlacklists = d => {
67
+ const setBlacklists = (d) => {
66
68
  if (!d) {
67
69
  setB([]);
68
- LocalStorage?.removeItem('in-app-debugger-blacklist');
70
+ LocalStorage?.removeItem("in-app-debugger-blacklist");
69
71
  } else {
70
- setB(v => {
72
+ setB((v) => {
71
73
  const newValue = Array.isArray(d) ? d : [...v, d];
72
- LocalStorage?.setItem('in-app-debugger-blacklist', JSON.stringify(newValue));
74
+ LocalStorage?.setItem(
75
+ "in-app-debugger-blacklist",
76
+ JSON.stringify(newValue)
77
+ );
73
78
  return newValue;
74
79
  });
75
80
  }
76
- }
81
+ };
77
82
 
78
83
  if (LocalStorage) {
79
84
  useEffect(() => {
80
85
  setTimeout(() => {
81
- LocalStorage.getItem('in-app-debugger-blacklist').then(d => {
86
+ LocalStorage.getItem("in-app-debugger-blacklist").then((d) => {
82
87
  if (d) {
83
88
  setBlacklists(JSON.parse(d));
84
89
  }
85
90
  });
86
91
  }, 4000);
87
- },[]);
92
+ }, []);
88
93
  }
89
94
 
90
- const { apis, ...restApiInterceptor } = useApiInterceptor(maxNumOfApiToStore, blacklists, interceptResponse);
95
+ const { apis, ...restApiInterceptor } = useApiInterceptor(
96
+ maxNumOfApiToStore,
97
+ blacklists,
98
+ interceptResponse,
99
+ blacklistRef
100
+ );
91
101
 
92
102
  const [tab, setTab] = useState("api");
93
103
 
@@ -118,7 +128,7 @@ export default ({
118
128
  shouldShowDetails,
119
129
  } = useAnimation(badgeHeight);
120
130
 
121
- const CustomTabComponent = tabs.find(t => tab === t.title)?.component;
131
+ const CustomTabComponent = tabs.find((t) => tab === t.title)?.component;
122
132
  return (
123
133
  <Animated.View
124
134
  style={{
@@ -163,34 +173,38 @@ export default ({
163
173
  <Label key={l}>{l}</Label>
164
174
  ))}
165
175
  </View>
166
- <View style={{ flexDirection: "row", padding: 5 }}>
176
+ <View style={{ flexDirection: "row", padding: 5, gap: 6 }}>
167
177
  <View style={{ flex: 1, flexDirection: "row" }}>
168
178
  {!!variables &&
169
- ["api", "variables", ...tabs.map(t => t.title)].map((t) => {
170
- const isSelected = t === tab;
171
- return (
172
- <TouchableOpacity
173
- onPress={() => setTab(t)}
174
- activeOpacity={isSelected ? 1 : 0.7}
175
- key={t}
176
- style={{
177
- flex: 1,
178
- borderBottomWidth: +isSelected,
179
- borderColor: "white",
180
- }}
181
- >
182
- <Text
179
+ ["api", "variables", ...tabs.map((t) => t.title)].map(
180
+ (t, i) => {
181
+ const isSelected = t === tab;
182
+ return (
183
+ <TouchableOpacity
184
+ onPress={() => setTab(t)}
185
+ activeOpacity={isSelected ? 1 : 0.7}
186
+ key={t}
183
187
  style={{
184
- color: "white",
185
- opacity: isSelected ? 1 : 0.5,
186
- textAlign: "center",
188
+ flex: 1,
189
+ borderBottomWidth: +isSelected,
190
+ borderColor: "white",
187
191
  }}
188
192
  >
189
- {t.toUpperCase()}
190
- </Text>
191
- </TouchableOpacity>
192
- );
193
- })}
193
+ <Text
194
+ style={{
195
+ color: "white",
196
+ opacity: isSelected ? 1 : 0.5,
197
+ textAlign: "center",
198
+ textTransform: "uppercase",
199
+ }}
200
+ >
201
+ {t}
202
+ {!i && apis.length && <Text> ({apis.length})</Text>}
203
+ </Text>
204
+ </TouchableOpacity>
205
+ );
206
+ }
207
+ )}
194
208
  </View>
195
209
  <X onPress={() => setIsOpen(false)} />
196
210
  </View>
@@ -199,7 +213,7 @@ export default ({
199
213
  )}
200
214
  {tab === "api" && (
201
215
  <Api
202
- {...{apis, setBlacklists, blacklists, maxNumOfApiToStore}}
216
+ {...{ apis, setBlacklists, blacklists, maxNumOfApiToStore }}
203
217
  {...restApiInterceptor}
204
218
  />
205
219
  )}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-in-app-debugger",
3
- "version": "1.0.47",
3
+ "version": "1.0.49",
4
4
  "description": "This library's main usage is to be used by Non-Technical testers during UAT, SIT or any testing phase.",
5
5
  "main": "index.jsx",
6
6
  "scripts": {
@@ -17,7 +17,7 @@ const parse = (data) => {
17
17
  }
18
18
  };
19
19
 
20
- export default (maxNumOfApiToStore, blacklists, interceptResponse) => {
20
+ export default (maxNumOfApiToStore, blacklists, interceptResponse, blacklistRef) => {
21
21
  const [apis, setApis] = useState([]);
22
22
  const [bookmarks, setBookmarks] = useState({});
23
23
 
@@ -35,7 +35,7 @@ export default (maxNumOfApiToStore, blacklists, interceptResponse) => {
35
35
  }, [apis]);
36
36
 
37
37
  const makeRequest = (data) => {
38
- if (blacklists.some((b) => b.url === data.url && b.method === data.method)) return;
38
+ if (blacklistRef.current.some((b) => b.url === data.url && b.method === data.method)) return;
39
39
  const date = new Date();
40
40
  let hour = date.getHours();
41
41
  const minute = (date.getMinutes() + '').padStart(2, '0');
package/useStateRef.js ADDED
@@ -0,0 +1,18 @@
1
+ import { useCallback, useRef, useState, SetStateAction, Dispatch } from "react";
2
+
3
+ const isFunction = (setStateAction) =>
4
+ typeof setStateAction === "function";
5
+
6
+
7
+ export default (initialState) => {
8
+ const [state, setState] = useState(initialState);
9
+ const ref = useRef(state);
10
+
11
+ const dispatch = useCallback((setStateAction) => {
12
+ ref.current = isFunction(setStateAction) ? setStateAction(ref.current) : setStateAction;
13
+
14
+ setState(ref.current);
15
+ }, []);
16
+
17
+ return [state, dispatch, ref];
18
+ };