[ADF-2438] fixed thumbnails height (#3407)

* [ADF-2438] calculate thumbnail height

* [ADF-2438] send height to parent element

* [ADF-2438] add width to css

* [ADF-2438] moved height and width logic to parent component

* [ADF-2438] added height and width logic to parent component

* [ADF-2438] fixed failing test
This commit is contained in:
Georgiana Roman
2018-06-04 14:20:20 +03:00
committed by Eugenio Romano
parent 2f51b9f2b8
commit 1266acc4ab
6 changed files with 42 additions and 28 deletions

View File

@@ -33,6 +33,8 @@ export class PdfThumbListComponent implements OnInit, AfterViewInit, OnDestroy {
virtualHeight: number = 0;
translateY: number = 0;
renderItems = [];
width: number = 91;
currentHeight: number = 0;
private items = [];
private margin: number = 15;
@@ -52,11 +54,13 @@ export class PdfThumbListComponent implements OnInit, AfterViewInit, OnDestroy {
}
ngOnInit() {
this.element.nativeElement.addEventListener('scroll', this.calculateItems, true);
this.pdfViewer.eventBus.on('pagechange', this.onPageChange);
this.element.nativeElement.addEventListener('scroll', this.calculateItems, true);
this.setHeight(this.pdfViewer.currentPageNumber);
this.items = this.getPages();
this.calculateItems();
}
ngAfterViewInit() {
@@ -97,10 +101,26 @@ export class PdfThumbListComponent implements OnInit, AfterViewInit, OnDestroy {
getPages() {
return this.pdfViewer._pages.map((page) => ({
id: page.id,
getWidth: () => { return this.width; },
getHeight: () => { return this.currentHeight; },
getPage: () => this.pdfViewer.pdfDocument.getPage(page.id)
}));
}
private setHeight(id): number {
const height = this.pdfViewer.pdfDocument.getPage(id).then((page) => this.calculateHeight(page));
return height;
}
private calculateHeight(page) {
const viewport = page.getViewport(1);
const pageRatio = viewport.width / viewport.height;
const height = Math.floor(this.width / pageRatio);
this.currentHeight = height;
this.itemHeight = height + this.margin;
}
private calculateItems() {
const { element, viewPort, itemsInView } = this.getContainerSetup();