Skip to content

Commit

Permalink
Moved propTypes declarations above components; added docstrings to We…
Browse files Browse the repository at this point in the history
…bPDFDocument propTypes
  • Loading branch information
artus9033 committed Dec 21, 2023
1 parent 44fc039 commit 26ecf68
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 46 deletions.
75 changes: 48 additions & 27 deletions src/components/PDFView/WebPDFDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,52 @@ import stylePropTypes from '@styles/stylePropTypes';
import CONST from '@src/CONST';
import PageRenderer from './WebPDFPageRenderer';

const propTypes = {
/** Index of the PDF page to be displayed passed by VariableSizeList */
errorLabelStyles: stylePropTypes,
/** Returns translated string for given locale and phrase */
translate: PropTypes.func.isRequired,
/** The source URL from which to load PDF file to be displayed */
sourceURL: PropTypes.string.isRequired,
/** Callback invoked when the PDF document is loaded successfully */
onDocumentLoadSuccess: PropTypes.func.isRequired,
/** Viewport info of all PDF pages */
pageViewportsLength: PropTypes.number.isRequired,
/** Sets attributes to list container */
setListAttributes: PropTypes.func.isRequired,
/** Indicates, whether the screen is of small width */
isSmallScreenWidth: PropTypes.bool.isRequired,
/** Height of PDF document container view */
containerHeight: PropTypes.number.isRequired,
/** Width of PDF document container view */
containerWidth: PropTypes.number.isRequired,
/** The number of pages of the PDF file to be rendered */
numPages: PropTypes.number,
/** Function that calculates the height of a page of the PDF document */
calculatePageHeight: PropTypes.func.isRequired,
/** Function that calculates the devicePixelRatio the page should be rendered with */
getDevicePixelRatio: PropTypes.func.isRequired,
/** The estimated height of a single PDF page for virtualized rendering purposes */
estimatedItemSize: PropTypes.number.isRequired,
/** The width of a page in the PDF file */
pageWidth: PropTypes.number.isRequired,
/** The style applied to the list component */
listStyle: stylePropTypes,
/** Function that should initiate that the user should be prompted for password to the PDF file */
initiatePasswordChallenge: PropTypes.func.isRequired,
/** Either:
* - `string` - the password provided by the user to unlock the PDF file
* - `undefined` if password isn't needed to view the PDF file
* - `null` if the password is required but hasn't been provided yet */
password: PropTypes.string,
};

const defaultProps = {
errorLabelStyles: [],
numPages: null,
listStyle: undefined,
};

const WebPDFDocument = memo(
({
errorLabelStyles,
Expand Down Expand Up @@ -79,32 +125,7 @@ const WebPDFDocument = memo(
);

WebPDFDocument.displayName = 'WebPDFDocument';
WebPDFDocument.propTypes = {
/** Index of the PDF page to be displayed passed by VariableSizeList */
errorLabelStyles: stylePropTypes,
translate: PropTypes.func.isRequired,
sourceURL: PropTypes.string.isRequired,
onDocumentLoadSuccess: PropTypes.func.isRequired,
pageViewportsLength: PropTypes.number.isRequired,
setListAttributes: PropTypes.func.isRequired,
isSmallScreenWidth: PropTypes.bool.isRequired,
containerHeight: PropTypes.number.isRequired,
containerWidth: PropTypes.number.isRequired,
numPages: PropTypes.number,
calculatePageHeight: PropTypes.func.isRequired,
getDevicePixelRatio: PropTypes.func.isRequired,
estimatedItemSize: PropTypes.number.isRequired,
pageWidth: PropTypes.number.isRequired,
listStyle: stylePropTypes,
initiatePasswordChallenge: PropTypes.func.isRequired,
// the password property can be null or undefined, indicating an entirely different state on purpose
// eslint-disable-next-line react/require-default-props
password: PropTypes.string,
};
WebPDFDocument.defaultProps = {
errorLabelStyles: [],
numPages: null,
listStyle: undefined,
};
WebPDFDocument.propTypes = propTypes;
WebPDFDocument.defaultProps = defaultProps;

export default WebPDFDocument;
40 changes: 21 additions & 19 deletions src/components/PDFView/WebPDFPageRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,26 @@ import _ from 'underscore';
import stylePropTypes from '@styles/stylePropTypes';
import PDFViewConstants from './constants';

const propTypes = {
/** Index of the PDF page to be displayed passed by VariableSizeList */
index: PropTypes.number.isRequired,

/** Page extra data passed by VariableSizeList's data prop */
data: PropTypes.shape({
/** Width of a single page in the document */
pageWidth: PropTypes.number.isRequired,
/** Function that calculates the height of a page given its index */
calculatePageHeight: PropTypes.func.isRequired,
/** Function that calculates the pixel ratio for a page given its calculated width and height */
getDevicePixelRatio: PropTypes.func.isRequired,
/** The estimated height of a single page in the document */
estimatedItemSize: PropTypes.number.isRequired,
}).isRequired,

/** Additional style props passed by VariableSizeList */
style: stylePropTypes.isRequired,
};

const WebPDFPageRenderer = memo(
({index: pageIndex, data, style}) => {
const {pageWidth, calculatePageHeight, getDevicePixelRatio, estimatedItemSize} = data;
Expand All @@ -32,24 +52,6 @@ const WebPDFPageRenderer = memo(
);

WebPDFPageRenderer.displayName = 'WebPDFPageRenderer';
WebPDFPageRenderer.propTypes = {
/** Index of the PDF page to be displayed passed by VariableSizeList */
index: PropTypes.number.isRequired,

/** Page extra data passed by VariableSizeList's data prop */
data: PropTypes.shape({
/** Width of a single page in the document */
pageWidth: PropTypes.number.isRequired,
/** Function that calculates the height of a page given its index */
calculatePageHeight: PropTypes.func.isRequired,
/** Function that calculates the pixel ratio for a page given its calculated width and height */
getDevicePixelRatio: PropTypes.func.isRequired,
/** The estimated height of a single page in the document */
estimatedItemSize: PropTypes.number.isRequired,
}).isRequired,

/** Additional style props passed by VariableSizeList */
style: stylePropTypes.isRequired,
};
WebPDFPageRenderer.propTypes = propTypes;

export default WebPDFPageRenderer;

0 comments on commit 26ecf68

Please sign in to comment.