react-native-debug-toolkit 0.5.0 → 0.5.1

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
@@ -22,31 +22,80 @@ pod 'FLEX', :configurations => ['Debug']
22
22
  pod 'DoraemonKit/Core', :configurations => ['Debug']
23
23
  ```
24
24
 
25
- 3. Run pod install in your iOS directory:
25
+ 3. Add the following code to your AppDelegate.m in the `didFinishLaunchingWithOptions` method:
26
+
27
+ ```objc
28
+ #ifdef DEBUG
29
+ #import <DoraemonKit/DoraemonManager.h>
30
+ #endif
31
+
32
+ #ifdef DEBUG
33
+ DoraemonManager *doKit = [DoraemonManager shareInstance];
34
+ doKit.autoDock = false;
35
+ [doKit install];
36
+ [doKit hiddenDoraemon];
37
+ #endif
38
+ ```
39
+
40
+ 4. Run pod install in your iOS directory:
26
41
 
27
42
  ```bash
28
43
  cd ios && pod install
29
44
  ```
30
45
 
31
- ## Basic Usage
46
+ ### Android Additional Setup
47
+
48
+ 1. Add the following to your `android/settings.gradle`:
49
+
50
+ ```gradle
51
+ include ':react-native-debug-toolkit'
52
+ project(':react-native-debug-toolkit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-debug-toolkit/android')
53
+ ```
54
+
55
+ 2. Add these dependencies to your `android/app/build.gradle`:
56
+
57
+ ```gradle
58
+ dependencies {
59
+ // Other dependencies...
60
+
61
+ debugImplementation 'io.github.didi.dokit:dokitx:3.7.1'
62
+ releaseImplementation 'io.github.didi.dokit:dokitx-no-op:3.7.1'
63
+ debugImplementation 'com.android.volley:volley:1.2.0'
64
+
65
+ implementation project(':react-native-debug-toolkit')
66
+ }
67
+ ```
68
+
69
+ 3. Initialize DoKit in your `MainApplication.kt`:
32
70
 
33
- ### Method 1: Quick Setup with Default Features
71
+ ```kotlin
72
+ import com.didichuxing.doraemonkit.DoKit
73
+
74
+ // Inside onCreate method
75
+ if (BuildConfig.DEBUG) {
76
+ DoKit.Builder(this)
77
+ .build()
78
+ DoKit.hide()
79
+ }
80
+ ```
81
+
82
+ ## Basic Usage
34
83
 
35
84
  The easiest way to add the debug toolkit to your app is using the `initializeDebugToolkit` function with default features:
36
85
 
37
86
  ```javascript
38
87
  // In your App.js or other initialization file
39
88
  import React, { useEffect } from 'react';
40
- import { initializeDebugToolkit } from 'react-native-debug-toolkit';
89
+ import { initializeDebugToolkit, isDebugMode } from 'react-native-debug-toolkit';
41
90
 
42
91
  function App() {
43
92
  useEffect(() => {
44
- if (__DEV__) {
93
+ if (isDebugMode) {
45
94
  // Initialize with all default features
46
95
  initializeDebugToolkit();
47
96
 
48
97
  // Or select specific built-in features
49
- // initializeDebugToolkit(['network', 'console', 'performance']);
98
+ // initializeDebugToolkit(['network', 'console', 'zustand', 'navigation', 'thirdPartyLibs']);
50
99
  }
51
100
 
52
101
  return () => {
@@ -58,108 +107,48 @@ function App() {
58
107
  }
59
108
  ```
60
109
 
61
- ### Method 2: Manual Setup
110
+ That's it! Your app will now display a floating debug panel in development mode, giving you access to all debugging features.
62
111
 
63
- For more control, you can manually set up the toolkit:
112
+ ## Built-in Features
64
113
 
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';
114
+ By initializing with the single line of code above, you'll automatically get access to all these debugging features:
72
115
 
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
116
+ - **Network**: Track and inspect all network requests and responses
117
+ - **Console**: View all console logs within the app
118
+ - **Zustand**: Monitor Zustand state management (if your app uses Zustand)
119
+ - **Navigation**: Automatically track navigation events in your app
120
+ - **ThirdPartyLibs**: Quick access to native debugging tools (FLEX for iOS, DoraemonKit)
98
121
 
99
- The toolkit comes with several built-in debugging features:
122
+ ## Integration
100
123
 
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
124
+ ### Advanced Axios Network Tracking
107
125
 
108
- ## Creating Custom Debug Features
109
-
110
- You can create your own custom debugging features:
126
+ For projects using Axios, you can enable more detailed network request tracking:
111
127
 
112
128
  ```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
- };
129
+ import axios from 'axios';
130
+ import { createNetworkFeature, isDebugMode } from 'react-native-debug-toolkit';
143
131
 
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]);
132
+ // Get network feature instance and set up Axios interceptors
133
+ if (isDebugMode) {
134
+ const networkFeature = createNetworkFeature();
135
+ networkFeature.setupAxiosInterceptors(axios);
136
+
137
+ // Optional: exclude sensitive URLs (like authentication endpoints)
138
+ networkFeature.addUrlToBlacklist('api.example.com/auth');
139
+ networkFeature.addUrlToBlacklist(/password/i); // Regex patterns supported
140
+ }
153
141
  ```
154
142
 
155
- ## Monitoring Zustand Stores
143
+ ### Monitoring Zustand Stores (If You Use Zustand)
156
144
 
157
- To monitor Zustand stores, use the provided middleware:
145
+ If your app uses Zustand for state management, just add the middleware to track all state changes:
158
146
 
159
147
  ```javascript
160
148
  import { create } from 'zustand';
161
149
  import { zustandLogMiddleware } from 'react-native-debug-toolkit';
162
150
 
151
+ // Simply add zustandLogMiddleware to wrap your store
163
152
  const useStore = create(
164
153
  zustandLogMiddleware(
165
154
  (set) => ({
@@ -171,80 +160,112 @@ const useStore = create(
171
160
  );
172
161
  ```
173
162
 
174
- ## Tracking Navigation
163
+ ### Navigation Tracking (React Navigation)
175
164
 
176
- To track navigation events:
165
+ If you're using React Navigation, adding navigation tracking is just one step:
177
166
 
178
167
  ```javascript
168
+ import React, { useRef } from 'react';
169
+ import { NavigationContainer } from '@react-navigation/native';
179
170
  import { useNavigationLogger } from 'react-native-debug-toolkit';
180
171
 
181
- // In your navigation container
182
172
  function AppNavigator() {
183
- useNavigationLogger(); // This will automatically track navigation events
173
+ const navigationRef = useRef(null);
174
+
175
+ // Add this line to enable navigation logging
176
+ useNavigationLogger(navigationRef);
184
177
 
185
178
  return (
186
- <NavigationContainer>
187
- {/* Your navigation structure */}
179
+ <NavigationContainer ref={navigationRef}>
180
+ {/* Your navigation configuration */}
188
181
  </NavigationContainer>
189
182
  );
190
183
  }
191
184
  ```
192
185
 
193
- Or manually log navigation events:
186
+ ## Custom Configuration
187
+
188
+ If you don't need all features, you can selectively enable specific ones:
194
189
 
195
190
  ```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
- });
191
+ // Only enable network and console logging features
192
+ initializeDebugToolkit(['network', 'console']);
193
+
194
+ // Or specify a custom set of features
195
+ initializeDebugToolkit([
196
+ 'network',
197
+ 'console',
198
+ 'zustand',
199
+ 'navigation',
200
+ 'thirdPartyLibs'
201
+ ]);
205
202
  ```
206
203
 
207
- ## API Reference
208
-
209
- ### DebugToolKit
210
-
211
- #### `new DebugToolKit()`
212
- Initializes a new instance of the debug toolkit. It's a singleton, so multiple calls will return the same instance.
213
-
214
- #### `addFeature(feature: Feature): DebugToolKit`
215
- Adds a new debugging feature to the toolkit. Returns the toolkit instance for chaining.
216
-
217
- #### `showDebugPanel(): void`
218
- Shows the floating debug panel.
219
-
220
- #### `hideDebugPanel(): void`
221
- Hides the floating debug panel.
222
-
223
- #### `updateDebugPanel(): void`
224
- Updates the debug panel with the latest feature data.
225
-
226
- #### `destroy(): void`
227
- Cleans up the debug toolkit, removing all features and event listeners.
204
+ ## Creating Custom Debug Features
228
205
 
229
- ### initializeDebugToolkit
206
+ You can create your own custom debugging features:
230
207
 
231
- #### `initializeDebugToolkit(features = defaultFeatures, options = {})`
232
- Convenience function to initialize and show the debug toolkit.
208
+ ```javascript
209
+ // In myCustomFeature.js
210
+ export const createMyCustomFeature = () => {
211
+ let customData = [];
212
+
213
+ return {
214
+ name: 'custom', // Unique identifier
215
+ label: 'My Custom Feature', // Display name in UI
216
+
217
+ setup: () => {
218
+ // Initialize your feature
219
+ console.log('My custom feature initialized');
220
+
221
+ // Start capturing data, set up listeners, etc.
222
+ const interval = setInterval(() => {
223
+ customData.push({
224
+ timestamp: new Date(),
225
+ value: Math.random() * 100
226
+ });
227
+
228
+ // Limit the amount of data stored
229
+ if (customData.length > 100) {
230
+ customData.shift();
231
+ }
232
+ }, 1000);
233
+
234
+ // Return cleanup function if needed
235
+ return () => clearInterval(interval);
236
+ },
237
+
238
+ getData: () => {
239
+ // Return data to display in the panel
240
+ return customData;
241
+ },
242
+
243
+ cleanup: () => {
244
+ // Clean up any listeners or resources
245
+ customData = [];
246
+ }
247
+ };
248
+ };
233
249
 
234
- - `features`: Array of feature names (strings) or creator functions
235
- - `options`: Additional options like `doraemonProductId` for iOS third-party debug libraries
250
+ // Usage with initializeDebugToolkit
251
+ initializeDebugToolkit(['network', 'console', createMyCustomFeature]);
252
+ ```
236
253
 
237
254
  ## Troubleshooting
238
255
 
239
- ### Common Issues
256
+ ### Debug panel not showing
257
+ - Make sure you're in development mode (`isDebugMode` is true)
258
+ - Check that you've correctly called `initializeDebugToolkit()`
240
259
 
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()`
260
+ ### iOS features not working
261
+ - Verify that you've added FLEX and DoraemonKit to your Podfile
262
+ - Run `pod install` again after making changes
263
+ - Make sure you're running a Debug build
244
264
 
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
265
+ ### Network requests not captured
266
+ - For Axios, ensure you've called `setupAxiosInterceptors(axios)`
267
+ - For fetch requests, the toolkit should automatically intercept them without additional configuration
248
268
 
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.
269
+ ### App performance issues
270
+ - This debug toolkit is meant for development only, ensure it's not included in production builds
271
+ - If performance is affected in development mode, try enabling only specific features
@@ -0,0 +1,230 @@
1
+
2
+
3
+
4
+ # React Native Debug Toolkit 使用文档
5
+
6
+ 一个简单但功能强大的React Native调试工具包,提供便捷的开发期浮动界面。
7
+
8
+ ## 安装
9
+
10
+ ```bash
11
+ npm install react-native-debug-toolkit
12
+ # 或
13
+ yarn add react-native-debug-toolkit
14
+ ```
15
+
16
+ ### iOS 额外设置
17
+
18
+ 该工具包使用FLEX和DoraemonKit提供iOS调试功能。请按以下步骤正确集成:
19
+
20
+ 1. 确保项目中已安装CocoaPods
21
+ 2. 在Podfile中添加以下依赖:
22
+
23
+ ```ruby
24
+ pod 'FLEX', :configurations => ['Debug']
25
+ pod 'DoraemonKit/Core', :git => 'https://github.com/superzcj/DoKit.git', :configurations => ['Debug'] #必选
26
+ ```
27
+
28
+ 3. 在`didFinishLaunchingWithOptions`方法中的AppDelegate.m文件中添加以下代码:
29
+
30
+ ```objc
31
+ #ifdef DEBUG
32
+ #import <DoraemonKit/DoraemonManager.h>
33
+ #endif
34
+
35
+ #ifdef DEBUG
36
+ DoraemonManager *doKit = [DoraemonManager shareInstance];
37
+ doKit.autoDock = false;
38
+ [doKit install];
39
+ [doKit hiddenDoraemon];
40
+ #endif
41
+ ```
42
+
43
+ 4. 在iOS目录中运行pod install:
44
+
45
+ ```bash
46
+ cd ios && pod install
47
+ ```
48
+
49
+ ### Android 额外设置
50
+
51
+ 1. 在`android/settings.gradle`中添加以下内容:
52
+
53
+ ```gradle
54
+ include ':react-native-debug-toolkit'
55
+ project(':react-native-debug-toolkit').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-debug-toolkit/android')
56
+ ```
57
+
58
+ 2. 在`android/app/build.gradle`中添加以下依赖:
59
+
60
+ ```gradle
61
+ dependencies {
62
+ // 其他依赖...
63
+
64
+ debugImplementation 'io.github.didi.dokit:dokitx:3.7.1'
65
+ releaseImplementation 'io.github.didi.dokit:dokitx-no-op:3.7.1'
66
+ debugImplementation 'com.android.volley:volley:1.2.0'
67
+
68
+ implementation project(':react-native-debug-toolkit')
69
+ }
70
+ ```
71
+
72
+ 3. 在`MainApplication.kt`中初始化DoKit:
73
+
74
+ ```kotlin
75
+ import com.didichuxing.doraemonkit.DoKit
76
+ import com.reactnative.debuglibs.RNDebugLibsPackage
77
+
78
+ // 在getPackages方法内
79
+ add(RNDebugLibsPackage())
80
+
81
+ // 在onCreate方法内
82
+ if (BuildConfig.DEBUG) {
83
+ DoKit.Builder(this)
84
+ .build()
85
+ DoKit.hide()
86
+ }
87
+ ```
88
+
89
+ ## 使用方法
90
+
91
+ 将调试工具包添加到您的应用程序中非常简单,只需一行代码即可启用所有功能:
92
+
93
+ ```javascript
94
+ // 在App.js或其他初始化文件中
95
+ import React, { useEffect } from 'react';
96
+ import { initializeDebugToolkit, isDebugMode } from 'react-native-debug-toolkit';
97
+
98
+ function App() {
99
+ useEffect(() => {
100
+ if (isDebugMode) {
101
+ // 使用所有默认功能初始化
102
+ initializeDebugToolkit();
103
+
104
+ // 或选择特定的内置功能
105
+ // initializeDebugToolkit(['network', 'console', 'zustand', 'navigation', 'thirdPartyLibs']);
106
+ }
107
+
108
+ return () => {
109
+ // 自动清理
110
+ };
111
+ }, []);
112
+
113
+ return <YourApp />;
114
+ }
115
+ ```
116
+
117
+ 就这么简单!现在您的应用程序将在开发模式下显示一个浮动的调试面板,让您可以访问所有调试功能。
118
+
119
+ ## 内置功能
120
+
121
+ 通过上面的一行代码初始化,您将自动获得以下所有调试功能:
122
+
123
+ - **网络监控**:跟踪和检查所有网络请求和响应
124
+ - **控制台日志**:在应用内查看所有控制台日志输出
125
+ - **Zustand状态**:监控Zustand状态管理(如果您的应用使用Zustand)
126
+ - **导航跟踪**:自动记录应用内的导航事件
127
+ - **第三方调试工具**:快速访问原生调试工具(iOS的FLEX,iOS和Android的DoraemonKit)
128
+
129
+ ## 集成
130
+
131
+ ### 高级Axios网络跟踪
132
+
133
+ 对于使用Axios的项目,您可以启用更详细的网络请求跟踪:
134
+
135
+ ```javascript
136
+ import axios from 'axios';
137
+ import { createNetworkFeature, isDebugMode } from 'react-native-debug-toolkit';
138
+
139
+ // 获取网络功能实例并设置Axios拦截器
140
+ if (isDebugMode) {
141
+ const networkFeature = createNetworkFeature();
142
+ networkFeature.setupAxiosInterceptors(axios);
143
+
144
+ // 可选:排除敏感URL(如认证接口)
145
+ networkFeature.addUrlToBlacklist('api.example.com/auth');
146
+ networkFeature.addUrlToBlacklist(/password/i); // 支持正则表达式
147
+ }
148
+ ```
149
+
150
+ ### 监控Zustand状态(如果您使用Zustand)
151
+
152
+ 如果您的应用使用Zustand进行状态管理,只需添加中间件即可跟踪所有状态变化:
153
+
154
+ ```javascript
155
+ import { create } from 'zustand';
156
+ import { zustandLogMiddleware } from 'react-native-debug-toolkit';
157
+
158
+ // 只需添加zustandLogMiddleware来包装您的store
159
+ const useStore = create(
160
+ zustandLogMiddleware(
161
+ (set) => ({
162
+ count: 0,
163
+ increment: () => set((state) => ({ count: state.count + 1 })),
164
+ decrement: () => set((state) => ({ count: state.count - 1 })),
165
+ })
166
+ )
167
+ );
168
+ ```
169
+
170
+ ### 导航跟踪(React Navigation)
171
+
172
+ 如果您使用React Navigation,添加导航跟踪只需一步:
173
+
174
+ ```javascript
175
+ import React, { useRef } from 'react';
176
+ import { NavigationContainer } from '@react-navigation/native';
177
+ import { useNavigationLogger } from 'react-native-debug-toolkit';
178
+
179
+ function AppNavigator() {
180
+ const navigationRef = useRef(null);
181
+
182
+ // 添加这一行来启用导航日志
183
+ useNavigationLogger(navigationRef);
184
+
185
+ return (
186
+ <NavigationContainer ref={navigationRef}>
187
+ {/* 您的导航配置 */}
188
+ </NavigationContainer>
189
+ );
190
+ }
191
+ ```
192
+
193
+ ## 自定义配置
194
+
195
+ 如果您不需要所有功能,可以选择性地启用特定功能:
196
+
197
+ ```javascript
198
+ // 只启用网络和控制台日志功能
199
+ initializeDebugToolkit(['network', 'console']);
200
+
201
+ // 或者指定一组自定义功能
202
+ initializeDebugToolkit([
203
+ 'network',
204
+ 'console',
205
+ 'zustand',
206
+ 'navigation',
207
+ 'thirdPartyLibs'
208
+ ]);
209
+ ```
210
+
211
+ ## 常见问题排除
212
+
213
+ ### 调试面板不显示
214
+ - 确保您在开发模式下(`isDebugMode`为true)
215
+ - 检查是否正确调用了`initializeDebugToolkit()`
216
+
217
+ ### iOS功能不工作
218
+ - 确认您已将FLEX和DoraemonKit添加到Podfile
219
+ - 在修改后重新运行`pod install`
220
+ - 确保您正在运行Debug构建版本
221
+
222
+ ### 网络请求未被捕获
223
+ - 对于Axios,请确保调用了`setupAxiosInterceptors(axios)`
224
+ - 对于fetch请求,工具包会自动拦截,无需额外配置
225
+
226
+ ### 应用性能问题
227
+ - 此调试工具包仅适用于开发阶段,请确保生产构建中未包含
228
+ - 如果开发模式下性能受影响,可以尝试只启用特定功能    
229
+
230
+
@@ -14,6 +14,7 @@ public class BuildTypePackage implements ReactPackage {
14
14
  public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
15
  List<NativeModule> modules = new ArrayList<>();
16
16
  modules.add(new BuildTypeModule(reactContext));
17
+ modules.add(new RNDebugLibsModule(reactContext));
17
18
  return modules;
18
19
  }
19
20
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-debug-toolkit",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
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",