react-native-debug-toolkit 0.1.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.
@@ -0,0 +1,75 @@
1
+ import React from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ Modal,
6
+ StyleSheet,
7
+ Dimensions
8
+ } from 'react-native';
9
+ import { DebugColors } from '../utils/DebugConst';
10
+
11
+ const { width: screenWidth, height: screenHeight } = Dimensions.get('window');
12
+
13
+ const RestartModal = () => {
14
+ return (
15
+ <Modal
16
+ visible={true}
17
+ transparent={true}
18
+ animationType="fade"
19
+ onRequestClose={() => {}}
20
+ >
21
+ <View style={styles.overlay}>
22
+ <View style={styles.modalContent}>
23
+ <Text style={styles.title}>Environment Changed</Text>
24
+ <Text style={styles.message}>
25
+ The app needs to restart to apply the new environment settings.{'\n\n'}
26
+ Please manually kill the app and restart it.
27
+ </Text>
28
+ </View>
29
+ </View>
30
+ </Modal>
31
+ );
32
+ };
33
+
34
+ const styles = StyleSheet.create({
35
+ overlay: {
36
+ position: 'absolute',
37
+ top: 0,
38
+ left: 0,
39
+ right: 0,
40
+ bottom: 0,
41
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
42
+ justifyContent: 'center',
43
+ alignItems: 'center',
44
+ width: screenWidth,
45
+ height: screenHeight,
46
+ zIndex: 9999,
47
+ },
48
+ modalContent: {
49
+ backgroundColor: 'white',
50
+ borderRadius: 10,
51
+ padding: 20,
52
+ width: screenWidth * 0.8,
53
+ alignItems: 'center',
54
+ elevation: 5,
55
+ shadowColor: '#000',
56
+ shadowOffset: { width: 0, height: 2 },
57
+ shadowOpacity: 0.25,
58
+ shadowRadius: 3.84,
59
+ },
60
+ title: {
61
+ fontSize: 18,
62
+ fontWeight: 'bold',
63
+ color: DebugColors.text,
64
+ marginBottom: 15,
65
+ textAlign: 'center'
66
+ },
67
+ message: {
68
+ fontSize: 16,
69
+ color: DebugColors.text,
70
+ textAlign: 'center',
71
+ lineHeight: 22
72
+ }
73
+ });
74
+
75
+ export default RestartModal;
@@ -0,0 +1,73 @@
1
+ import React from 'react';
2
+ import {
3
+ View,
4
+ Text,
5
+ TouchableOpacity,
6
+ StyleSheet,
7
+ ScrollView
8
+ } from 'react-native';
9
+ import { DebugColors } from '../utils/DebugConst';
10
+
11
+ const SubViewEnvironment = ({ options, currentValue, onChange }) => {
12
+ return (
13
+ <View style={styles.container}>
14
+ <Text style={styles.title}>Environment</Text>
15
+ <ScrollView style={styles.scrollView}>
16
+ {options.map((option, index) => (
17
+ <TouchableOpacity
18
+ key={index}
19
+ style={[
20
+ styles.option,
21
+ option.value === currentValue && styles.selectedOption
22
+ ]}
23
+ onPress={() => onChange(option.value)}
24
+ >
25
+ <Text style={[
26
+ styles.optionText,
27
+ option.value === currentValue && styles.selectedOptionText
28
+ ]}>
29
+ {option.label}
30
+ </Text>
31
+ </TouchableOpacity>
32
+ ))}
33
+ </ScrollView>
34
+ </View>
35
+ );
36
+ };
37
+
38
+ const styles = StyleSheet.create({
39
+ container: {
40
+ flex: 1,
41
+ padding: 15
42
+ },
43
+ title: {
44
+ fontSize: 18,
45
+ fontWeight: 'bold',
46
+ marginBottom: 15,
47
+ color: DebugColors.text
48
+ },
49
+ scrollView: {
50
+ flex: 1
51
+ },
52
+ option: {
53
+ padding: 12,
54
+ borderRadius: 8,
55
+ marginBottom: 8,
56
+ backgroundColor: DebugColors.background,
57
+ borderWidth: 1,
58
+ borderColor: DebugColors.border
59
+ },
60
+ selectedOption: {
61
+ backgroundColor: DebugColors.blue,
62
+ borderColor: DebugColors.blue
63
+ },
64
+ optionText: {
65
+ fontSize: 16,
66
+ color: DebugColors.text
67
+ },
68
+ selectedOptionText: {
69
+ color: DebugColors.white
70
+ }
71
+ });
72
+
73
+ export default SubViewEnvironment;
@@ -0,0 +1,267 @@
1
+ import React, { useState } from 'react'
2
+ import {
3
+ View,
4
+ Text,
5
+ StyleSheet,
6
+ FlatList,
7
+ TouchableOpacity,
8
+ Modal,
9
+ } from 'react-native'
10
+ import HttpLogDetails from './HttpLogDetails'
11
+
12
+ const SubViewHTTPLogs = ({ logs = [] }) => {
13
+ const [selectedLog, setSelectedLog] = useState(null)
14
+
15
+ const getMethodColor = (method) => {
16
+ switch (method?.toUpperCase()) {
17
+ case 'GET':
18
+ return '#0D96F2' // Standard API blue
19
+ case 'POST':
20
+ return '#49CC90' // Swagger green
21
+ case 'PUT':
22
+ return '#FCA130' // Standard PUT orange
23
+ case 'DELETE':
24
+ return '#F93E3E' // Standard DELETE red
25
+ default:
26
+ return '#666666'
27
+ }
28
+ }
29
+
30
+ const renderLogItem = ({ item }) => {
31
+ // Check both HTTP status and API success flag
32
+ const isSuccess = item.response?.success ?? item.response?.status < 400
33
+ const statusColor = !isSuccess ? '#ff4444' : '#00C851'
34
+ const methodColor = getMethodColor(item.request?.method)
35
+
36
+ return (
37
+ <TouchableOpacity
38
+ style={styles.logItem}
39
+ onPress={() => setSelectedLog(item)}>
40
+ <View style={styles.logItemContainer}>
41
+ <View
42
+ style={[styles.statusIndicator, { backgroundColor: statusColor }]}
43
+ />
44
+
45
+ <View style={styles.logContent}>
46
+ <View style={styles.methodRow}>
47
+ <Text style={[styles.method, { color: methodColor }]}>
48
+ {(item.request?.method || 'GET').toUpperCase()}
49
+ </Text>
50
+ <Text style={[styles.status, { color: statusColor }]}>
51
+ {item.response?.status || 'Error'}
52
+ </Text>
53
+ </View>
54
+
55
+ <Text
56
+ style={[styles.url, !isSuccess && styles.failedUrl]}
57
+ numberOfLines={2}>
58
+ {item.request?.url}
59
+ </Text>
60
+
61
+ <View style={styles.logFooter}>
62
+ <Text style={styles.time}>
63
+ {item.timestamp
64
+ ? new Date(item.timestamp).toLocaleTimeString()
65
+ : ''}
66
+ </Text>
67
+ {!isSuccess && item.response?.data && (
68
+ <Text style={styles.errorMessage} numberOfLines={1}>
69
+ {item.response.data.message || 'Request Failed'}
70
+ </Text>
71
+ )}
72
+ </View>
73
+ </View>
74
+ </View>
75
+ </TouchableOpacity>
76
+ )
77
+ }
78
+
79
+ return (
80
+ <View style={styles.container}>
81
+ {logs.length === 0 ? (
82
+ <Text style={styles.emptyText}>No HTTP requests logged yet</Text>
83
+ ) : (
84
+ <FlatList
85
+ data={[...logs].sort((a, b) => b.timestamp - a.timestamp)}
86
+ renderItem={renderLogItem}
87
+ keyExtractor={(item, index) => index.toString()}
88
+ style={styles.list}
89
+ />
90
+ )}
91
+
92
+ <Modal
93
+ visible={!!selectedLog}
94
+ animationType='slide'
95
+ transparent={true}
96
+ onRequestClose={() => setSelectedLog(null)}>
97
+ {selectedLog && (
98
+ <TouchableOpacity
99
+ style={styles.modalContainer}
100
+ activeOpacity={1}
101
+ onPress={() => setSelectedLog(null)}>
102
+ <TouchableOpacity
103
+ style={styles.modalContent}
104
+ activeOpacity={1}
105
+ onPress={(e) => e.stopPropagation()}>
106
+ <View style={styles.modalHeader}>
107
+ <View style={styles.modalHeaderContent}>
108
+ <View style={styles.modalMethodStatus}>
109
+ <Text
110
+ style={[
111
+ styles.modalMethod,
112
+ { color: getMethodColor(selectedLog.request?.method) },
113
+ ]}>
114
+ {(selectedLog.request?.method || 'GET').toUpperCase()}
115
+ </Text>
116
+ <Text
117
+ style={[
118
+ styles.modalStatus,
119
+ {
120
+ color:
121
+ selectedLog.response?.status >= 400
122
+ ? '#ff4444'
123
+ : '#00C851',
124
+ },
125
+ ]}>
126
+ {selectedLog.response?.status || 'Error'}
127
+ </Text>
128
+ </View>
129
+ </View>
130
+ <TouchableOpacity
131
+ style={styles.closeButton}
132
+ onPress={() => setSelectedLog(null)}>
133
+ <Text style={styles.closeButtonText}>×</Text>
134
+ </TouchableOpacity>
135
+ </View>
136
+ <HttpLogDetails log={selectedLog} />
137
+ </TouchableOpacity>
138
+ </TouchableOpacity>
139
+ )}
140
+ </Modal>
141
+ </View>
142
+ )
143
+ }
144
+
145
+ const styles = StyleSheet.create({
146
+ container: {
147
+ flex: 1,
148
+ backgroundColor: '#fff',
149
+ },
150
+ list: {
151
+ flex: 1,
152
+ },
153
+ emptyText: {
154
+ textAlign: 'center',
155
+ color: '#999',
156
+ marginTop: 20,
157
+ },
158
+ logItem: {
159
+ borderBottomWidth: 1,
160
+ borderBottomColor: '#eee',
161
+ },
162
+ logItemContainer: {
163
+ flexDirection: 'row',
164
+ padding: 12,
165
+ },
166
+ statusIndicator: {
167
+ width: 4,
168
+ borderRadius: 2,
169
+ marginRight: 12,
170
+ },
171
+ logContent: {
172
+ flex: 1,
173
+ },
174
+ methodRow: {
175
+ flexDirection: 'row',
176
+ alignItems: 'center',
177
+ marginBottom: 6,
178
+ },
179
+ method: {
180
+ fontSize: 15,
181
+ fontWeight: 'bold',
182
+ marginRight: 8,
183
+ },
184
+ status: {
185
+ fontSize: 13,
186
+ fontWeight: '600',
187
+ },
188
+ url: {
189
+ fontSize: 13,
190
+ color: '#333',
191
+ marginBottom: 6,
192
+ lineHeight: 18,
193
+ },
194
+ failedUrl: {
195
+ color: '#ff4444',
196
+ },
197
+ logFooter: {
198
+ flexDirection: 'row',
199
+ justifyContent: 'space-between',
200
+ },
201
+ time: {
202
+ fontSize: 12,
203
+ color: '#999',
204
+ },
205
+ duration: {
206
+ fontSize: 12,
207
+ color: '#999',
208
+ },
209
+ errorMessage: {
210
+ color: '#ff4444',
211
+ fontSize: 12,
212
+ marginLeft: 8,
213
+ },
214
+ modalContainer: {
215
+ flex: 1,
216
+ backgroundColor: 'rgba(0,0,0,0.5)',
217
+ justifyContent: 'center',
218
+ alignItems: 'center',
219
+ },
220
+ modalContent: {
221
+ width: '90%',
222
+ height: '80%',
223
+ backgroundColor: '#fff',
224
+ borderRadius: 10,
225
+ overflow: 'hidden',
226
+ },
227
+ modalHeader: {
228
+ flexDirection: 'row',
229
+ alignItems: 'center',
230
+ padding: 15,
231
+ borderBottomWidth: 1,
232
+ borderBottomColor: '#eee',
233
+ backgroundColor: '#f8f9fa',
234
+ },
235
+ modalHeaderContent: {
236
+ flex: 1,
237
+ marginRight: 10,
238
+ },
239
+ modalMethodStatus: {
240
+ flexDirection: 'row',
241
+ alignItems: 'center',
242
+ },
243
+ modalMethod: {
244
+ fontSize: 16,
245
+ fontWeight: 'bold',
246
+ marginRight: 10,
247
+ },
248
+ modalStatus: {
249
+ fontSize: 14,
250
+ fontWeight: '600',
251
+ },
252
+ closeButton: {
253
+ width: 30,
254
+ height: 30,
255
+ alignItems: 'center',
256
+ justifyContent: 'center',
257
+ borderRadius: 15,
258
+ backgroundColor: '#eee',
259
+ },
260
+ closeButtonText: {
261
+ fontSize: 20,
262
+ color: '#666',
263
+ lineHeight: 20,
264
+ },
265
+ })
266
+
267
+ export default SubViewHTTPLogs
@@ -0,0 +1,66 @@
1
+ import React from 'react'
2
+ import {
3
+ View,
4
+ Text,
5
+ TouchableOpacity,
6
+ StyleSheet,
7
+ Animated,
8
+ } from 'react-native'
9
+ import { DebugColors } from '../utils/DebugConst'
10
+
11
+ const TabView = ({ tabs, activeTab, onTabChange, children }) => {
12
+ return (
13
+ <View style={styles.container}>
14
+ <View style={styles.tabBar}>
15
+ {tabs.map((tab, index) => (
16
+ <TouchableOpacity
17
+ key={index}
18
+ style={[styles.tab, activeTab === index && styles.activeTab]}
19
+ onPress={() => onTabChange(index)}>
20
+ <Text
21
+ style={[
22
+ styles.tabText,
23
+ activeTab === index && styles.activeTabText,
24
+ ]}>
25
+ {tab.label}
26
+ </Text>
27
+ </TouchableOpacity>
28
+ ))}
29
+ </View>
30
+ <View style={styles.content}>{children}</View>
31
+ </View>
32
+ )
33
+ }
34
+
35
+ const styles = StyleSheet.create({
36
+ container: {
37
+ flex: 1,
38
+ },
39
+ tabBar: {
40
+ flexDirection: 'row',
41
+ borderBottomWidth: 1,
42
+ borderBottomColor: DebugColors.border,
43
+ backgroundColor: DebugColors.background,
44
+ },
45
+ tab: {
46
+ flex: 1,
47
+ paddingVertical: 12,
48
+ alignItems: 'center',
49
+ },
50
+ activeTab: {
51
+ borderBottomWidth: 2,
52
+ borderBottomColor: DebugColors.blue,
53
+ },
54
+ tabText: {
55
+ color: DebugColors.textLight,
56
+ fontWeight: '500',
57
+ },
58
+ activeTabText: {
59
+ color: DebugColors.blue,
60
+ },
61
+ content: {
62
+ flex: 1,
63
+ },
64
+ })
65
+
66
+ export default TabView
package/package.json ADDED
@@ -0,0 +1,39 @@
1
+ {
2
+ "name": "react-native-debug-toolkit",
3
+ "version": "0.1.1",
4
+ "description": "A simple yet powerful debugging toolkit for React Native with a convenient floating UI for development",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "test": "echo \"Error: no test specified\" && exit 1",
9
+ "bundle": "react-native bundle --platform ios --dev false --entry-file index.js --bundle-output dist/main.jsbundle --assets-dest dist"
10
+ },
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "git+https://gitlab.outer.staruniongame.com/seaart-app-front/react-native-debug-toolkit.git"
14
+ },
15
+ "keywords": [
16
+ "react-native",
17
+ "debug",
18
+ "toolkit",
19
+ "logging",
20
+ "development-tools",
21
+ "floating-ui"
22
+ ],
23
+ "author": "zcj",
24
+ "license": "MIT",
25
+ "dependencies": {
26
+ "react-native-root-siblings": "^4.0.0"
27
+ },
28
+ "peerDependencies": {
29
+ "react": "*",
30
+ "react-native": "*"
31
+ },
32
+ "devDependencies": {
33
+ "@types/react": "^18.0.0",
34
+ "@types/react-native": "^0.70.0"
35
+ },
36
+ "jest": {
37
+ "preset": "react-native"
38
+ }
39
+ }