forked from Expensify/react-fast-pdf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPageRenderer.tsx
More file actions
46 lines (42 loc) · 1.69 KB
/
PageRenderer.tsx
File metadata and controls
46 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import React, {memo, type CSSProperties} from 'react';
import {Page} from 'react-pdf';
import {pdfPreviewerStyles as styles} from './styles.js';
import {PAGE_BORDER} from './constants.js';
type Props = {
index: number;
style: CSSProperties;
data: {
pageWidth: number;
estimatedPageHeight: number;
calculatePageHeight: (pageIndex: number) => number;
getDevicePixelRatio: (width: number, height: number) => number | undefined;
numPages: number;
};
};
function PageRenderer({index, style, data}: Props) {
const {pageWidth, estimatedPageHeight, calculatePageHeight, getDevicePixelRatio, numPages} = data;
/**
* Render a specific page based on its index.
* The method includes a wrapper to apply virtualized styles.
*/
const pageHeight = calculatePageHeight(index);
const devicePixelRatio = getDevicePixelRatio(pageWidth, pageHeight);
const parsedTop = parseFloat(style.top as unknown as string);
const topPadding = numPages === 1 ? parsedTop : parsedTop + PAGE_BORDER;
return (
<div style={{...styles.pageWrapper, ...style, top: `${topPadding}px`}}>
<Page
key={`page_${index}`}
width={pageWidth}
height={pageHeight || estimatedPageHeight}
pageIndex={index}
// This needs to be empty to avoid multiple loading texts which show per page and look ugly
// See https://github.com/Expensify/App/issues/14358 for more details
loading=""
devicePixelRatio={devicePixelRatio}
/>
</div>
);
}
PageRenderer.displayName = 'PageRenderer';
export default memo(PageRenderer);