Repository navigation
[Resizable columns] Absorb resize width in trailing columns #103186
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
JS00001
merged 20 commits into
Expensify:main
from
software-mansion-labs:war-in/resizable-table-columns-automatic-widths-on-right
Oct 20, 2026
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
9b7bcff
refactor: replace `resizableColumnKeys` with `resizableColumns` and i…
war-in a61f9e1
Merge branch 'war-in/resizable-table-columns-basics' into war-in/resi…
war-in acc0dd1
fix: make the last column shrink when dragging the previous column
war-in 73b9476
fix: rename and clean up code
war-in 0dc7ea6
refactor: simplify column resizing logic by replacing `resizableColum…
war-in 0017576
Merge remote-tracking branch 'upstream/main' into war-in/resizable-ta…
war-in fdcbd4a
Merge branch 'main' into war-in/resizable-table-columns-automatic-wid…
war-in 0a32b50
fix: drop the "not stored" check to fix UI jump
war-in 3f288cc
Merge branch 'main' into war-in/resizable-table-columns-automatic-wid…
war-in 93d2583
fix: respect maximum widths when growing absorbers
war-in cd3625d
fix: keep user-sized columns fixed and absorb drags in unset columns …
war-in dd5f3c5
fix: keep layout stable between drags and refreshes
war-in acc96cb
Merge branch 'main' into war-in/resizable-table-columns-automatic-wid…
war-in 5d98846
test: add user-resized columns test case
war-in c2d7f93
refactor: freeze layout after the first drag
war-in 6aee9ea
test: improve tests
war-in eb2a912
test: improve tests
war-in 10011cd
Merge branch 'refs/heads/main' into war-in/resizable-table-columns-au…
war-in 6aa43de
chore: remove unused export
war-in 6cfb222
fix: let a drag use the leftover room a fixed-width last column fills
war-in File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 0 additions & 70 deletions
70
src/components/Table/columnResize/applyColumnWidthOverrides.ts
This file was deleted.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
src/components/Table/columnResize/getAbsorbedColumnWidths.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** Splits a column's resize among the columns to its right, so the row keeps its width instead of overflowing. */ | ||
| import CONST from '@src/CONST'; | ||
|
|
||
| const {MIN_WIDTH} = CONST.TABLES.COLUMN_RESIZE; | ||
|
|
||
| /** A later column that absorbs another column's resize. */ | ||
| type ColumnAbsorber = { | ||
| columnKey: string; | ||
|
|
||
| /** The layout's minimum, so a drag and a reload land on the same widths. */ | ||
| minWidth: number; | ||
|
|
||
| /** Widest it may grow to, so a column meant to truncate long values never takes another column's freed width past its cap. */ | ||
| maxWidth: number; | ||
| }; | ||
|
|
||
| /** | ||
| * Splits a resize delta equally among the absorbers. An absorber that runs out of room between its minimum and maximum | ||
| * stops absorbing and its share moves to the rest. Whatever none of them can absorb is left over, so the row overflows | ||
| * and scrolls, or falls short and the growable column fills the gap. Shares are whole px and sum exactly. Absorbers without a start width are skipped. Returns each absorber's new width by column key. | ||
| */ | ||
| function getAbsorbedColumnWidths(absorbers: ColumnAbsorber[], startWidths: Record<string, number>, delta: number): Record<string, number> { | ||
| const absorbersWithRoom = absorbers.flatMap(({columnKey, minWidth, maxWidth}) => { | ||
| const startWidth = startWidths[columnKey]; | ||
|
|
||
| if (startWidth === undefined) { | ||
| return []; | ||
| } | ||
|
|
||
| const roundedStartWidth = Math.round(startWidth); | ||
|
|
||
| // How far it can move in the delta's direction: shrinking down to its minimum, or growing up to its maximum. | ||
| const room = delta > 0 ? Math.max(roundedStartWidth - Math.max(Math.round(minWidth), MIN_WIDTH), 0) : Math.max(Math.round(maxWidth) - roundedStartWidth, 0); | ||
|
|
||
| return [{columnKey, startWidth: roundedStartWidth, room}]; | ||
| }); | ||
|
|
||
| // Settled from the least room up, so an absorber hitting its minimum leaves its unabsorbed share to the rest. Stable, so ties keep render order. | ||
| const settleOrder = absorbersWithRoom.toSorted((first, second) => first.room - second.room); | ||
| const absorbedWidths: Record<string, number> = {}; | ||
| let remainingDelta = Math.round(delta); | ||
|
|
||
| for (const [position, absorber] of settleOrder.entries()) { | ||
| const equalShare = Math.round(remainingDelta / (settleOrder.length - position)); | ||
| const share = Math.max(Math.min(equalShare, absorber.room), -absorber.room); | ||
|
|
||
| absorbedWidths[absorber.columnKey] = absorber.startWidth - share; | ||
| remainingDelta -= share; | ||
| } | ||
|
|
||
| return absorbedWidths; | ||
| } | ||
|
|
||
| export default getAbsorbedColumnWidths; | ||
| export type {ColumnAbsorber}; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| /** Sums a row's column widths, counting a column without a width as 0. */ | ||
| function getColumnsWidthSum(columns: Array<{key: string}>, columnWidths: Record<string, number>): number { | ||
| return columns.reduce((total, column) => total + (columnWidths[column.key] ?? 0), 0); | ||
| } | ||
|
|
||
| export default getColumnsWidthSum; |
50 changes: 50 additions & 0 deletions
50
src/components/Table/columnResize/getFrozenColumnWidths.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** Repaints a saved layout, with the columns the user never dragged absorbing room that changed since the save. */ | ||
| import type {StoredTableColumnWidths} from '@src/types/onyx/TableColumnWidths'; | ||
|
|
||
| import type {ResizableColumn} from './resolveDraggedColumnWidths'; | ||
|
|
||
| import getAbsorbedColumnWidths from './getAbsorbedColumnWidths'; | ||
| import getColumnsWidthSum from './getColumnsWidthSum'; | ||
| import {getAbsorbedDelta, getColumnAbsorbers} from './resolveDraggedColumnWidths'; | ||
|
|
||
| type GetFrozenColumnWidthsParams = { | ||
| /** Every column, in render order. A column added since the save starts at its content width. */ | ||
| columns: ResizableColumn[]; | ||
|
|
||
| storedTableColumnWidths: StoredTableColumnWidths; | ||
|
|
||
| /** Measured like the saved one, so they can be compared. */ | ||
| availableColumnsWidth: number; | ||
| }; | ||
|
|
||
| /** | ||
| * Room gained or lost since the save, from the table width or from added and hidden columns, first offsets the saved | ||
| * overflow or short row, like a drag does. The rest is split equally among the auto-sized columns. Widths are recomputed | ||
| * from the save every time, so resizing the window back restores them exactly. | ||
| */ | ||
| function getFrozenColumnWidths({ | ||
| columns, | ||
| storedTableColumnWidths: {availableColumnsWidth: savedAvailableColumnsWidth, columnWidths: savedColumnWidths, resizedColumnKeys}, | ||
| availableColumnsWidth, | ||
| }: GetFrozenColumnWidthsParams): Record<string, number> { | ||
| const baseColumnWidths: Record<string, number> = {}; | ||
|
|
||
| for (const column of columns) { | ||
| baseColumnWidths[column.key] = column.declaredWidth ?? savedColumnWidths[column.key] ?? Math.min(column.contentWidth, column.maxWidth); | ||
|
war-in marked this conversation as resolved.
Resolved
war-in marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| // Every saved column, hidden ones included, so a hidden column's width counts as freed room. | ||
| const savedColumnsWidth = Object.values(savedColumnWidths).reduce((total, width) => total + width, 0); | ||
| const extraRoom = availableColumnsWidth - savedAvailableColumnsWidth + savedColumnsWidth - getColumnsWidthSum(columns, baseColumnWidths); | ||
| const absorbers = getColumnAbsorbers( | ||
| columns.filter((column) => savedColumnWidths[column.key] !== undefined), | ||
| resizedColumnKeys, | ||
| ); | ||
|
|
||
| // Negated because a positive delta shrinks absorbers. | ||
| const absorbedDelta = getAbsorbedDelta(-extraRoom, savedColumnsWidth - savedAvailableColumnsWidth); | ||
|
|
||
| return {...baseColumnWidths, ...getAbsorbedColumnWidths(absorbers, baseColumnWidths, absorbedDelta)}; | ||
| } | ||
|
|
||
| export default getFrozenColumnWidths; | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.