[AAE-4009] Fix horizontal scroll issue for pdf-viewer (#7023)

* [AAE-4009] Fix horizontal scroll issue for pdf-viewer

* [AAE-4009] Rewrite method with single exit
This commit is contained in:
Nanna Setämaa 2021-05-17 11:35:26 +01:00 committed by GitHub
parent f3ada4ef85
commit f7ec24d1bb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -625,6 +625,16 @@ describe('Test PdfViewer component', () => {
});
}, 25000);
it('should check if page fits to documentContainer', (done) => {
spyOn(componentUrlTestComponent.pdfViewerComponent, 'checkPageFitInContainer');
componentUrlTestComponent.pdfViewerComponent.scalePage(1);
fixtureUrlTestComponent.detectChanges();
fixtureUrlTestComponent.whenStable().then(() => {
expect(componentUrlTestComponent.pdfViewerComponent.checkPageFitInContainer).toHaveBeenCalled();
done();
});
});
});
describe('Zoom', () => {

View File

@ -306,6 +306,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
}
horizontalScale = Math.round(horizontalScale);
scale = Math.min(this.MAX_AUTO_SCALE, horizontalScale);
scale = this.checkPageFitInContainer(scale);
break;
default:
@ -316,6 +317,7 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
this.setScaleUpdatePages(scale);
} else {
this.currentScale = 0;
scale = this.checkPageFitInContainer(scale);
this.setScaleUpdatePages(scale);
}
}
@ -329,6 +331,20 @@ export class PdfViewerComponent implements OnChanges, OnDestroy {
return document.getElementById(`${this.randomPdfId}-viewer-viewerPdf`);
}
checkPageFitInContainer(scale: number): number {
const documentContainerSize = this.getDocumentContainer();
const page = this.pdfViewer._pages[this.pdfViewer._currentPageNumber - 1];
if (page.width > documentContainerSize.clientWidth) {
scale = Math.fround((documentContainerSize.clientWidth - 20) / page.width);
if (scale < this.MIN_SCALE) {
scale = this.MIN_SCALE;
}
}
return scale;
}
/**
* Update all the pages with the newScale scale
*