gonzalezreal / swift-markdown-ui

Display and customize Markdown text in SwiftUI
MIT License
2.53k stars 318 forks source link

Table height miscalculated #219

Closed FliiFe closed 1 year ago

FliiFe commented 1 year ago

Describe the bug In some cases, a table's height might not be correctly calculated, disturbing the surrounding elements

Checklist

Steps to reproduce I used the following table.

| Column 2 | Column 1 |
|----------|----------|
| Here's another example of a multiline text in column 2.\nI'm just adding more lines to make it longer. | This is a sample text.\nIt spans multiple lines. |
| And the content of the second column is here as well.\nI can add more lines if I want to, but I'll stop now. | The second row starts here. |
| This is a multiline text, just like the others. | Third row, first column's text. |
| Fourth row, second column. | Fourth row, first column. |
| Fifth row, second column. | Fifth row, first column. |
| Sixth row, second column. | Sixth row, first column. |
| Seventh row, second column. | Seventh row, first column. |
| Eighth row, second column. | Eighth row, first column. |
| Ninth row, second column. | Ninth row, first column. |
| Tenth row, second column. | Tenth row, first column. |

Adjust the window width: sometimes the height is correct, sometimes it is not.

Expected behavior The Markdown view extends to the full height of the table

Screenshots https://streamable.com/we218l

Look at the Divider view below the Markdown view. They are next to each other in a VStack.

Version information

gonzalezreal commented 1 year ago

Hi @FliiFe,

MarkdownUI uses SwiftUI's Grid to render tables:

https://github.com/gonzalezreal/swift-markdown-ui/blob/66dcceca0ffbb772eba5b4de19694f817820087d/Sources/MarkdownUI/Views/Blocks/TableView.swift#L16

The video shows that the Grid reports an incorrect height to the VStack when the parent view becomes too narrow. Have you tried to fix the height of the Markdown view to its ideal height?

Markdown {
  ...
}
.fixedSize(horizontal: false, vertical: true)
FliiFe commented 1 year ago

This seems to do the trick, thank you!

gonzalezreal commented 1 year ago

Hey @FliiFe,

The latest release includes the fixedSize modifier in all the bundled themes, so you shouldn't need to call it after upgrading.