Skip to content

Commit d0adaf6

Browse files
os-botify[bot]koko57
authored andcommitted
fix: apply resizing fix
1 parent 6fb801d commit d0adaf6

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ dist/
88

99
# NPM file created by GitHub actions
1010
.npmrc
11+
.idea/

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-fast-pdf",
3-
"version": "1.0.25",
3+
"version": "1.0.26",
44
"description": "react-fast-pdf",
55
"main": "./dist/index.js",
66
"files": [

src/PDFPreviewer.tsx

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,12 @@ function PDFPreviewer({
6767
const [isPasswordInvalid, setIsPasswordInvalid] = useState(false);
6868
const containerRef = useRef<HTMLDivElement>(null);
6969
const onPasswordCallbackRef = useRef<OnPasswordCallback | null>(null);
70+
const listRef = useRef<List>(null);
7071

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

210+
/**
211+
* Reset List style cache when dimensions change
212+
*/
213+
useLayoutEffect(() => {
214+
if (containerWidth > 0 && containerHeight > 0) {
215+
listRef.current?.resetAfterIndex(0);
216+
}
217+
}, [containerWidth, containerHeight]);
218+
209219
useLayoutEffect(() => {
210220
if (!containerRef.current) {
211221
return undefined;
@@ -240,6 +250,7 @@ function PDFPreviewer({
240250
>
241251
{pageViewports.length > 0 && (
242252
<List
253+
ref={listRef}
243254
style={{...styles.list, ...contentContainerStyle}}
244255
outerRef={setListAttributes}
245256
width={isSmallScreen ? pageWidth : containerWidth}

0 commit comments

Comments
 (0)