Skip to content

Commit 5cab651

Browse files
authored
Merge pull request #47 from callstack-internal/fix/initial-sizes
2 parents d3ee169 + d0adaf6 commit 5cab651

2 files changed

Lines changed: 13 additions & 1 deletion

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/

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)