-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSquare.js
60 lines (58 loc) · 1.55 KB
/
Square.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
51
52
53
54
55
56
57
58
59
60
import React, { PureComponent } from "react";
import { View } from "react-native";
import { styles } from "./SectionStyle";
import Constant from "./Constant";
import PropTypes from "prop-types";
export default class Square extends PureComponent {
render() {
const { fullScreenWidth, allowHeightExcess, backgroundColor } = this.props;
let xSquares = this.props.xSquares;
let ySquares = this.props.ySquares;
if (xSquares >= 10) {
xSquares = 9;
}
if (xSquares <= 0) {
xSquares = 1;
}
if (ySquares <= 0) {
ySquares = 1;
}
let dimensions = Constant.getSectionSize(xSquares, ySquares, fullScreenWidth);
const maxHeight = allowHeightExcess ? null : dimensions.height;
return (
<View
style={[
styles.secondaryContainer,
{
backgroundColor: backgroundColor,
margin: dimensions.margin,
minHeight: dimensions.height,
maxHeight: maxHeight,
width: dimensions.width
},
fullScreenWidth ? styles.fullScreenWidth : null,
{ ...this.props.style }
]}
>
{this.props.children}
</View>
);
}
}
Square.propTypes = {
xSquares: PropTypes.number,
ySquares: PropTypes.number,
backgroundColor: PropTypes.string,
allowHeightExcess: PropTypes.bool,
fullScreenWidth: PropTypes.bool,
style: PropTypes.oneOf(PropTypes.object, PropTypes.array, PropTypes.number),
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node])
};
Square.defaultProps = {
xSquares: 1,
ySquares: 1,
backgroundColor: "#D3D3D3",
allowHeightExcess: false,
fullScreenWidth: false,
style: null
};