fix(ui): virtual grid scroll restore (#948)
This commit is contained in:
@@ -307,7 +307,6 @@ export class BookBrowserComponent implements AfterViewInit {
|
|||||||
);
|
);
|
||||||
private readonly virtualGridGap = computed(() => this.isMobile() ? this.MOBILE_GAP : this.GRID_GAP);
|
private readonly virtualGridGap = computed(() => this.isMobile() ? this.MOBILE_GAP : this.GRID_GAP);
|
||||||
private readonly virtualGridColumns = computed(() => this.isMobile() ? this.mobileColumnCount() : undefined);
|
private readonly virtualGridColumns = computed(() => this.isMobile() ? this.mobileColumnCount() : undefined);
|
||||||
private readonly isGridView = computed(() => this.currentViewMode() === VIEW_MODES.GRID);
|
|
||||||
private readonly virtualBookCount = computed(() => {
|
private readonly virtualBookCount = computed(() => {
|
||||||
const renderedBookCount = this.gridBooks().length;
|
const renderedBookCount = this.gridBooks().length;
|
||||||
return this.appBooksApi.hasNextPage()
|
return this.appBooksApi.hasNextPage()
|
||||||
@@ -321,7 +320,6 @@ export class BookBrowserComponent implements AfterViewInit {
|
|||||||
gap: this.virtualGridGap,
|
gap: this.virtualGridGap,
|
||||||
columns: this.virtualGridColumns,
|
columns: this.virtualGridColumns,
|
||||||
count: this.virtualBookCount,
|
count: this.virtualBookCount,
|
||||||
enabled: this.isGridView,
|
|
||||||
initialOffset: this.initialScrollOffset,
|
initialOffset: this.initialScrollOffset,
|
||||||
fillItemWidth: true,
|
fillItemWidth: true,
|
||||||
estimateItemHeight: itemWidth => this.isMobile()
|
estimateItemHeight: itemWidth => this.isMobile()
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ export interface VirtualGridOptions {
|
|||||||
columns?: Signal<number | undefined>;
|
columns?: Signal<number | undefined>;
|
||||||
initialOffset?: () => number;
|
initialOffset?: () => number;
|
||||||
fillItemWidth?: boolean;
|
fillItemWidth?: boolean;
|
||||||
enabled?: Signal<boolean>;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function getScrollContentWidth(element: HTMLElement | null): number {
|
function getScrollContentWidth(element: HTMLElement | null): number {
|
||||||
@@ -94,7 +93,6 @@ export function createVirtualGrid(options: VirtualGridOptions) {
|
|||||||
return Math.max(options.minItemWidth(), (availableWidth - totalGap) / columns);
|
return Math.max(options.minItemWidth(), (availableWidth - totalGap) / columns);
|
||||||
});
|
});
|
||||||
const itemHeight = computed(() => options.estimateItemHeight(itemWidth()));
|
const itemHeight = computed(() => options.estimateItemHeight(itemWidth()));
|
||||||
const enabled = computed(() => !!options.scrollElement() && (options.enabled?.() ?? true));
|
|
||||||
const columnGap = computed(() => {
|
const columnGap = computed(() => {
|
||||||
if (options.fillItemWidth) {
|
if (options.fillItemWidth) {
|
||||||
return gap();
|
return gap();
|
||||||
@@ -116,7 +114,6 @@ export function createVirtualGrid(options: VirtualGridOptions) {
|
|||||||
overscan: toSafeInteger(options.overscan ?? gridColumns() * DEFAULT_OVERSCAN_ROWS, DEFAULT_OVERSCAN_ROWS),
|
overscan: toSafeInteger(options.overscan ?? gridColumns() * DEFAULT_OVERSCAN_ROWS, DEFAULT_OVERSCAN_ROWS),
|
||||||
gap: toSafeSize(columnGap(), DEFAULT_ITEM_SIZE),
|
gap: toSafeSize(columnGap(), DEFAULT_ITEM_SIZE),
|
||||||
lanes: toSafeInteger(gridColumns(), 1),
|
lanes: toSafeInteger(gridColumns(), 1),
|
||||||
enabled: enabled(),
|
|
||||||
initialOffset: () => options.initialOffset?.() ?? 0,
|
initialOffset: () => options.initialOffset?.() ?? 0,
|
||||||
observeElementRect: (instance, callback) => observeElementRect(instance, rect => {
|
observeElementRect: (instance, callback) => observeElementRect(instance, rect => {
|
||||||
callback(rect);
|
callback(rect);
|
||||||
@@ -129,9 +126,7 @@ export function createVirtualGrid(options: VirtualGridOptions) {
|
|||||||
itemHeight();
|
itemHeight();
|
||||||
gridColumns();
|
gridColumns();
|
||||||
columnGap();
|
columnGap();
|
||||||
if (enabled()) {
|
queueMicrotask(() => virtualizer.measure());
|
||||||
queueMicrotask(() => virtualizer.measure());
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
const updatePreservingScrollPosition = (update: () => void): void => {
|
const updatePreservingScrollPosition = (update: () => void): void => {
|
||||||
|
|||||||
Reference in New Issue
Block a user