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 pathcell.js
More file actions
55 lines (50 loc) · 1.69 KB
/
cell.js
File metadata and controls
55 lines (50 loc) · 1.69 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
import React, {Component} from "react";
import PropTypes from "prop-types";
import {View, Text, StyleSheet} from "react-native";
export class Cell extends Component {
static propTypes = {
data: PropTypes.any,
width: PropTypes.number,
height: PropTypes.number,
flex: PropTypes.number,
style: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
textStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
borderStyle: PropTypes.object
};
render() {
const {data, width, height, flex, style, textStyle, borderStyle, ...props} = this.props;
const textDom = React.isValidElement(data) ? (
data
) : (
<Text style={[textStyle, styles.text]} {...props}>
{data}
</Text>
);
const borderTopWidth = (borderStyle && borderStyle.borderWidth) || 0;
const borderRightWidth = borderTopWidth;
const borderColor = (borderStyle && borderStyle.borderColor) || "#000";
return (
<View
style={[
{
borderTopWidth,
borderRightWidth,
borderColor
},
styles.cell,
width && {width},
height && {height},
flex && {flex},
!width && !flex && !height && !style && {flex: 1},
style
]}
>
{textDom}
</View>
);
}
}
const styles = StyleSheet.create({
cell: {justifyContent: "center"},
text: {backgroundColor: "transparent"}
});