Skip to content

Instantly share code, notes, and snippets.

@yudapc
Created May 22, 2018 02:14
Show Gist options
  • Save yudapc/12087affea2941dce630c833fbbcad16 to your computer and use it in GitHub Desktop.
Save yudapc/12087affea2941dce630c833fbbcad16 to your computer and use it in GitHub Desktop.
React Native
import React, { Component } from 'react';
import { ScrollView, View, Text, Dimensions } from 'react-native';
const widthLeftSide = 0.7; // 70%
const widthDevice = Dimensions.get('window').width * widthLeftSide;
const column = 3;
const padding = 16;
const totalPadding = padding * (column * 2);
const cardBoxWidth = (widthDevice - totalPadding) / column;
const customPaddingRight = 4 * 6.5;
const categories = [
{
id: 1,
name: 'Category 1'
},
{
id: 2,
name: 'Category 2'
},
{
id: 3,
name: 'Category 3'
},
{
id: 4,
name: 'Category 4'
},
{
id: 5,
name: 'Category 5'
},
{
id: 6,
name: 'Category 6'
},
{
id: 7,
name: 'Category 7'
},
{
id: 8,
name: 'Category 8'
}
];
export class Grid extends Component {
render() {
return (
<View
style={{
flex: 1,
flexDirection: 'row',
flexWrap: 'wrap',
justifyContent: 'flex-start',
paddingLeft: 16
}}
>
{categories.map((element, elementIndex) => {
return (
<View
key={element.id}
style={{
backgroundColor: '#fff',
paddingRight: customPaddingRight,
paddingVertical: 16
}}
>
<View
style={{
height: 330,
width: cardBoxWidth,
backgroundColor: 'rgba(0, 0, 0, 0.38)'
}}
>
<Text>{element.name}</Text>
</View>
</View>
);
})}
</View>
);
}
}
export default Grid;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment