@@ -51,6 +51,7 @@ export interface Props {
5151 customStyle ?: CustomStyle
5252 useGoogleReader ?: boolean
5353 withScroll ?: boolean
54+ withPinchZoom ?: boolean
5455 onLoad ?( event : WebViewNavigationEvent ) : void
5556 onLoadEnd ?( event : WebViewNavigationEvent | WebViewErrorEvent ) : void
5657 onError ?( event : WebViewErrorEvent | WebViewHttpErrorEvent | string ) : void
@@ -68,16 +69,20 @@ function viewerHtml(
6869 base64 : string ,
6970 customStyle ?: CustomStyle ,
7071 withScroll : boolean = false ,
72+ withPinchZoom : boolean = false ,
7173) : string {
7274 return `
7375<!DOCTYPE html>
7476<html>
7577 <head>
7678 <title>PDF reader</title>
7779 <meta charset="utf-8" />
78- <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
80+ <meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, maximum-scale=${
81+ withPinchZoom ? '4.0' : '1.0'
82+ } , user-scalable=${ withPinchZoom ? 'yes' : 'no' } " />
7983 <script src="https://cdn.jsdelivr.net/npm/[email protected] /build/pdf.min.js"></script> 8084 <script src="https://cdn.jsdelivr.net/npm/[email protected] /web/pdf_viewer.min.js"></script> 85+ <script src="https://wzrd.in/standalone/raf@latest"></script>
8186 <script
8287 crossorigin
8388 src="https://unpkg.com/react@16/umd/react.production.min.js"
@@ -123,13 +128,17 @@ async function writeWebViewReaderFileAsync(
123128 data : string ,
124129 customStyle ?: CustomStyle ,
125130 withScroll ?: boolean ,
131+ withPinchZoom ?: boolean ,
126132) : Promise < void > {
127133 const { exists, md5 } = await getInfoAsync ( bundleJsPath , { md5 : true } )
128134 const bundleContainer = require ( './bundleContainer' )
129135 if ( __DEV__ || ! exists || bundleContainer . getBundleMd5 ( ) !== md5 ) {
130136 await writeAsStringAsync ( bundleJsPath , bundleContainer . getBundle ( ) )
131137 }
132- await writeAsStringAsync ( htmlPath , viewerHtml ( data , customStyle , withScroll ) )
138+ await writeAsStringAsync (
139+ htmlPath ,
140+ viewerHtml ( data , customStyle , withScroll , withPinchZoom ) ,
141+ )
133142}
134143
135144async function writePDFAsync ( base64 : string ) {
@@ -267,12 +276,17 @@ class PdfReader extends React.Component<Props, State> {
267276
268277 init = async ( ) => {
269278 try {
270- const { source, customStyle, withScroll } = this . props
279+ const { source, customStyle, withScroll, withPinchZoom } = this . props
271280 const { renderType } = this . state
272281 switch ( renderType ! ) {
273282 case 'URL_TO_BASE64' : {
274283 const data = await fetchPdfAsync ( source )
275- await writeWebViewReaderFileAsync ( data ! , customStyle , withScroll )
284+ await writeWebViewReaderFileAsync (
285+ data ! ,
286+ customStyle ,
287+ withScroll ,
288+ withPinchZoom ,
289+ )
276290 break
277291 }
278292
@@ -281,6 +295,7 @@ class PdfReader extends React.Component<Props, State> {
281295 source . base64 ! ,
282296 customStyle ,
283297 withScroll ,
298+ withPinchZoom ,
284299 )
285300 break
286301 }
@@ -410,7 +425,6 @@ class PdfReader extends React.Component<Props, State> {
410425 'content:*' ,
411426 ]
412427 const style = [ styles . webview , webviewStyle ]
413- // html: `<script>alert(navigator.serviceWorker)</script>`,
414428 const isAndroid = Platform . OS === 'android'
415429 if ( ready ) {
416430 const source : WebViewSource | undefined = this . getWebviewSource ( )
@@ -434,7 +448,6 @@ class PdfReader extends React.Component<Props, State> {
434448 allowFileAccess = { isAndroid }
435449 allowFileAccessFromFileURLs = { isAndroid }
436450 allowUniversalAccessFromFileURLs = { isAndroid }
437- androidHardwareAccelerationDisabled
438451 scalesPageToFit = { Platform . select ( { android : false } ) }
439452 mixedContentMode = { isAndroid ? 'always' : undefined }
440453 sharedCookiesEnabled = { false }
0 commit comments