Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Put card list grid items in rows #122

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@protonapp/material-components",
"version": "0.9.42",
"version": "0.9.43",
"description": "Material UI Components for Proton",
"main": "index.js",
"scripts": {
Expand Down
45 changes: 37 additions & 8 deletions src/CardList/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,26 @@ export default class ImageList extends Component {
return columns
}

getRows(items) {
const columnCount = this.getColumnCount()
const count = Math.ceil(items.length / columnCount)
const rows = []

for (let i = 0; i < items.length; i += 1) {
const row = Math.floor(i / count)

if (!rows[row]) {
rows[row] = []
}

if (items[i]) {
rows[row].push(items[i])
}
}

return rows
}

renderCell = (itm, layout, editor, _fonts, width = null) => (
<Cell
{...itm}
Expand Down Expand Up @@ -96,14 +116,20 @@ export default class ImageList extends Component {
renderGrid(items) {
let { layout, columnCount, editor, _fonts } = this.props

let { fullWidth } = this.state
let width = fullWidth / columnCount - 8
const rows = this.getRows(items)
const cellContainerStyles = { width: `${100 / columnCount}%` }

return (
<View onLayout={this.handleLayout} style={styles.gridWrap}>
{items.map((itm, i) =>
this.renderCell(itm, layout, editor, _fonts, width)
)}
{rows.map((row, i) => (
<View key={i} style={styles.row}>
{row.map((itm, j) => (
<View style={cellContainerStyles} key={j}>
{this.renderCell(itm, layout, editor, _fonts)}
</View>
))}
</View>
))}
</View>
)
}
Expand Down Expand Up @@ -409,7 +435,6 @@ class Cell extends Component {
render() {
let {
onPress,
media,
button1,
button2,
icon1,
Expand All @@ -420,8 +445,6 @@ class Cell extends Component {
editor,
} = this.props

let mediaPosition = media && media.position
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image


let cell = [styles.cell, { width }]

let {
Expand Down Expand Up @@ -695,6 +718,12 @@ const styles = StyleSheet.create({
flexDirection: 'column',
flex: 1,
},
row: {
flexDirection: 'row',
flex: 1,
flexBasis: '100%',
alignItems: 'flex-start',
},
cell: {
marginLeft: 4,
marginRight: 4,
Expand Down