Skip to content

Commit 1988532

Browse files
authored
Merge pull request #1 from itenl/dev-1.1.0
Dev 1.1.0
2 parents a0f4127 + 31129f3 commit 1988532

15 files changed

Lines changed: 499 additions & 268 deletions

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
# react-native-vdebug
22

3+
4+
[![NPM Version](http://img.shields.io/npm/v/react-native-vdebug.svg?style=flat)](https://www.npmjs.org/package/react-native-vdebug)
5+
[![NPM Downloads](https://img.shields.io/npm/dm/react-native-vdebug.svg?style=flat)](https://npmcharts.com/compare/react-native-vdebug?minimal=true)
6+
[![install size](https://packagephobia.now.sh/badge?p=react-native-vdebug)](https://packagephobia.now.sh/result?p=react-native-vdebug)
7+
8+
39
`React-Native 调试工具`
410

511
### 支持情况
612
- [x] Command 自定义上下文
713
- [x] 复制 cURL 至粘贴板
814
- [x] 重新请求 URL
915
- [x] 可视化 Response
16+
- [x] Log 等级分类
17+
- [x] 关键字过滤 Log / Network
1018
- [ ] Command 历史记录 (ing...)
11-
- [ ] Log 等级分类 (ing...)
12-
- [ ] 关键字过滤 Log / Network (ing...)
19+
- [ ] 导出所有 Log / Network (ing...)
1320

1421
## Install
1522

@@ -30,17 +37,17 @@ return <VDebug info={{ obj: 'your object' }} />
3037

3138
## Snapshot
3239

33-
<img src="./snapshot/z3mcx-duskg.gif" />
34-
35-
<img src="./snapshot/Snipaste_2020-10-07_18-14-33.png" />
36-
37-
<img src="./snapshot/Snipaste_2020-10-07_18-14-48.png" />
38-
39-
<img src="./snapshot/Snipaste_2020-10-07_18-15-06.png" />
40+
<img src="./snapshot/79tx5-qew2r.gif" />
41+
<br />
42+
<img src="./snapshot/abovz-11w3r.jpg" />
43+
<br />
44+
<img src="./snapshot/aka6s-nqpkq.jpg" />
45+
<br />
4046

4147
-------------------
4248

4349
`禁止商业用途 ❤ 研究学习范畴 ❤ 作者保留解释权`
50+
<br />
4451
Commercial use is forbidden and The author reserves the right of interpretion
4552

4653
[✶ MIT ✶](./LICENSE)

index.js

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,27 @@
11
import React, { PureComponent } from 'react';
22
import { ScrollView, View, Text, TouchableOpacity, PanResponder, Animated, Dimensions, StyleSheet, TextInput, Keyboard, NativeModules, Platform, KeyboardAvoidingView } from 'react-native';
33
import event from './src/event';
4-
import Network from './src/network';
5-
import Log from './src/console';
4+
import Network, { traceNetwork } from './src/network';
5+
import Log, { traceLog } from './src/log';
66
import Info from './src/info';
77
const { width, height } = Dimensions.get('window');
88

9-
let externalContext = {};
9+
let commandContext = global;
1010

11-
export const setExternalContext = context => {
12-
externalContext = context || {};
11+
export const setExternalContext = externalContext => {
12+
if (externalContext) commandContext = externalContext;
1313
};
1414

15-
function evalInContext(js, context) {
16-
return function (str) {
17-
let result = '';
18-
try {
19-
// eslint-disable-next-line no-eval
20-
result = eval(str);
21-
} catch (err) {
22-
result = 'Invalid input';
23-
}
24-
return event.trigger('addLog', result);
25-
}.call(context, `with(this) { ${js} } `);
26-
}
15+
// Log/network trace when Element is not initialized.
16+
export const initTrace = () => {
17+
traceLog();
18+
traceNetwork();
19+
};
2720

2821
class VDebug extends PureComponent {
2922
constructor(props) {
3023
super(props);
24+
initTrace();
3125
this.state = {
3226
commandValue: '',
3327
showPanel: false,
@@ -37,11 +31,11 @@ class VDebug extends PureComponent {
3731
panels: [
3832
{
3933
title: 'Log',
40-
component: Log
34+
component: <Log />
4135
},
4236
{
4337
title: 'Network',
44-
component: Network
38+
component: <Network />
4539
},
4640
{
4741
title: 'Info',
@@ -105,16 +99,28 @@ class VDebug extends PureComponent {
10599
NativeModules?.DevMenu?.reload();
106100
}
107101

108-
execCommand = () => {
102+
evalInContext(js, context) {
103+
return function (str) {
104+
let result = '';
105+
try {
106+
// eslint-disable-next-line no-eval
107+
result = eval(str);
108+
} catch (err) {
109+
result = 'Invalid input';
110+
}
111+
return event.trigger('addLog', result);
112+
}.call(context, `with(this) { ${js} } `);
113+
}
114+
115+
execCommand() {
109116
if (!this.state.commandValue) return;
110-
const context = externalContext;
111-
evalInContext(this.state.commandValue, context);
117+
this.evalInContext(this.state.commandValue, commandContext);
112118
Keyboard.dismiss();
113-
};
119+
}
114120

115-
clearCommand = () => {
121+
clearCommand() {
116122
this.textInput.clear();
117-
};
123+
}
118124

119125
scrollToPage(index, animated = true) {
120126
this.scrollToCard(index, animated);
@@ -156,14 +162,14 @@ class VDebug extends PureComponent {
156162
}}
157163
style={styles.commandBarInput}
158164
placeholderTextColor={'#000000a1'}
159-
placeholder="command..."
165+
placeholder="Command..."
160166
onChangeText={text => this.setState({ commandValue: text })}
161167
value={this.state.commandValue}
162168
/>
163-
<TouchableOpacity style={styles.commandBarBtn} onPress={() => this.clearCommand()}>
169+
<TouchableOpacity style={styles.commandBarBtn} onPress={this.clearCommand.bind(this)}>
164170
<Text>X</Text>
165171
</TouchableOpacity>
166-
<TouchableOpacity style={styles.commandBarBtn} onPress={() => this.execCommand()}>
172+
<TouchableOpacity style={styles.commandBarBtn} onPress={this.execCommand.bind(this)}>
167173
<Text>OK</Text>
168174
</TouchableOpacity>
169175
</View>
@@ -189,7 +195,7 @@ class VDebug extends PureComponent {
189195
}
190196

191197
onScrollAnimationEnd({ nativeEvent }) {
192-
const currentPageIndex = Math.floor(nativeEvent.contentOffset.x / width);
198+
const currentPageIndex = Math.floor(nativeEvent.contentOffset.x / Math.floor(width));
193199
currentPageIndex != this.state.currentPageIndex &&
194200
this.setState({
195201
currentPageIndex: currentPageIndex

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "react-native-vdebug",
3-
"version": "1.0.0",
4-
"description": "`React-Native 调试工具`",
3+
"version": "1.1.0",
4+
"description": "React-Native 调试工具",
55
"main": "index.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1"
88
},
99
"repository": {
1010
"type": "git",
11-
"url": "git+https://github.com/itenl/react-native-vdebug.git"
11+
"url": "https://github.com/itenl/react-native-vdebug.git"
1212
},
1313
"keywords": [
1414
"react-native",
@@ -20,5 +20,8 @@
2020
"bugs": {
2121
"url": "https://github.com/itenl/react-native-vdebug/issues"
2222
},
23+
"engines": {
24+
"node": ">=8.11.0"
25+
},
2326
"homepage": "https://github.com/itenl/react-native-vdebug#readme"
2427
}

snapshot/79tx5-qew2r.gif

1.33 MB
Loading
-54.5 KB
Binary file not shown.
-76.4 KB
Binary file not shown.
-63.8 KB
Binary file not shown.

snapshot/abovz-11w3r.jpg

27.2 KB
Loading

snapshot/aka6s-nqpkq.jpg

29.8 KB
Loading

snapshot/z3mcx-duskg.gif

-2.94 MB
Binary file not shown.

0 commit comments

Comments
 (0)