File tree 4 files changed +34
-20
lines changed
4 files changed +34
-20
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,9 @@ yarn add react-native-devsettings
26
26
Add the following line to your ` App.tsx ` file
27
27
28
28
``` js
29
- import ' react-native-devsettings' ;
29
+ import " react-native-devsettings" ;
30
+ // OR if you are using AsyncStorage
31
+ import " react-native-devsettings/withAsyncStorage" ;
30
32
```
31
33
32
34
Execute ` cmd+d ` or ` cmd+m ` on your simulator/emulator and select ` (*) Debug JS Remotely `
Original file line number Diff line number Diff line change @@ -6,25 +6,13 @@ const main = async () => {
6
6
stop : '(*) Stop Debugging' ,
7
7
debug : '(*) Debug JS Remotely' ,
8
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
9
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
+ } ) ;
28
16
} ;
29
17
30
18
if ( __DEV__ ) {
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " react-native-devsettings" ,
3
- "version" : " 1.0.3 " ,
3
+ "version" : " 1.0.4 " ,
4
4
"main" : " index.ts" ,
5
5
"description" : " A simple library to enable/disable Chrome Debugger from your app" ,
6
6
"author" :
" Gustavo Gard <[email protected] >" ,
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments