Skip to content

Commit dbcf048

Browse files
committed
Add 'import "react-native-devsettings/withAsyncStorage";' if you are using AsyncStorage
1 parent 822cb8f commit dbcf048

File tree

4 files changed

+34
-20
lines changed

4 files changed

+34
-20
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ yarn add react-native-devsettings
2626
Add the following line to your `App.tsx` file
2727

2828
```js
29-
import 'react-native-devsettings';
29+
import "react-native-devsettings";
30+
// OR if you are using AsyncStorage
31+
import "react-native-devsettings/withAsyncStorage";
3032
```
3133

3234
Execute `cmd+d` or `cmd+m` on your simulator/emulator and select `(*) Debug JS Remotely`

index.ts

+6-18
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,13 @@ const main = async () => {
66
stop: '(*) Stop Debugging',
77
debug: '(*) Debug JS Remotely',
88
};
9-
const storageKey = '@RNDS/isDebuggingRemotely';
10-
try {
11-
const AsyncStorage = require('@react-native-async-storage/async-storage').default;
12-
const isDebuggingRemotelyString = await AsyncStorage.getItem(storageKey);
13-
let isDebuggingRemotely = isDebuggingRemotelyString === 'true';
14-
DevSettings.addMenuItem(isDebuggingRemotely ? message.stop : message.debug, async () => {
15-
isDebuggingRemotely = !isDebuggingRemotely;
169

17-
await AsyncStorage.setItem(storageKey, JSON.stringify(isDebuggingRemotely));
18-
NativeModules.DevSettings.setIsDebuggingRemotely(isDebuggingRemotely);
19-
});
20-
} catch (error) {
21-
DevSettings.addMenuItem(message.debug, () => {
22-
NativeModules.DevSettings.setIsDebuggingRemotely(true);
23-
});
24-
DevSettings.addMenuItem(message.stop, () => {
25-
NativeModules.DevSettings.setIsDebuggingRemotely(false);
26-
});
27-
}
10+
DevSettings.addMenuItem(message.debug, () => {
11+
NativeModules.DevSettings.setIsDebuggingRemotely(true);
12+
});
13+
DevSettings.addMenuItem(message.stop, () => {
14+
NativeModules.DevSettings.setIsDebuggingRemotely(false);
15+
});
2816
};
2917

3018
if (__DEV__) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-devsettings",
3-
"version": "1.0.3",
3+
"version": "1.0.4",
44
"main": "index.ts",
55
"description": "A simple library to enable/disable Chrome Debugger from your app",
66
"author": "Gustavo Gard <[email protected]>",

withAsyncStorage.ts

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { NativeModules, DevSettings } from 'react-native';
2+
import AsyncStorage from '@react-native-async-storage/async-storage';
3+
4+
// Tested with React Native 0.71
5+
const withAsyncStorage = async () => {
6+
const message = {
7+
stop: '(*) Stop Debugging',
8+
debug: '(*) Debug JS Remotely',
9+
};
10+
const storageKey = '@RNDS/isDebuggingRemotely';
11+
const isDebuggingRemotelyString = await AsyncStorage.getItem(storageKey);
12+
let isDebuggingRemotely = isDebuggingRemotelyString === 'true';
13+
DevSettings.addMenuItem(isDebuggingRemotely ? message.stop : message.debug, async () => {
14+
isDebuggingRemotely = !isDebuggingRemotely;
15+
16+
await AsyncStorage.setItem(storageKey, JSON.stringify(isDebuggingRemotely));
17+
NativeModules.DevSettings.setIsDebuggingRemotely(isDebuggingRemotely);
18+
});
19+
};
20+
21+
if (__DEV__) {
22+
// add a delay to avoid issue with React Native Debugger
23+
setTimeout(withAsyncStorage, 100);
24+
}

0 commit comments

Comments
 (0)