reactjs - Two column layout in react native -
i want display multiple elements in 2 columns in react native application. have far:
class app extends component { render() { const { viewstyle, childstyle } = style; return ( <view style={viewstyle}> <view style={childstyle} /> <view style={childstyle} /> <view style={childstyle} /> <view style={childstyle} /> <view style={childstyle} /> <view style={childstyle} /> <view style={childstyle} /> <view style={childstyle} /> <view style={childstyle} /> </view> ); } } const space = 5; const style = { viewstyle: { flex: 1, flexwrap: 'wrap', flexdirection: 'row', padding: space, margintop: 20, backgroundcolor: 'green' }, childstyle: { width: '50%', height: 100, backgroundcolor: 'red', borderwidth: 1, bordercolor: 'black', marginbottom: space } }
and here screenshot: https://imgur.com/a/wkgdr
my problem is: how can space in middle (between left , right elements)? , possible, works when user rotates device?
you have container flexdirection: 'row', such columns inside of this. have empty view inserted between columns:
const {width, height} = require('dimensions').get('window'); <view style={{flex: 1, flexdirection: 'row', width: width}}> <view style={[viewstyle, {flex: 5, flexdirection: 'column'}]> <view style={childstyle} /> <view style={childstyle} /> ... </view> <view style={{flex: 1}}> </view> <view style={[viewstyle, {flex: 5, flexdirection: 'column'}]> <view style={childstyle} /> <view style={childstyle} /> ... </view> </view>
difficult maintain fixed pixel dimension this, size on screen rotation. alternatively use padding in column views have space between them. disable screen orientation changes if wanted go far. hope helps!
Comments
Post a Comment