Skip to content
Open
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
63 changes: 32 additions & 31 deletions packages/happy-app/sources/components/markdown/MarkdownView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,9 +286,9 @@ function RenderSpans(props: RenderSpanProps) {
</>)
}

// Table rendering uses column-first layout to ensure consistent column widths.
// Each column is rendered as a vertical container with all its cells (header + data).
// This ensures that cells in the same column have the same width, determined by the widest content.
// Table rendering uses row-first layout to ensure consistent row heights.
// Each row is rendered as a horizontal container with all its cells.
// This ensures that cells in the same row have the same height.
function RenderTableBlock(props: {
headers: MarkdownSpan[][],
rows: MarkdownSpan[][][],
Expand All @@ -310,26 +310,30 @@ function RenderTableBlock(props: {
style={style.tableScrollView}
>
<View style={style.tableContent}>
{/* Render each column as a vertical container */}
{props.headers.map((header, colIndex) => (
<View
key={`column-${colIndex}`}
style={[
style.tableColumn,
colIndex === columnCount - 1 && style.tableColumnLast
]}
>
{/* Header cell for this column */}
<View style={[style.tableCell, style.tableHeaderCell, style.tableCellFirst]}>
{/* Header row */}
<View style={style.tableRow}>
{props.headers.map((header, colIndex) => (
<View
key={`header-${colIndex}`}
style={[
style.tableCell,
style.tableHeaderCell,
colIndex < columnCount - 1 && style.tableCellBorderRight,
]}
>
<Text style={style.tableHeaderText}><RenderSpans spans={header} baseStyle={style.tableHeaderText} onLinkPress={props.onLinkPress} selectable={props.selectable} /></Text>
</View>
{/* Data cells for this column */}
{props.rows.map((row, rowIndex) => (
))}
</View>
{/* Data rows */}
{props.rows.map((row, rowIndex) => (
<View key={`row-${rowIndex}`} style={[style.tableRow, isLastRow(rowIndex) && style.tableRowLast]}>
{props.headers.map((_, colIndex) => (
<View
key={`cell-${rowIndex}-${colIndex}`}
style={[
style.tableCell,
isLastRow(rowIndex) && style.tableCellLast
colIndex < columnCount - 1 && style.tableCellBorderRight,
]}
>
<Text style={style.tableCellText}><RenderSpans spans={row[colIndex] ?? []} baseStyle={style.tableCellText} onLinkPress={props.onLinkPress} selectable={props.selectable} /></Text>
Expand Down Expand Up @@ -591,28 +595,25 @@ const style = StyleSheet.create((theme) => ({
flexGrow: 0,
},
tableContent: {
flexDirection: 'row',
},
tableColumn: {
flexDirection: 'column',
borderRightWidth: 1,
borderRightColor: theme.colors.divider,
},
tableColumnLast: {
borderRightWidth: 0,
tableRow: {
flexDirection: 'row',
borderBottomWidth: 1,
borderBottomColor: theme.colors.divider,
},
tableRowLast: {
borderBottomWidth: 0,
},
tableCell: {
flex: 1,
paddingHorizontal: 12,
paddingVertical: 8,
borderBottomWidth: 1,
borderBottomColor: theme.colors.divider,
alignItems: 'flex-start',
},
tableCellFirst: {
borderTopWidth: 0,
},
tableCellLast: {
borderBottomWidth: 0,
tableCellBorderRight: {
borderRightWidth: 1,
borderRightColor: theme.colors.divider,
},
tableHeaderCell: {
backgroundColor: theme.colors.surfaceHigh,
Expand Down