-
-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
611bf8b
commit b242456
Showing
8 changed files
with
33 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,4 +11,6 @@ src | |
.prettierrc | ||
tsconfig.json | ||
tslint.json | ||
.github/FUNDING.yml | ||
.github | ||
ISSUE_TEMPLATE.md | ||
LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<script src="//cdn.jsdelivr.net/npm/[email protected]/build/pdf.min.js"></script> | ||
<script src="//cdn.jsdelivr.net/npm/[email protected]/web/pdf_viewer.min.js"></script> | ||
<script src="https://wzrd.in/standalone/raf@latest"></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react@16/umd/react.production.min.js" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,6 +51,7 @@ export interface Props { | |
customStyle?: CustomStyle | ||
useGoogleReader?: boolean | ||
withScroll?: boolean | ||
withPinchZoom?: boolean | ||
onLoad?(event: WebViewNavigationEvent): void | ||
onLoadEnd?(event: WebViewNavigationEvent | WebViewErrorEvent): void | ||
onError?(event: WebViewErrorEvent | WebViewHttpErrorEvent | string): void | ||
|
@@ -68,16 +69,20 @@ function viewerHtml( | |
base64: string, | ||
customStyle?: CustomStyle, | ||
withScroll: boolean = false, | ||
withPinchZoom: boolean = false, | ||
): string { | ||
return ` | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<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=1.0, user-scalable=no" /> | ||
<meta name="viewport" content="width=device-width, minimum-scale=1.0, initial-scale=1.0, maximum-scale=${ | ||
withPinchZoom ? '4.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> | ||
<script src="https://wzrd.in/standalone/raf@latest"></script> | ||
<script | ||
crossorigin | ||
src="https://unpkg.com/react@16/umd/react.production.min.js" | ||
|
@@ -123,13 +128,17 @@ async function writeWebViewReaderFileAsync( | |
data: string, | ||
customStyle?: CustomStyle, | ||
withScroll?: boolean, | ||
withPinchZoom?: boolean, | ||
): Promise<void> { | ||
const { exists, md5 } = await getInfoAsync(bundleJsPath, { md5: true }) | ||
const bundleContainer = require('./bundleContainer') | ||
if (__DEV__ || !exists || bundleContainer.getBundleMd5() !== md5) { | ||
await writeAsStringAsync(bundleJsPath, bundleContainer.getBundle()) | ||
} | ||
await writeAsStringAsync(htmlPath, viewerHtml(data, customStyle, withScroll)) | ||
await writeAsStringAsync( | ||
htmlPath, | ||
viewerHtml(data, customStyle, withScroll, withPinchZoom), | ||
) | ||
} | ||
|
||
async function writePDFAsync(base64: string) { | ||
|
@@ -267,12 +276,17 @@ class PdfReader extends React.Component<Props, State> { | |
|
||
init = async () => { | ||
try { | ||
const { source, customStyle, withScroll } = this.props | ||
const { source, customStyle, withScroll, withPinchZoom } = this.props | ||
const { renderType } = this.state | ||
switch (renderType!) { | ||
case 'URL_TO_BASE64': { | ||
const data = await fetchPdfAsync(source) | ||
await writeWebViewReaderFileAsync(data!, customStyle, withScroll) | ||
await writeWebViewReaderFileAsync( | ||
data!, | ||
customStyle, | ||
withScroll, | ||
withPinchZoom, | ||
) | ||
break | ||
} | ||
|
||
|
@@ -281,6 +295,7 @@ class PdfReader extends React.Component<Props, State> { | |
source.base64!, | ||
customStyle, | ||
withScroll, | ||
withPinchZoom, | ||
) | ||
break | ||
} | ||
|
@@ -410,7 +425,6 @@ class PdfReader extends React.Component<Props, State> { | |
'content:*', | ||
] | ||
const style = [styles.webview, webviewStyle] | ||
// html: `<script>alert(navigator.serviceWorker)</script>`, | ||
const isAndroid = Platform.OS === 'android' | ||
if (ready) { | ||
const source: WebViewSource | undefined = this.getWebviewSource() | ||
|
@@ -434,7 +448,6 @@ class PdfReader extends React.Component<Props, State> { | |
allowFileAccess={isAndroid} | ||
allowFileAccessFromFileURLs={isAndroid} | ||
allowUniversalAccessFromFileURLs={isAndroid} | ||
androidHardwareAccelerationDisabled | ||
scalesPageToFit={Platform.select({ android: false })} | ||
mixedContentMode={isAndroid ? 'always' : undefined} | ||
sharedCookiesEnabled={false} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b242456
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Amazing! Thanks a lot!