Skip to content

Commit

Permalink
feat: 🎸 increase zoom capability
Browse files Browse the repository at this point in the history
  • Loading branch information
xcarpentier committed Jul 10, 2020
1 parent e01c672 commit 3ebbe1e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion react-pdf/Reader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Reader extends React.Component<Props, State> {
error: undefined,
}

MAX_SCALE = 2
MAX_SCALE = 4
__zoomEvent = false

onDocumentLoadSuccess = ({ numPages }) => {
Expand Down
4 changes: 2 additions & 2 deletions src/bundleContainer.ts

Large diffs are not rendered by default.

15 changes: 12 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export interface Props {
useGoogleReader?: boolean
withScroll?: boolean
withPinchZoom?: boolean
maximumPinchZoomScale?: number
onLoad?(event: WebViewNavigationEvent): void
onLoadEnd?(event: WebViewNavigationEvent | WebViewErrorEvent): void
onError?(event: WebViewErrorEvent | WebViewHttpErrorEvent | string): void
Expand All @@ -70,6 +71,7 @@ function viewerHtml(
customStyle?: CustomStyle,
withScroll: boolean = false,
withPinchZoom: boolean = false,
maximumPinchZoomScale: number = 5,
): string {
return `
<!DOCTYPE html>
Expand All @@ -78,7 +80,7 @@ function viewerHtml(
<title>PDF reader</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, maximum-scale=${
withPinchZoom ? '4.0' : '1.0'
withPinchZoom ? `${maximumPinchZoomScale}.0` : '1.0'
}, user-scalable=${withPinchZoom ? 'yes' : 'no'}" />
<script src="https://cdn.jsdelivr.net/npm/[email protected]/build/pdf.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/web/pdf_viewer.min.js"></script>
Expand Down Expand Up @@ -129,6 +131,7 @@ async function writeWebViewReaderFileAsync(
customStyle?: CustomStyle,
withScroll?: boolean,
withPinchZoom?: boolean,
maximumPinchZoomScale?: number,
): Promise<void> {
const { exists, md5 } = await getInfoAsync(bundleJsPath, { md5: true })
const bundleContainer = require('./bundleContainer')
Expand All @@ -137,7 +140,13 @@ async function writeWebViewReaderFileAsync(
}
await writeAsStringAsync(
htmlPath,
viewerHtml(data, customStyle, withScroll, withPinchZoom),
viewerHtml(
data,
customStyle,
withScroll,
withPinchZoom,
maximumPinchZoomScale,
),
)
}

Expand Down Expand Up @@ -276,7 +285,7 @@ class PdfReader extends React.Component<Props, State> {

init = async () => {
try {
const { source, customStyle, withScroll, withPinchZoom } = this.props
const { source, customStyle, withScroll, withPinchZoom, } = this.props
const { renderType } = this.state
switch (renderType!) {
case 'URL_TO_BASE64': {
Expand Down

0 comments on commit 3ebbe1e

Please sign in to comment.