-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
50 lines (46 loc) · 1.33 KB
/
index.js
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
/**
* Created by Orz on 2018/4/28.
*/
import React, { Component } from 'react'
import { ScrollView, View, Text, Dimensions } from 'react-native'
import Cell from './cell'
import style from './styles'
let {width} = Dimensions.get('window')
export default class Table extends Component {
constructor(props) {
super(props)
this.state = {
header: this.props.header?this.props.header:[],
body: this.props.body?this.props.body:[],
height: this.props.height?this.props.height:17,
width: this.props.width,
}
}
render() {
let header = this.state.header
let body = this.state.body
let len = this.state.width?this.state.width:Math.round(width / header.length)
let key = 0
let H = header.map((h) => {
return(<Cell key={key++} data={h} len={len} bold={true}/>)
})
let B = body.map((b) => {
let a = b.map((b) => {
return(<Cell key={key++} data={b} len={len}/>)
})
return(<View key={key++} style={[style.row, {height: this.state.height}]}>{a}</View>)
})
return(
<ScrollView>
<View style={style.col}>
<View style={[style.row, {height: this.state.height}]}>
{H.length>0?H:''}
</View>
<View style={style.col}>
{B.length>0?B:''}
</View>
</View>
</ScrollView>
)
}
}