react-native-debug-toolkit 0.4.2 → 0.5.0

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
@@ -30,27 +30,27 @@ cd ios && pod install
30
30
 
31
31
  ## Basic Usage
32
32
 
33
+ ### Method 1: Quick Setup with Default Features
34
+
35
+ The easiest way to add the debug toolkit to your app is using the `initializeDebugToolkit` function with default features:
36
+
33
37
  ```javascript
34
- // In your App.js
35
- import DebugToolKit from 'react-native-debug-toolkit';
38
+ // In your App.js or other initialization file
39
+ import React, { useEffect } from 'react';
40
+ import { initializeDebugToolkit } from 'react-native-debug-toolkit';
36
41
 
37
42
  function App() {
38
43
  useEffect(() => {
39
44
  if (__DEV__) {
40
- const debugToolKit = new DebugToolKit();
41
- debugToolKit.addFeature({
42
- name: 'network',
43
- label: 'Network Logs',
44
- setup: () => console.log('Feature ready'),
45
- getData: () => ({ message: 'Hello debugging world!' })
46
- });
47
- debugToolKit.showDebugPanel();
45
+ // Initialize with all default features
46
+ initializeDebugToolkit();
47
+
48
+ // Or select specific built-in features
49
+ // initializeDebugToolkit(['network', 'console', 'performance']);
48
50
  }
49
51
 
50
52
  return () => {
51
- if (__DEV__) {
52
- DebugToolKit.instance.destroy();
53
- }
53
+ // Cleanup happens automatically
54
54
  };
55
55
  }, []);
56
56
 
@@ -58,12 +58,151 @@ function App() {
58
58
  }
59
59
  ```
60
60
 
61
- ## Features
61
+ ### Method 2: Manual Setup
62
62
 
63
- - Lightweight floating debug panel
64
- - Customizable debugging features
65
- - Development-only functionality (automatically disabled in production)
66
- - Easy to extend with your own debug tools
63
+ For more control, you can manually set up the toolkit:
64
+
65
+ ```javascript
66
+ // In your App.js
67
+ import React, { useEffect } from 'react';
68
+ import DebugToolKit, {
69
+ createNetworkFeature,
70
+ createConsoleLogFeature
71
+ } from 'react-native-debug-toolkit';
72
+
73
+ function App() {
74
+ useEffect(() => {
75
+ if (__DEV__) {
76
+ // Create toolkit instance
77
+ const debugToolKit = new DebugToolKit();
78
+
79
+ // Add features you want
80
+ debugToolKit.addFeature(createNetworkFeature());
81
+ debugToolKit.addFeature(createConsoleLogFeature());
82
+
83
+ // Show floating panel
84
+ debugToolKit.showDebugPanel();
85
+
86
+ return () => {
87
+ // Clean up
88
+ debugToolKit.destroy();
89
+ };
90
+ }
91
+ }, []);
92
+
93
+ return <YourApp />;
94
+ }
95
+ ```
96
+
97
+ ## Available Features
98
+
99
+ The toolkit comes with several built-in debugging features:
100
+
101
+ - **Network**: Track and inspect network requests and responses
102
+ - **Console**: View console logs within the app
103
+ - **Performance**: Monitor performance metrics
104
+ - **Zustand**: Monitor Zustand state management (if used)
105
+ - **Navigation**: Track navigation events
106
+ - **ThirdPartyLibs**: Access tools from third-party debugging libraries
107
+
108
+ ## Creating Custom Debug Features
109
+
110
+ You can create your own custom debugging features:
111
+
112
+ ```javascript
113
+ // In myCustomFeature.js
114
+ export const createMyCustomFeature = () => {
115
+ let customData = [];
116
+
117
+ return {
118
+ name: 'custom',
119
+ label: 'My Custom Feature',
120
+
121
+ setup: () => {
122
+ // Initialize your feature
123
+ console.log('My custom feature initialized');
124
+
125
+ // Start capturing data, set up listeners, etc.
126
+ },
127
+
128
+ getData: () => {
129
+ // Return data to display in the panel
130
+ return {
131
+ someMetric: 123,
132
+ customData,
133
+ status: 'Ready'
134
+ };
135
+ },
136
+
137
+ cleanup: () => {
138
+ // Clean up any listeners or resources
139
+ customData = [];
140
+ }
141
+ };
142
+ };
143
+
144
+ // In your App.js
145
+ import { createMyCustomFeature } from './myCustomFeature';
146
+
147
+ // Usage with manual setup
148
+ const debugToolKit = new DebugToolKit();
149
+ debugToolKit.addFeature(createMyCustomFeature());
150
+
151
+ // Or with initializeDebugToolkit
152
+ initializeDebugToolkit(['network', 'console', createMyCustomFeature]);
153
+ ```
154
+
155
+ ## Monitoring Zustand Stores
156
+
157
+ To monitor Zustand stores, use the provided middleware:
158
+
159
+ ```javascript
160
+ import { create } from 'zustand';
161
+ import { zustandLogMiddleware } from 'react-native-debug-toolkit';
162
+
163
+ const useStore = create(
164
+ zustandLogMiddleware(
165
+ (set) => ({
166
+ count: 0,
167
+ increment: () => set((state) => ({ count: state.count + 1 })),
168
+ decrement: () => set((state) => ({ count: state.count - 1 })),
169
+ })
170
+ )
171
+ );
172
+ ```
173
+
174
+ ## Tracking Navigation
175
+
176
+ To track navigation events:
177
+
178
+ ```javascript
179
+ import { useNavigationLogger } from 'react-native-debug-toolkit';
180
+
181
+ // In your navigation container
182
+ function AppNavigator() {
183
+ useNavigationLogger(); // This will automatically track navigation events
184
+
185
+ return (
186
+ <NavigationContainer>
187
+ {/* Your navigation structure */}
188
+ </NavigationContainer>
189
+ );
190
+ }
191
+ ```
192
+
193
+ Or manually log navigation events:
194
+
195
+ ```javascript
196
+ import { addNavigationLog } from 'react-native-debug-toolkit';
197
+
198
+ // Log navigation events manually
199
+ addNavigationLog({
200
+ type: 'navigate',
201
+ from: 'HomeScreen',
202
+ to: 'DetailScreen',
203
+ params: { id: 123 }
204
+ });
205
+ ```
67
206
 
68
207
  ## API Reference
69
208
 
@@ -75,13 +214,6 @@ Initializes a new instance of the debug toolkit. It's a singleton, so multiple c
75
214
  #### `addFeature(feature: Feature): DebugToolKit`
76
215
  Adds a new debugging feature to the toolkit. Returns the toolkit instance for chaining.
77
216
 
78
- Feature object must have:
79
- - `name`: Unique identifier for the feature
80
- - `label`: Display name in the debug panel
81
- - `setup()`: Function to run when the feature is added
82
- - `getData()`: Function that returns data to display in the panel
83
- - `cleanup()`: (Optional) Function to run when the feature is removed
84
-
85
217
  #### `showDebugPanel(): void`
86
218
  Shows the floating debug panel.
87
219
 
@@ -94,33 +226,25 @@ Updates the debug panel with the latest feature data.
94
226
  #### `destroy(): void`
95
227
  Cleans up the debug toolkit, removing all features and event listeners.
96
228
 
97
- ## Example: Network Feature
229
+ ### initializeDebugToolkit
98
230
 
99
- ```javascript
100
- // In debugFeatures.js
101
- import { NetworkFeature } from 'react-native-debug-toolkit/lib/features/NetworkFeature';
231
+ #### `initializeDebugToolkit(features = defaultFeatures, options = {})`
232
+ Convenience function to initialize and show the debug toolkit.
102
233
 
103
- export const createNetworkFeature = () => {
104
- const feature = new NetworkFeature();
105
- return {
106
- name: 'network',
107
- label: 'Network Logs',
108
- setup: () => feature.setup(),
109
- getData: () => feature.getData(),
110
- cleanup: () => feature.cleanup()
111
- };
112
- };
234
+ - `features`: Array of feature names (strings) or creator functions
235
+ - `options`: Additional options like `doraemonProductId` for iOS third-party debug libraries
113
236
 
114
- // In App.js
115
- const debugToolKit = new DebugToolKit();
116
- debugToolKit.addFeature(createNetworkFeature());
117
- debugToolKit.showDebugPanel();
118
- ```
237
+ ## Troubleshooting
119
238
 
120
- ## Contributing
239
+ ### Common Issues
121
240
 
122
- Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
241
+ 1. **Debug panel not showing**
242
+ - Make sure you're in development mode (`__DEV__` must be true)
243
+ - Check that you've called `showDebugPanel()`
123
244
 
124
- ## License
245
+ 2. **iOS features not working**
246
+ - Verify that you've added FLEX and DoraemonKit to your Podfile
247
+ - Run `pod install` again after making changes
125
248
 
126
- [MIT](https://choosealicense.com/licenses/mit/)
249
+ 3. **Performance issues**
250
+ - The Debug Toolkit is intended for development only. Make sure to use the `__DEV__` condition to prevent it from running in production.
@@ -0,0 +1,44 @@
1
+ package com.reactnative.debuglibs;
2
+
3
+ import com.facebook.react.bridge.ReactApplicationContext;
4
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
5
+ import com.facebook.react.bridge.ReactMethod;
6
+ import com.facebook.react.bridge.Promise;
7
+
8
+ import java.util.HashMap;
9
+ import java.util.Map;
10
+
11
+ public class BuildTypeModule extends ReactContextBaseJavaModule {
12
+ private final ReactApplicationContext reactContext;
13
+
14
+ public BuildTypeModule(ReactApplicationContext reactContext) {
15
+ super(reactContext);
16
+ this.reactContext = reactContext;
17
+ }
18
+
19
+ @Override
20
+ public String getName() {
21
+ return "BuildTypeModule";
22
+ }
23
+
24
+ @Override
25
+ public Map<String, Object> getConstants() {
26
+ final Map<String, Object> constants = new HashMap<>();
27
+ constants.put("buildType", BuildConfig.DEBUG ? "debug" : "release");
28
+ return constants;
29
+ }
30
+
31
+ @ReactMethod(isBlockingSynchronousMethod = true)
32
+ public String getBuildTypeSync() {
33
+ return BuildConfig.DEBUG ? "debug" : "release";
34
+ }
35
+
36
+ @ReactMethod
37
+ public void getBuildType(Promise promise) {
38
+ try {
39
+ promise.resolve(BuildConfig.DEBUG ? "debug" : "release");
40
+ } catch (Exception e) {
41
+ promise.reject("ERR_UNEXPECTED", e.getMessage(), e);
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,24 @@
1
+ package com.reactnative.debuglibs;
2
+
3
+ import com.facebook.react.ReactPackage;
4
+ import com.facebook.react.bridge.NativeModule;
5
+ import com.facebook.react.bridge.ReactApplicationContext;
6
+ import com.facebook.react.uimanager.ViewManager;
7
+
8
+ import java.util.ArrayList;
9
+ import java.util.Collections;
10
+ import java.util.List;
11
+
12
+ public class BuildTypePackage implements ReactPackage {
13
+ @Override
14
+ public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
+ List<NativeModule> modules = new ArrayList<>();
16
+ modules.add(new BuildTypeModule(reactContext));
17
+ return modules;
18
+ }
19
+
20
+ @Override
21
+ public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
22
+ return Collections.emptyList();
23
+ }
24
+ }
@@ -1,7 +1,6 @@
1
1
  package com.reactnative.debuglibs;
2
2
 
3
3
  import android.app.Application;
4
- import android.widget.Toast;
5
4
  import androidx.annotation.NonNull;
6
5
 
7
6
  import com.facebook.react.bridge.ReactApplicationContext;
@@ -56,15 +55,21 @@ public class RNDebugLibsModule extends ReactContextBaseJavaModule {
56
55
 
57
56
  @ReactMethod
58
57
  public void showDoraemonKit() {
59
- DoKit.showToolPanel();
60
- DoKit.show();
61
-
58
+ reactContext.runOnUiQueueThread(new Runnable() {
59
+ @Override
60
+ public void run() {
61
+ DoKit.show();
62
+ }
63
+ });
62
64
  }
63
65
 
64
66
  @ReactMethod
65
67
  public void hideDoraemonKit() {
66
- // Toast.makeText(reactContext, "hideDoraemonKit被调用", Toast.LENGTH_SHORT).show();
67
- // DoKit.hideToolPanel();
68
- DoKit.hide();
68
+ reactContext.runOnUiQueueThread(new Runnable() {
69
+ @Override
70
+ public void run() {
71
+ DoKit.hide();
72
+ }
73
+ });
69
74
  }
70
75
  }
package/index.js CHANGED
@@ -3,7 +3,7 @@
3
3
  * A comprehensive debugging toolkit for React Native
4
4
  */
5
5
  import DebugToolKit from './lib/DebugToolKit'
6
- import { initializeDebugToolkit } from './lib'
6
+ import { initializeDebugToolkit, isDebugMode } from './lib'
7
7
 
8
8
  import { createNetworkFeature } from './lib/features/NetworkFeature'
9
9
  import { createPerformanceFeature } from './lib/features/PerformanceFeature'
@@ -22,7 +22,8 @@ export {
22
22
  addZustandLog,
23
23
  createNavigationLogFeature,
24
24
  addNavigationLog,
25
- useNavigationLogger
25
+ useNavigationLogger,
26
+ isDebugMode
26
27
  }
27
28
 
28
29
  export default DebugToolKit
@@ -2,6 +2,7 @@ import React from 'react'
2
2
  import { BackHandler, Pressable, Text } from 'react-native'
3
3
  import RootSiblings from 'react-native-root-siblings'
4
4
  import FloatPanelView from './views/FloatPanelView'
5
+ import NativeDebugLibs from './NativeDebugLibs'
5
6
 
6
7
  export default class DebugToolKit {
7
8
  static instance = null
@@ -11,28 +12,38 @@ export default class DebugToolKit {
11
12
  return DebugToolKit.instance
12
13
  }
13
14
 
15
+ // Set the debug mode flag directly from NativeDebugLibs
16
+ this.isDebugMode = NativeDebugLibs.isDebugBuild()
14
17
  this.floatPanel = null
15
18
  this.features = []
16
19
  this.isPanelVisible = false
17
20
 
18
21
  const featuresToLoad = config.features || []
19
22
 
20
- featuresToLoad.forEach(featureOrCreator => {
21
- const feature = typeof featureOrCreator === 'function'
22
- ? featureOrCreator()
23
- : featureOrCreator
24
- this.addFeature(feature)
25
- })
23
+ // Only load features in debug mode
24
+ if (this.isDebugMode) {
25
+ featuresToLoad.forEach(featureOrCreator => {
26
+ const feature = typeof featureOrCreator === 'function'
27
+ ? featureOrCreator()
28
+ : featureOrCreator
29
+ this.addFeature(feature)
30
+ })
31
+
32
+ if (config.autoShow) {
33
+ this.showDebugPanel()
34
+ }
26
35
 
27
- if (config.autoShow) {
28
- this.showDebugPanel()
36
+ BackHandler.addEventListener('hardwareBackPress', () => true)
37
+ } else {
38
+ console.log('[DebugToolKit] Not initializing features - not in debug mode')
29
39
  }
30
-
31
- BackHandler.addEventListener('hardwareBackPress', () => true)
40
+
32
41
  DebugToolKit.instance = this
33
42
  }
34
43
 
35
44
  addFeature(feature) {
45
+ if (!this.isDebugMode) return this;
46
+
36
47
  if (feature && typeof feature.name === 'string') {
37
48
  this.features.push(feature)
38
49
  feature.setup?.()
@@ -43,7 +54,7 @@ export default class DebugToolKit {
43
54
  }
44
55
 
45
56
  showDebugPanel = () => {
46
- if (!__DEV__) {
57
+ if (!this.isDebugMode) {
47
58
  return
48
59
  }
49
60
 
@@ -1,8 +1,32 @@
1
1
  import { NativeModules, Platform } from 'react-native'
2
2
 
3
- const { RNDebugLibs } = NativeModules
3
+ const { RNDebugLibs, BuildTypeModule } = NativeModules
4
4
 
5
5
  export default class NativeDebugLibs {
6
+ // Build type methods
7
+ static getBuildType() {
8
+ if (BuildTypeModule) {
9
+ return BuildTypeModule.getBuildType();
10
+ }
11
+ return Promise.resolve(null);
12
+ }
13
+
14
+ static getBuildTypeSync() {
15
+ console.log('BuildTypeModule', BuildTypeModule);
16
+ if (BuildTypeModule) {
17
+ console.log('BuildTypeModule.getBuildTypeSync()', BuildTypeModule.getBuildTypeSync());
18
+ return BuildTypeModule.getBuildTypeSync();
19
+ }
20
+ return null;
21
+ }
22
+
23
+ static isDebugBuild() {
24
+ if (BuildTypeModule) {
25
+ return BuildTypeModule.getBuildTypeSync() === 'debug';
26
+ }
27
+ return false;
28
+ }
29
+
6
30
  // FLEX methods (iOS only)
7
31
  static showExplorer() {
8
32
  if (Platform.OS === 'ios' && RNDebugLibs) {
package/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import DebugToolKit from './DebugToolKit'
2
2
  import { createNetworkFeature } from './features/NetworkFeature'
3
- import { createPerformanceFeature} from './features/PerformanceFeature'
3
+ // import { createPerformanceFeature} from './features/PerformanceFeature'
4
4
  import { createConsoleLogFeature } from './features/ConsoleLogFeature'
5
5
  import { createZustandLogFeature, zustandLogMiddleware } from './features/ZustandLogFeature'
6
6
  import { createNavigationLogFeature, addNavigationLog } from './features/NavigationLogFeature'
@@ -11,7 +11,7 @@ import NativeDebugLibs from './NativeDebugLibs'
11
11
  const featureRegistry = {
12
12
  network: createNetworkFeature,
13
13
  console: createConsoleLogFeature,
14
- performance: createPerformanceFeature,
14
+ // performance: createPerformanceFeature,
15
15
  zustand: createZustandLogFeature,
16
16
  navigation: createNavigationLogFeature,
17
17
  thirdPartyLibs: createThirdPartyLibsFeature,
@@ -22,17 +22,25 @@ const featureRegistry = {
22
22
  // List of default features (can use strings now)
23
23
  const defaultFeatures = ['network', 'console', 'zustand', 'navigation', 'thirdPartyLibs']
24
24
 
25
+ // Export the debug mode status - this is used by the app
26
+ const isDebugMode = NativeDebugLibs.isDebugBuild();
27
+
25
28
  /**
26
29
  * Initializes and shows the Debug ToolKit panel with specified features.
27
- * Only runs in development mode (__DEV__ === true).
30
+ * Only runs in debug mode.
28
31
  * Features can be specified as strings (e.g., 'network') or creator functions.
29
32
  * @param {Array<string|Function>} features - Array of feature names (strings) or creator functions. Defaults to standard features.
30
33
  * @param {Object} options - Additional options like doraemonProductId for third-party debug libraries
31
34
  */
32
35
  export function initializeDebugToolkit(features = defaultFeatures, options = {}) {
33
-
36
+ // Create instance but it will internally handle debug mode check
34
37
  try {
35
38
  const debugToolKit = new DebugToolKit();
39
+
40
+ // If not in debug mode, the class methods won't do anything
41
+ if (!isDebugMode) {
42
+ return debugToolKit;
43
+ }
36
44
 
37
45
  // Initialize third-party debug libraries if configured
38
46
  if (options.doraemonProductId) {
@@ -89,12 +97,13 @@ export function initializeDebugToolkit(features = defaultFeatures, options = {})
89
97
  export {
90
98
  DebugToolKit,
91
99
  createNetworkFeature,
92
- createPerformanceFeature,
100
+ // createPerformanceFeature,
93
101
  createConsoleLogFeature,
94
102
  createZustandLogFeature,
95
103
  createNavigationLogFeature,
96
104
  createThirdPartyLibsFeature,
97
105
  addNavigationLog,
98
106
  zustandLogMiddleware, // Export middleware for use in Zustand stores
99
- featureRegistry
107
+ featureRegistry,
108
+ isDebugMode
100
109
  };
@@ -16,7 +16,7 @@ import {
16
16
  // import AsyncStorage from '@react-native-async-storage/async-storage'
17
17
  import { IconRadius, DebugColors } from '../utils/DebugConst'
18
18
  import SubViewHTTPLogs from './SubViewHTTPLogs'
19
- import SubViewPerformance from './SubViewPerformance'
19
+ // import SubViewPerformance from './SubViewPerformance'
20
20
  import SubViewConsoleLogs from './SubViewConsoleLogs'
21
21
  import SubViewZustandLogs from './SubViewZustandLogs'
22
22
  import SubViewNavigationLogs from './SubViewNavigationLogs'
@@ -305,9 +305,9 @@ export default class FloatPanelView extends Component {
305
305
  }
306
306
 
307
307
  // Special handling for performance view
308
- if (feature.name === 'performance') {
309
- return <SubViewPerformance />
310
- }
308
+ // if (feature.name === 'performance') {
309
+ // return <SubViewPerformance />
310
+ // }
311
311
 
312
312
  if (feature.name === 'console') {
313
313
  return <SubViewConsoleLogs logs={data} />
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-debug-toolkit",
3
- "version": "0.4.2",
3
+ "version": "0.5.0",
4
4
  "description": "A simple yet powerful debugging toolkit for React Native with a convenient floating UI for development",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",