I want to achieve the following. I have a datastructure Table, which is basically a 2D array of Strings. I want to display them with the following constraints: Each column must be the width of the widest cell in that column, with a maximum of 300. If the text doesn't fit, the text should wrap. This is my best attempt:
ScrollView(.horizontal, showsIndicators: false) {
Grid(horizontalSpacing: 20, verticalSpacing: 10) {
ForEach(table.rows) { row in
GridRow {
ForEach(row.cells) { cell in
DocumentContentView(content: cell)
.frame(maxWidth: 300)
}
}
}
}
}
.scrollBounceBehavior(.basedOnSize, axes: .horizontal)
.scrollClipDisabled()
However, this truncates the text. If I remove the scrollview, it works as expected, but then the columns become way too narrow on iPhone. I want the table to be scrollable. Does anyone have an idea?