|
1 | | -import ScrollView from '@components/ScrollView'; |
2 | | - |
3 | 1 | import useThemeStyles from '@hooks/useThemeStyles'; |
4 | 2 |
|
| 3 | +import variables from '@styles/variables'; |
| 4 | + |
5 | 5 | import type {CustomRendererProps, TBlock, TNode} from 'react-native-render-html'; |
6 | 6 |
|
7 | 7 | import {useContext, useMemo} from 'react'; |
8 | 8 | import {View} from 'react-native'; |
| 9 | +import {ScrollView} from 'react-native-gesture-handler'; |
9 | 10 | import {useContentWidth} from 'react-native-render-html'; |
10 | 11 |
|
11 | 12 | import type {CellHorizontalAlignment} from './TableColumnAlignmentContext'; |
@@ -39,18 +40,20 @@ function TableRenderer({tnode}: CustomRendererProps<TBlock>) { |
39 | 40 | // outside a comment. A concrete number is required because a percentage does not resolve inside a horizontal ScrollView. |
40 | 41 | const measuredContentWidth = useContext(TableContentWidthContext); |
41 | 42 | const fallbackContentWidth = useContentWidth(); |
42 | | - const minWidth = measuredContentWidth || fallbackContentWidth; |
| 43 | + const viewportWidth = measuredContentWidth || fallbackContentWidth; |
| 44 | + const columnsWidth = columnAlignments.length * variables.htmlTableColumnMaxWidth + 2 * variables.tableRowPaddingHorizontal; |
| 45 | + const contentWidth = Math.max(viewportWidth, columnsWidth); |
43 | 46 |
|
44 | 47 | return ( |
45 | 48 | <TableColumnAlignmentContext.Provider value={columnAlignments}> |
46 | 49 | <ScrollView |
47 | 50 | horizontal |
| 51 | + shouldActivateOnStart |
48 | 52 | showsHorizontalScrollIndicator={false} |
49 | | - style={styles.w100} |
50 | | - contentContainerStyle={styles.htmlTableScrollContainerContent} |
| 53 | + style={{width: viewportWidth}} |
| 54 | + contentContainerStyle={{width: contentWidth}} |
51 | 55 | > |
52 | | - {/* The width makes the table fill the available message width; it still grows wider and scrolls horizontally when the columns need more room than that. */} |
53 | | - <View style={[styles.htmlTable, {minWidth}]}> |
| 56 | + <View style={styles.htmlTable}> |
54 | 57 | <TableChildrenRenderer tnode={tnode} /> |
55 | 58 | </View> |
56 | 59 | </ScrollView> |
|
0 commit comments