Skip to content

Commit 3d6ff7c

Browse files
committed
fix native scroll
1 parent 552b0f3 commit 3d6ff7c

2 files changed

Lines changed: 17 additions & 12 deletions

File tree

src/components/HTMLEngineProvider/HTMLRenderers/TableRenderer.tsx

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import ScrollView from '@components/ScrollView';
2-
31
import useThemeStyles from '@hooks/useThemeStyles';
42

3+
import variables from '@styles/variables';
4+
55
import type {CustomRendererProps, TBlock, TNode} from 'react-native-render-html';
66

77
import {useContext, useMemo} from 'react';
88
import {View} from 'react-native';
9+
import {ScrollView} from 'react-native-gesture-handler';
910
import {useContentWidth} from 'react-native-render-html';
1011

1112
import type {CellHorizontalAlignment} from './TableColumnAlignmentContext';
@@ -39,18 +40,20 @@ function TableRenderer({tnode}: CustomRendererProps<TBlock>) {
3940
// outside a comment. A concrete number is required because a percentage does not resolve inside a horizontal ScrollView.
4041
const measuredContentWidth = useContext(TableContentWidthContext);
4142
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);
4346

4447
return (
4548
<TableColumnAlignmentContext.Provider value={columnAlignments}>
4649
<ScrollView
4750
horizontal
51+
shouldActivateOnStart
4852
showsHorizontalScrollIndicator={false}
49-
style={styles.w100}
50-
contentContainerStyle={styles.htmlTableScrollContainerContent}
53+
style={{width: viewportWidth}}
54+
contentContainerStyle={{width: contentWidth}}
5155
>
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}>
5457
<TableChildrenRenderer tnode={tnode} />
5558
</View>
5659
</ScrollView>

src/styles/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2696,10 +2696,6 @@ const staticStyles = (theme: ThemeColors) =>
26962696
minHeight: variables.tableHeaderContentHeight,
26972697
},
26982698

2699-
htmlTableScrollContainerContent: {
2700-
flexGrow: 1,
2701-
},
2702-
27032699
htmlTable: {
27042700
marginVertical: 8,
27052701
borderRadius: variables.componentBorderRadius,
@@ -2730,7 +2726,13 @@ const staticStyles = (theme: ThemeColors) =>
27302726
},
27312727

27322728
htmlTableCell: {
2733-
flex: 1,
2729+
// A definite flexBasis (not flex: 1 / basis 0) keeps columns aligned across rows inside the horizontal
2730+
// ScrollView, where the indefinite main-axis width otherwise collapses each cell to its content width.
2731+
// flexShrink: 0 stops columns from shrinking to fit the viewport, so a wide table overflows and can be
2732+
// scrolled horizontally; flexGrow: 1 still lets columns expand to fill the message width when it is wider.
2733+
flexGrow: 1,
2734+
flexShrink: 0,
2735+
flexBasis: variables.htmlTableColumnMaxWidth,
27342736
minWidth: variables.htmlTableColumnMinWidth,
27352737
paddingEnd: 8,
27362738
},

0 commit comments

Comments
 (0)