Created
March 31, 2017 08:19
-
-
Save Emilios1995/b2dbfa736a6df16349e50b26c560d000 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react'; | |
import { Text, View, StyleSheet, Dimensions } from 'react-native'; | |
const { width } = Dimensions.get("window"); | |
export default class App extends Component { | |
render() { | |
const tileDimensions = calcTileDimensions(width, 2) // -> change this number and see! | |
const tiles = 'Lorem Ipsum Dolor Sit Amet'.split(' ') | |
return ( | |
<View style={styles.container}> | |
{tiles.map(i => Item({...tileDimensions, text: i}))} | |
</View> | |
); | |
} | |
} | |
const Item = ({size, margin, text}) => ( | |
<View style={[styles.item, {width: size, height: size, marginHorizontal: margin}]}> | |
<Text style={styles.itemText}>{text}</Text> | |
</View> | |
) | |
const calcTileDimensions = (deviceWidth, tpr) => { | |
const margin = deviceWidth / (tpr * 10); | |
const size = (deviceWidth - margin * (tpr * 2)) / tpr; | |
return { size, margin }; | |
}; | |
const styles = StyleSheet.create({ | |
container: { | |
justifyContent: "flex-start", flexDirection: "row", flexWrap: "wrap", marginTop: 30 | |
}, | |
item: { | |
backgroundColor: 'yellow', | |
alignSelf: "flex-start", | |
alignItems: 'center', | |
justifyContent: 'center', | |
marginBottom: 20 | |
}, | |
itemText: { | |
fontSize: 20 | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment