Skip to content

Ability to invoke recalculation of a user provided function used to calculate the dynamic item row height #1891

Description

@mlc-mlapis

Problem Solved By The Feature

If the items' content is dynamically modified (by a user action) or the row width is affected (by a viewport resize), the shown content of one row can overwrite the content of the following row (when an item's content is increasing or a row's width is decreasing), or a space below the row can be added (when an item's content is decreasing or a row's width is increasing).

The typical case when it happens:

<rx-virtual-scroll-viewport [dynamic]="dynamicSize">
  <div *rxVirtualFor="let item of items$; trackBy: 'id'">
    <span>{{ (showTimestamps ? '' : (item.timestamp + separator)) + item.content }}</span>
  </div>
</rx-virtual-scroll-viewport>

dynamicSize is a reference to the function:

dynamicSize = (item: Log) => {
  const letterWidth = 7.26; // a monospaced font is used
  const rowSize = 22;
  const totalWidthRequiredBase = ((this.showTimestamps ? '' : (item.timestamp + this.separator)) + item.content).length * letterWidth;
  const rows = Math.ceil(totalWidthRequiredBase / this.viewportWidth);
  return Math.max(rows, 1) * rowSize;
};

where showTimestamps and viewportWidth are class variables through which the calculation can be affected from the user side.

Solution

Adding a new input to the <rx-virtual-scroll-viewport> component (or any equivalent control) that would invoke internal recalculation of the dynamicSize function in moments when a user changes the showTimestamps variable or when the viewportWidth value is changed by resizing the viewport width.

Additional Context

Actually, the dynamicSize function is invoked only when the source items$ array is being changed (some items are added or deleted).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

</> Template@rx-angular/template related

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions