Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ dist/

# NPM file created by GitHub actions
.npmrc
.idea/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NAB - what's this change?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's for Webstorm users - to ignore local files that Webstorm creates

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-fast-pdf",
"version": "1.0.25",
"version": "1.0.26",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The bot bumps it automatically.

Suggested change
"version": "1.0.26",

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

strange, it should be already like that on main

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I see it. What's going on? 😅

Screenshot 2025-02-13 at 16 11 59 Screenshot 2025-02-13 at 16 11 55

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind.

"description": "react-fast-pdf",
"main": "./dist/index.js",
"files": [
Expand Down
13 changes: 12 additions & 1 deletion src/PDFPreviewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ function PDFPreviewer({
const [isPasswordInvalid, setIsPasswordInvalid] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);
const onPasswordCallbackRef = useRef<OnPasswordCallback | null>(null);
const listRef = useRef<List>(null);

/**
* Calculate the devicePixelRatio the page should be rendered with
* Each platform has a different default devicePixelRatio and different canvas limits, we need to verify that
* with the default devicePixelRatio it will be able to diplay the pdf correctly, if not we must change the devicePixelRatio.
* with the default devicePixelRatio it will be able to display the pdf correctly, if not we must change the devicePixelRatio.
* @param {Number} width of the page
* @param {Number} height of the page
* @returns {Number} devicePixelRatio for this page on this platform
Expand Down Expand Up @@ -206,6 +207,15 @@ function PDFPreviewer({
);
}, [isPasswordInvalid, attemptPDFLoad, setIsPasswordInvalid, renderPasswordForm]);

/**
* Reset List style cache when dimensions change
*/
useLayoutEffect(() => {
if (containerWidth > 0 && containerHeight > 0) {
listRef.current?.resetAfterIndex(0);
}
}, [containerWidth, containerHeight]);

useLayoutEffect(() => {
if (!containerRef.current) {
return undefined;
Expand Down Expand Up @@ -240,6 +250,7 @@ function PDFPreviewer({
>
{pageViewports.length > 0 && (
<List
ref={listRef}
style={{...styles.list, ...contentContainerStyle}}
outerRef={setListAttributes}
width={isSmallScreen ? pageWidth : containerWidth}
Expand Down