Skip to content

Commit 65a8b76

Browse files
committed
Add AsyncStorage support
1 parent 173474c commit 65a8b76

7 files changed

Lines changed: 115 additions & 27 deletions

File tree

.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"editor.rulers": [100],
3+
"prettier.trailingComma": "all",
4+
"prettier.singleQuote": true,
5+
"prettier.semi": true,
6+
"prettier.printWidth": 100
7+
}

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,27 @@
11
# react-native-devsettings
22

33
Enable react-native-debugger and chrome debugger on Hermes
4+
5+
## Installation
6+
7+
```sh
8+
npm install react-native-devsettings
9+
```
10+
11+
or
12+
13+
```sh
14+
yarn add react-native-devsettings
15+
```
16+
17+
## Usage
18+
19+
Add the following line to your `App.tsx` file
20+
21+
```js
22+
import 'react-native-devsettings';
23+
```
24+
25+
Execute `cmd+d` or `cmd+m` on your simulator/emulator and select `(*) Debug JS Remotely`
26+
27+
![Example](example.png)

declaration.d.ts

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1 @@
1-
interface Window {
2-
__DEV__: boolean;
3-
}
4-
5-
declare module "react-native" {
6-
export const NativeModules: NativeModules;
7-
export const DevSettings: DevSettings;
8-
}
9-
10-
interface NativeModules {
11-
DevSettings: {
12-
setIsDebuggingRemotely: (isDebuggingRemotely: boolean) => void;
13-
};
14-
}
15-
16-
interface DevSettings {
17-
addMenuItem: (title: string, handler: () => void) => void;
18-
}
1+
declare var __DEV__: boolean;

example.png

1.13 MB
Loading

index.ts

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
import { NativeModules, DevSettings } from "react-native";
1+
import { NativeModules, DevSettings } from 'react-native';
22

33
// Tested with React Native 0.71
4-
if (window.__DEV__) {
5-
DevSettings.addMenuItem("* Debug with Chrome", () => {
6-
NativeModules.DevSettings.setIsDebuggingRemotely(true);
7-
});
8-
DevSettings.addMenuItem("* Stop Debugging", () => {
9-
NativeModules.DevSettings.setIsDebuggingRemotely(false);
10-
});
4+
const main = async () => {
5+
const message = {
6+
stop: '(*) Stop Debugging',
7+
debug: '(*) Debug JS Remotely',
8+
};
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;
16+
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+
}
28+
};
29+
30+
if (__DEV__) {
31+
// add a delay to avoid issue with React Native Debugger
32+
setTimeout(main, 100);
1133
}

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-devsettings",
3-
"version": "1.0.0",
3+
"version": "1.0.1",
44
"main": "index.ts",
55
"description": "A simple library to enable/disable Chrome Debugger from your app",
66
"repository": "git@github.com:gusgard/react-native-devsettings.git",
@@ -21,6 +21,8 @@
2121
"publish:beta": "npm publish --tag beta"
2222
},
2323
"devDependencies": {
24+
"@react-native-async-storage/async-storage": "^1.18.1",
25+
"@types/react-native": "^0.71.6",
2426
"typescript": "^5.0.4"
2527
}
2628
}

yarn.lock

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,56 @@
22
# yarn lockfile v1
33

44

5+
"@react-native-async-storage/async-storage@^1.18.1":
6+
version "1.18.1"
7+
resolved "https://registry.yarnpkg.com/@react-native-async-storage/async-storage/-/async-storage-1.18.1.tgz#b1aea4f07fb1dba3325b857b770671517ddab221"
8+
integrity sha512-70aFW8fVCKl+oA1AKPFDpE6s4t9pulj2QeLX+MabEmzfT3urd/3cckv45WJvtocdoIH/oXA3Y+YcCRJCcNa8mA==
9+
dependencies:
10+
merge-options "^3.0.4"
11+
12+
"@types/prop-types@*":
13+
version "15.7.5"
14+
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf"
15+
integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==
16+
17+
"@types/react-native@^0.71.6":
18+
version "0.71.6"
19+
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.71.6.tgz#bf0fc6a69bf0c2933c089dfb19fc182b09cb7790"
20+
integrity sha512-eCqEZ+GhW9L9o6yVoPqCCAq8Sbd6liaKlh6WviD0X7O035NEe7VQ+q9KXYL+mhyZrLI5sbX7f3G973gG6fuiyQ==
21+
dependencies:
22+
"@types/react" "*"
23+
24+
"@types/react@*":
25+
version "18.2.2"
26+
resolved "https://registry.yarnpkg.com/@types/react/-/react-18.2.2.tgz#2b6b1831d9c805b3790b6613becb5c8d2f3be479"
27+
integrity sha512-4GZH3GLuqdZbDvOW5Pqqe7jgsDrKwkJfZMZLwFcgoz3CVDSvnMeG/Ihe44IbZ5Mqhh1fyTh5e44z6pNjIzzV8g==
28+
dependencies:
29+
"@types/prop-types" "*"
30+
"@types/scheduler" "*"
31+
csstype "^3.0.2"
32+
33+
"@types/scheduler@*":
34+
version "0.16.3"
35+
resolved "https://registry.yarnpkg.com/@types/scheduler/-/scheduler-0.16.3.tgz#cef09e3ec9af1d63d2a6cc5b383a737e24e6dcf5"
36+
integrity sha512-5cJ8CB4yAx7BH1oMvdU0Jh9lrEXyPkar6F9G/ERswkCuvP4KQZfZkSjcMbAICCpQTN4OuZn8tz0HiKv9TGZgrQ==
37+
38+
csstype@^3.0.2:
39+
version "3.1.2"
40+
resolved "https://registry.yarnpkg.com/csstype/-/csstype-3.1.2.tgz#1d4bf9d572f11c14031f0436e1c10bc1f571f50b"
41+
integrity sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==
42+
43+
is-plain-obj@^2.1.0:
44+
version "2.1.0"
45+
resolved "https://registry.yarnpkg.com/is-plain-obj/-/is-plain-obj-2.1.0.tgz#45e42e37fccf1f40da8e5f76ee21515840c09287"
46+
integrity sha512-YWnfyRwxL/+SsrWYfOpUtz5b3YD+nyfkHvjbcanzk8zgyO4ASD67uVMRt8k5bM4lLMDnXfriRhOpemw+NfT1eA==
47+
48+
merge-options@^3.0.4:
49+
version "3.0.4"
50+
resolved "https://registry.yarnpkg.com/merge-options/-/merge-options-3.0.4.tgz#84709c2aa2a4b24c1981f66c179fe5565cc6dbb7"
51+
integrity sha512-2Sug1+knBjkaMsMgf1ctR1Ujx+Ayku4EdJN4Z+C2+JzoeF7A3OZ9KM2GY0CpQS51NR61LTurMJrRKPhSs3ZRTQ==
52+
dependencies:
53+
is-plain-obj "^2.1.0"
54+
555
typescript@^5.0.4:
656
version "5.0.4"
757
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.0.4.tgz#b217fd20119bd61a94d4011274e0ab369058da3b"

0 commit comments

Comments
 (0)