Skip to content

Commit

Permalink
Added Grid Component
Browse files Browse the repository at this point in the history
  • Loading branch information
binoy14 committed Dec 27, 2016
1 parent 4a73fdf commit 93cfa62
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/grid/Col.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { PropTypes } from "react";
import { View } from "react-native";

const Col = (props) => {
const {style, size, width} = props;

const styles = {
flex: (size) ? size : (style && style.width) ? 0 : 1,
flexDirection: 'column',
...style,
};

return (
<View
{...styles}
{...props}
>
{props.children}
</View>
);
};

Col.propTypes = {
size: PropTypes.number,
style: PropTypes.object,
};

export default Col;
46 changes: 46 additions & 0 deletions src/grid/Grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import React, { Component, PropTypes } from 'react';
import { View } from 'react-native';
import Row from "./Row";

class Grid extends Component {
styles;

static propTypes = {
style: PropTypes.object,
}

isRow() {
let isRow = false;
React.Children.forEach(this.props.children, (child) => {
if (child.type === Row) {
console.log('here')
isRow = true;
}
});

return isRow;
}

componentWillMount() {
const {style} = this.props;

this.styles = {
flex: 1,
flexDirection: this.isRow() ? 'column' : 'row',
...style,
};
}

render() {
return (
<View
{...this.styles}
{...this.props}
>
{this.props.children}
</View>
);
}
}

export default Grid;
28 changes: 28 additions & 0 deletions src/grid/Row.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React, { PropTypes } from "react";
import { View } from "react-native";

const Row = (props) => {
const {style, size} = props;

const styles = {
flex: (size) ? size : (style && style.height) ? 0 : 1,
flexDirection: 'row',
...style,
};

return (
<View
{...styles}
{...props}
>
{props.children}
</View>
);
};

Row.propTypes = {
size: PropTypes.number,
style: PropTypes.object,
};

export default Row;
6 changes: 6 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import Tab from './tabs/Tab'
import colors from './config/colors'
import getIconType from './helpers/getIconType'
import normalize from './helpers/normalizeText'
import Grid from "./grid/Grid"
import Row from "./grid/Row"
import Col from "./grid/Col"

const Elements = {
Button,
Expand All @@ -40,6 +43,9 @@ const Elements = {
colors,
getIconType,
normalize,
Grid,
Row,
Col,
}

module.exports = Elements

0 comments on commit 93cfa62

Please sign in to comment.