Skip to content

Commit 9d7c10f

Browse files
committed
remove border bottom of the last table item
1 parent c38f84d commit 9d7c10f

3 files changed

Lines changed: 22 additions & 3 deletions

File tree

src/components/HTMLEngineProvider/HTMLRenderers/TableRowRenderer.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,24 @@
11
import React from 'react';
22
import {View} from 'react-native';
3-
import type {CustomRendererProps, TBlock} from 'react-native-render-html';
3+
import type {CustomRendererProps, TBlock, TNode} from 'react-native-render-html';
44
import {TNodeRenderer} from 'react-native-render-html';
55
import useThemeStyles from '@hooks/useThemeStyles';
66

7+
function getElementChildren(node: TNode | null | undefined): TNode[] {
8+
return node?.children?.filter((child) => !!child.tagName) ?? [];
9+
}
10+
11+
function isLastRowOfTable(tnode: TNode): boolean {
12+
const section = tnode.parent;
13+
const table = section?.parent;
14+
if (!section || !table) {
15+
return false;
16+
}
17+
const sectionRows = getElementChildren(section);
18+
const tableSections = getElementChildren(table);
19+
return sectionRows[sectionRows.length - 1] === tnode && tableSections[tableSections.length - 1] === section;
20+
}
21+
722
function TableRowRenderer({tnode}: CustomRendererProps<TBlock>) {
823
const styles = useThemeStyles();
924

@@ -14,7 +29,7 @@ function TableRowRenderer({tnode}: CustomRendererProps<TBlock>) {
1429
const cells = tnode.children.filter((child) => !!child.tagName);
1530

1631
return (
17-
<View style={isHeaderRow ? styles.htmlTableHeaderRow : styles.htmlTableRow}>
32+
<View style={[isHeaderRow ? styles.htmlTableHeaderRow : styles.htmlTableRow, isLastRowOfTable(tnode) && styles.htmlTableLastRow]}>
1833
{cells.map((child, index) => {
1934
const key = `${child.tagName ?? 'node'}-${index}`;
2035
return (

src/styles/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,6 +2686,10 @@ const staticStyles = (theme: ThemeColors) =>
26862686
borderColor: theme.border,
26872687
},
26882688

2689+
htmlTableLastRow: {
2690+
borderBottomWidth: 0,
2691+
},
2692+
26892693
htmlTableCell: {
26902694
flex: 1,
26912695
minWidth: variables.htmlTableColumnMinWidth,

src/styles/variables.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ export default {
132132
tableRowPaddingVertical: 8,
133133
tableRowPaddingHorizontal: 12,
134134
htmlTableRowMinHeight: 40,
135-
htmlTableColumnMinWidth: 80,
135+
htmlTableColumnMinWidth: 120,
136136
tableGroupRowPaddingVertical: 4,
137137
tableGroupRowHeight: 36,
138138
tableCheckboxColumnWidth: 20,

0 commit comments

Comments
 (0)