forked from react-native-elements/react-native-elements
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGrid.js
More file actions
66 lines (55 loc) · 1.22 KB
/
Grid.js
File metadata and controls
66 lines (55 loc) · 1.22 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
import React, { Component, PropTypes } from 'react';
import { View, TouchableOpacity } from 'react-native';
import Row from './Row';
class Grid extends Component {
styles;
static propTypes = {
style: PropTypes.object,
onPress: PropTypes.func,
activeOpacity: PropTypes.number,
}
static defaultProps = {
activeOpacity: 1,
}
isRow() {
let isRow = false;
React.Children.forEach(this.props.children, (child) => {
if (child.type === Row) {
isRow = true;
}
});
return isRow;
}
componentWillMount() {
const {style} = this.props;
this.styles = {
flex: 1,
flexDirection: this.isRow() ? 'column' : 'row',
...style,
};
}
render() {
const {onPress, activeOpacity} = this.props;
if (onPress) {
return (
<TouchableOpacity style={{flex: 1}} activeOpacity={activeOpacity} onPress={onPress}>
<View
{...this.styles}
{...this.props}
>
{this.props.children}
</View>
</TouchableOpacity>
);
}
return (
<View
{...this.styles}
{...this.props}
>
{this.props.children}
</View>
);
}
}
export default Grid;