Center the selected item in the gallery view strip

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent 3f90e9d1db
commit b2ad753da2

@ -24,7 +24,7 @@
</div> </div>
<mat-divider fxFlex></mat-divider> <mat-divider fxFlex></mat-divider>
<div class="file-scroll-view" fxFlex="20%"> <div class="file-scroll-view" fxFlex="20%">
<cdk-virtual-scroll-viewport #virtualScroll orientation="horizontal" itemSize="250" minBufferPx="1000" <cdk-virtual-scroll-viewport #virtualScroll orientation="horizontal" itemSize="260" minBufferPx="1000"
maxBufferPx="3000" class="file-scroll-viewport"> maxBufferPx="3000" class="file-scroll-viewport">
<div *cdkVirtualFor="let entry of entries" class="file-item"> <div *cdkVirtualFor="let entry of entries" class="file-item">
<app-file-gallery-entry [file]="entry" (fileSelectEvent)="onEntrySelect($event)"></app-file-gallery-entry> <app-file-gallery-entry [file]="entry" (fileSelectEvent)="onEntrySelect($event)"></app-file-gallery-entry>

@ -50,8 +50,19 @@ export class FileGalleryComponent implements OnChanges, OnInit {
this.selectedFile?.unselect(); this.selectedFile?.unselect();
entry.select(); entry.select();
this.selectedFile = entry; this.selectedFile = entry;
const selectedIndex = this.entries.indexOf(entry);
//this.virtualScroll.scrollToIndex(, "smooth");
await this.loadSelectedFile(); await this.loadSelectedFile();
this.virtualScroll.scrollToIndex(this.entries.indexOf(entry), "smooth");
if (this.virtualScroll) {
const viewportSize = this.virtualScroll.getViewportSize();
const indexAdjustment = (viewportSize / 260) / 2; // adjustment to have the selected item centered
this.virtualScroll.scrollToIndex(Math.max(selectedIndex - indexAdjustment, 0), "smooth");
if (selectedIndex > indexAdjustment) {
this.virtualScroll.scrollToOffset(this.virtualScroll.measureScrollOffset("left") + 130, "smooth");
}
}
this.fileSelectEvent.emit(this.selectedFile.data); this.fileSelectEvent.emit(this.selectedFile.data);
} }
} }

Loading…
Cancel
Save