This repository was archived by the owner on May 5, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 187
Expand file tree
/
Copy pathcols.js
More file actions
70 lines (63 loc) · 2.4 KB
/
cols.js
File metadata and controls
70 lines (63 loc) · 2.4 KB
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
import React, {Component} from "react";
import PropTypes from "prop-types";
import {View, StyleSheet} from "react-native";
import {Cell} from "./cell";
import {sum} from "../utils";
export class Col extends Component {
static propTypes = {
data: PropTypes.array,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
width: PropTypes.number,
heightArr: PropTypes.arrayOf(PropTypes.number),
flex: PropTypes.number,
textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
};
render() {
const {data, style, width, heightArr, flex, textStyle, ...props} = this.props;
return data ? (
<View style={[width ? {width: width} : {flex: 1}, flex && {flex: flex}, style]}>
{data.map((item, i) => {
const height = heightArr && heightArr[i];
return <Cell key={i} data={item} width={width} height={height} textStyle={textStyle} {...props} />;
})}
</View>
) : null;
}
}
export class Cols extends Component {
static propTypes = {
data: PropTypes.array,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
widthArr: PropTypes.arrayOf(PropTypes.number),
heightArr: PropTypes.arrayOf(PropTypes.number),
flexArr: PropTypes.arrayOf(PropTypes.number),
textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
};
render() {
const {data, style, widthArr, heightArr, flexArr, textStyle, ...props} = this.props;
const width = widthArr ? sum(widthArr) : 0;
return data ? (
<View style={[styles.cols, width && {width}]}>
{data.map((item, i) => {
const flex = flexArr && flexArr[i];
const wth = widthArr && widthArr[i];
return (
<Col
key={i}
data={item}
width={wth}
heightArr={heightArr}
flex={flex}
style={style}
textStyle={textStyle}
{...props}
/>
);
})}
</View>
) : null;
}
}
const styles = StyleSheet.create({
cols: {flexDirection: "row"}
});