/
index.jsx
140 lines (131 loc) · 3.41 KB
/
index.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import React from 'react';
import { ListView, StyleSheet, Text, View } from '@hippy/react';
import {
getArray,
getBoolean,
getMap,
getNum,
getObject,
getString,
getTurboConfig,
nativeWithPromise,
printTurboConfig,
} from './demoTurbo';
const turboStyles = StyleSheet.create({
container: {
flex: 1,
},
cellContentView: {
flexDirection: 'row',
justifyContent: 'space-between',
backgroundColor: '#ccc',
marginBottom: 1,
},
funcInfo: {
justifyContent: 'center',
paddingLeft: 15,
paddingRight: 15,
},
actionButton: {
backgroundColor: '#4c9afa',
color: '#fff',
height: 44,
lineHeight: 44,
textAlign: 'center',
width: 80,
borderRadius: 6,
},
resultView: {
backgroundColor: 'darkseagreen',
minHeight: 150,
padding: 15,
},
});
export default class TurboDemo extends React.Component {
constructor(props) {
super(props);
this.state = {
config: null,
result: '',
funList: [
'getString',
'getNum',
'getBoolean',
'getMap',
'getObject',
'getArray',
'nativeWithPromise',
'getTurboConfig',
'printTurboConfig',
'getInfo',
'setInfo',
],
};
this.onTurboFunc = this.onTurboFunc.bind(this);
this.getRenderRow = this.getRenderRow.bind(this);
this.getRowKey = this.getRowKey.bind(this);
}
async onTurboFunc(funcName) {
let result;
if (funcName === 'nativeWithPromise') {
result = await nativeWithPromise('aaa');
} else if (funcName === 'getTurboConfig') {
this.config = getTurboConfig();
result = '获取到config对象';
} else if (funcName === 'printTurboConfig') {
result = printTurboConfig(this.config || getTurboConfig());
} else if (funcName === 'getInfo') {
result = (this.config || getTurboConfig()).getInfo();
} else if (funcName === 'setInfo') {
(this.config || getTurboConfig()).setInfo('Hello World');
result = '设置config信息成功';
} else {
const basicFuncs = {
getString: () => getString('123'),
getNum: () => getNum(1024),
getBoolean: () => getBoolean(true),
getMap: () => getMap(new Map([['a', '1'], ['b', 2]])),
getObject: () => getObject({ c: '3', d: '4' }),
getArray: () => getArray(['a', 'b', 'c']),
};
result = basicFuncs[funcName]();
}
this.setState({ result });
}
renderResultView() {
return (
<View style={turboStyles.resultView}>
<Text style={{ backgroundColor: 'darkseagreen' }}>{`${this.state.result}`}</Text>
</View>
);
}
getRenderRow(index) {
const { funList } = this.state;
return (
<View style={turboStyles.cellContentView}>
<View style={turboStyles.funcInfo}>
<Text numberofLines={0}>函数名:{funList[index]}</Text>
</View>
<Text style={turboStyles.actionButton} onClick={() => this.onTurboFunc(funList[index])}>执行</Text>
</View>
);
}
getRowKey(index) {
const { funList } = this.state;
return funList[index];
}
render() {
const { funList } = this.state;
return (
<View style={turboStyles.container}>
{this.renderResultView()}
<ListView
numberOfRows={funList.length}
renderRow={this.getRenderRow}
getRowKey={this.getRowKey}
style={{ flex: 1 }}
/>
</View>
);
}
}