react-native-debug-toolkit 0.4.3 → 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 +203 -58
- package/README.zh-CN.md +230 -0
- package/android/src/main/java/com/reactnative/debuglibs/BuildTypeModule.java +44 -0
- package/android/src/main/java/com/reactnative/debuglibs/BuildTypePackage.java +25 -0
- package/index.js +3 -2
- package/lib/DebugToolKit.js +22 -11
- package/lib/NativeDebugLibs.js +25 -1
- package/lib/index.js +15 -6
- package/lib/views/FloatPanelView.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,35 +22,84 @@ pod 'FLEX', :configurations => ['Debug']
|
|
|
22
22
|
pod 'DoraemonKit/Core', :configurations => ['Debug']
|
|
23
23
|
```
|
|
24
24
|
|
|
25
|
-
3.
|
|
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
|
|
|
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`:
|
|
70
|
+
|
|
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
|
+
|
|
31
82
|
## Basic Usage
|
|
32
83
|
|
|
84
|
+
The easiest way to add the debug toolkit to your app is using the `initializeDebugToolkit` function with default features:
|
|
85
|
+
|
|
33
86
|
```javascript
|
|
34
|
-
// In your App.js
|
|
35
|
-
import
|
|
87
|
+
// In your App.js or other initialization file
|
|
88
|
+
import React, { useEffect } from 'react';
|
|
89
|
+
import { initializeDebugToolkit, isDebugMode } from 'react-native-debug-toolkit';
|
|
36
90
|
|
|
37
91
|
function App() {
|
|
38
92
|
useEffect(() => {
|
|
39
|
-
if (
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
getData: () => ({ message: 'Hello debugging world!' })
|
|
46
|
-
});
|
|
47
|
-
debugToolKit.showDebugPanel();
|
|
93
|
+
if (isDebugMode) {
|
|
94
|
+
// Initialize with all default features
|
|
95
|
+
initializeDebugToolkit();
|
|
96
|
+
|
|
97
|
+
// Or select specific built-in features
|
|
98
|
+
// initializeDebugToolkit(['network', 'console', 'zustand', 'navigation', 'thirdPartyLibs']);
|
|
48
99
|
}
|
|
49
100
|
|
|
50
101
|
return () => {
|
|
51
|
-
|
|
52
|
-
DebugToolKit.instance.destroy();
|
|
53
|
-
}
|
|
102
|
+
// Cleanup happens automatically
|
|
54
103
|
};
|
|
55
104
|
}, []);
|
|
56
105
|
|
|
@@ -58,69 +107,165 @@ function App() {
|
|
|
58
107
|
}
|
|
59
108
|
```
|
|
60
109
|
|
|
61
|
-
|
|
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
|
-
-
|
|
64
|
-
- Customizable debugging features
|
|
65
|
-
- Development-only functionality (automatically disabled in production)
|
|
66
|
-
- Easy to extend with your own debug tools
|
|
112
|
+
## Built-in Features
|
|
67
113
|
|
|
68
|
-
|
|
114
|
+
By initializing with the single line of code above, you'll automatically get access to all these debugging features:
|
|
69
115
|
|
|
70
|
-
|
|
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)
|
|
71
121
|
|
|
72
|
-
|
|
73
|
-
Initializes a new instance of the debug toolkit. It's a singleton, so multiple calls will return the same instance.
|
|
122
|
+
## Integration
|
|
74
123
|
|
|
75
|
-
|
|
76
|
-
Adds a new debugging feature to the toolkit. Returns the toolkit instance for chaining.
|
|
124
|
+
### Advanced Axios Network Tracking
|
|
77
125
|
|
|
78
|
-
|
|
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
|
|
126
|
+
For projects using Axios, you can enable more detailed network request tracking:
|
|
84
127
|
|
|
85
|
-
|
|
86
|
-
|
|
128
|
+
```javascript
|
|
129
|
+
import axios from 'axios';
|
|
130
|
+
import { createNetworkFeature, isDebugMode } from 'react-native-debug-toolkit';
|
|
87
131
|
|
|
88
|
-
|
|
89
|
-
|
|
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
|
+
}
|
|
141
|
+
```
|
|
90
142
|
|
|
91
|
-
|
|
92
|
-
Updates the debug panel with the latest feature data.
|
|
143
|
+
### Monitoring Zustand Stores (If You Use Zustand)
|
|
93
144
|
|
|
94
|
-
|
|
95
|
-
Cleans up the debug toolkit, removing all features and event listeners.
|
|
145
|
+
If your app uses Zustand for state management, just add the middleware to track all state changes:
|
|
96
146
|
|
|
97
|
-
|
|
147
|
+
```javascript
|
|
148
|
+
import { create } from 'zustand';
|
|
149
|
+
import { zustandLogMiddleware } from 'react-native-debug-toolkit';
|
|
150
|
+
|
|
151
|
+
// Simply add zustandLogMiddleware to wrap your store
|
|
152
|
+
const useStore = create(
|
|
153
|
+
zustandLogMiddleware(
|
|
154
|
+
(set) => ({
|
|
155
|
+
count: 0,
|
|
156
|
+
increment: () => set((state) => ({ count: state.count + 1 })),
|
|
157
|
+
decrement: () => set((state) => ({ count: state.count - 1 })),
|
|
158
|
+
})
|
|
159
|
+
)
|
|
160
|
+
);
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Navigation Tracking (React Navigation)
|
|
164
|
+
|
|
165
|
+
If you're using React Navigation, adding navigation tracking is just one step:
|
|
166
|
+
|
|
167
|
+
```javascript
|
|
168
|
+
import React, { useRef } from 'react';
|
|
169
|
+
import { NavigationContainer } from '@react-navigation/native';
|
|
170
|
+
import { useNavigationLogger } from 'react-native-debug-toolkit';
|
|
171
|
+
|
|
172
|
+
function AppNavigator() {
|
|
173
|
+
const navigationRef = useRef(null);
|
|
174
|
+
|
|
175
|
+
// Add this line to enable navigation logging
|
|
176
|
+
useNavigationLogger(navigationRef);
|
|
177
|
+
|
|
178
|
+
return (
|
|
179
|
+
<NavigationContainer ref={navigationRef}>
|
|
180
|
+
{/* Your navigation configuration */}
|
|
181
|
+
</NavigationContainer>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Custom Configuration
|
|
187
|
+
|
|
188
|
+
If you don't need all features, you can selectively enable specific ones:
|
|
98
189
|
|
|
99
190
|
```javascript
|
|
100
|
-
//
|
|
101
|
-
|
|
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
|
+
]);
|
|
202
|
+
```
|
|
102
203
|
|
|
103
|
-
|
|
104
|
-
|
|
204
|
+
## Creating Custom Debug Features
|
|
205
|
+
|
|
206
|
+
You can create your own custom debugging features:
|
|
207
|
+
|
|
208
|
+
```javascript
|
|
209
|
+
// In myCustomFeature.js
|
|
210
|
+
export const createMyCustomFeature = () => {
|
|
211
|
+
let customData = [];
|
|
212
|
+
|
|
105
213
|
return {
|
|
106
|
-
name: '
|
|
107
|
-
label: '
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
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
|
+
}
|
|
111
247
|
};
|
|
112
248
|
};
|
|
113
249
|
|
|
114
|
-
//
|
|
115
|
-
|
|
116
|
-
debugToolKit.addFeature(createNetworkFeature());
|
|
117
|
-
debugToolKit.showDebugPanel();
|
|
250
|
+
// Usage with initializeDebugToolkit
|
|
251
|
+
initializeDebugToolkit(['network', 'console', createMyCustomFeature]);
|
|
118
252
|
```
|
|
119
253
|
|
|
120
|
-
##
|
|
254
|
+
## Troubleshooting
|
|
255
|
+
|
|
256
|
+
### Debug panel not showing
|
|
257
|
+
- Make sure you're in development mode (`isDebugMode` is true)
|
|
258
|
+
- Check that you've correctly called `initializeDebugToolkit()`
|
|
121
259
|
|
|
122
|
-
|
|
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
|
|
123
264
|
|
|
124
|
-
|
|
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
|
|
125
268
|
|
|
126
|
-
|
|
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
|
package/README.zh-CN.md
ADDED
|
@@ -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
|
+
|
|
@@ -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,25 @@
|
|
|
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
|
+
modules.add(new RNDebugLibsModule(reactContext));
|
|
18
|
+
return modules;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Override
|
|
22
|
+
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
|
|
23
|
+
return Collections.emptyList();
|
|
24
|
+
}
|
|
25
|
+
}
|
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
|
package/lib/DebugToolKit.js
CHANGED
|
@@ -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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
|
|
28
|
-
|
|
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 (!
|
|
57
|
+
if (!this.isDebugMode) {
|
|
47
58
|
return
|
|
48
59
|
}
|
|
49
60
|
|
package/lib/NativeDebugLibs.js
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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