Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr fix #199

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
"description": "PDF reader Example",
"slug": "rn-pdf-reader-example",
"privacy": "public",
"sdkVersion": "36.0.0",
"platforms": ["ios", "android", "web"],
"platforms": [
"ios",
"android",
"web"
],
"version": "1.0.0",
"orientation": "portrait",
"icon": "./src/assets/images/icon.png",
Expand Down
65 changes: 27 additions & 38 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"name": "rn-pdf-reader-js",
"version": "4.1.1",
"description": "PDF reader for Expo",
"main": "node_modules/expo/AppEntry.js",
"name": "@valli_/rn-pdf-reader-js",
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you change the name of the package that won't publish in the right place ;)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Working, thanks a lot!

"version": "1.0.9",
"description": "Fork From PDF reader for Expo - Xavier Carpentier <[email protected]> (https://xaviercarpentier.com/)",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "Xavier Carpentier <[email protected]> (https://xaviercarpentier.com/)",
"author": "Tomas Valli",
"license": "MIT",
"scripts": {
"start": "yarn config:dev && expo start -c",
"start": "npx expo start",
"tsc": "node_modules/.bin/tsc --noEmit",
"bundle": "./scripts/gen_bundle_string.js",
"build": "yarn bundle && rm -rf lib/ && node_modules/.bin/tsc",
"build": "yarn bundle && node_modules/.bin/tsc",
"config:dev": "json -I -f package.json -e 'this.main=\"node_modules/expo/AppEntry.js\"'",
"config:npm": "json -I -f package.json -e 'this.main=\"lib/index.js\"'",
"lint": "tslint --project .",
Expand All @@ -29,39 +29,28 @@
"react-pdf",
"expo"
],
"repository": {
"type": "git",
"url": "git+https://github.com/xcarpentier/rn-pdf-reader-js.git"
},
"peerDependencies": {
"expo": ">= 33.0.x < 41.0.x",
"expo-constants": ">= 5.0.0 < 9.x",
"expo-file-system": ">= 5.0.0 < 9.x",
"react": "16.x",
"react-native": "*",
"react-native-webview": ">= 7.0.5 < 12.x"
},
"dependencies": {
"buffer": "5.1.0",
"csstype": "2.6.8",
"js-base64": "2.4.5"
"buffer": "^6.0.3",
"csstype": "^3.1.1",
"js-base64": "^3.7.2"
},
"devDependencies": {
"@types/js-base64": "2.3.1",
"@types/react": "16.9.17",
"@types/react-dom": "16.9.4",
"@types/react-native": "0.60.28",
"babel-preset-expo": "^8.0.0",
"crypto": "1.0.1",
"expo": "^36.0.2",
"expo-constants": "~8.0.0",
"expo-file-system": "~8.0.0",
"json": "^9.0.6",
"react": "16.9.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-36.0.1.tar.gz",
"react-native-webview": "7.4.3",
"tslint": "^5.20.1",
"@types/js-base64": "^3.3.1",
"@types/react": "~18.2.14",
"@types/react-dom": "~18.0.10",
"@types/react-native": "^0.72.2",
"babel-preset-expo": "^9.5.0",
"crypto": "^1.0.1",
"expo": "^49.0.0",
"expo-constants": "~14.4.2",
"expo-file-system": "~15.4.4",
"json": "^11.0.0",
"react": "18.2.0",
"react-native": "0.72.5",
"react-native-webview": "13.2.2",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "3.7.4"
}
"typescript": "^5.1.3"
},
"repository": "[email protected]:Valli-/rn-pdf-reader-js.git"
}
7 changes: 3 additions & 4 deletions react-pdf/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
"dependencies": {
"@babel/runtime": "7.7.7",
"raf": "3.4.1",
"react": "16.12.0",
"react-dom": "16.12.0",
"react-pdf": "4.1.0"
"react": "18.0.0",
"react-dom": "18.0.0",
"react-pdf": "7.1.2"
},
"devDependencies": {
"@babel/core": "7.7.7",
Expand All @@ -29,7 +29,6 @@
"@babel/preset-react": "7.7.4",
"@babel/runtime-corejs2": "7.7.7",
"@types/raf": "3.4.0",
"@types/react-pdf": "4.0.3",
"babel-eslint": "10.0.3",
"babel-loader": "8.0.6",
"copy-webpack-plugin": "5.1.1",
Expand Down
37 changes: 17 additions & 20 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,16 @@ import {
WebViewHttpErrorEvent,
} from 'react-native-webview/lib/WebViewTypes'

const {
cacheDirectory,
writeAsStringAsync,
deleteAsync,
getInfoAsync,
EncodingType,
} = FileSystem
const { cacheDirectory, writeAsStringAsync, deleteAsync, getInfoAsync } =
FileSystem

export type RenderType =
| 'DIRECT_URL'
| 'DIRECT_BASE64'
| 'BASE64_TO_LOCAL_PDF'
| 'URL_TO_BASE64'
| 'GOOGLE_READER'
| 'GOOGLE_DRIVE_VIEWER';
| 'GOOGLE_DRIVE_VIEWER'

export interface CustomStyle {
readerContainer?: CSS.Properties<any>
Expand Down Expand Up @@ -134,7 +129,9 @@ async function writeWebViewReaderFileAsync(
withPinchZoom?: boolean,
maximumPinchZoomScale?: number,
): Promise<void> {
const { exists, md5 } = await getInfoAsync(bundleJsPath, { md5: true })
const { exists, md5 } = (await getInfoAsync(bundleJsPath, {
md5: true,
})) as any
const bundleContainer = require('./bundleContainer')
if (__DEV__ || !exists || bundleContainer.getBundleMd5() !== md5) {
await writeAsStringAsync(bundleJsPath, bundleContainer.getBundle())
Expand All @@ -155,7 +152,7 @@ async function writePDFAsync(base64: string) {
await writeAsStringAsync(
pdfPath,
base64.replace('data:application/pdf;base64,', ''),
{ encoding: EncodingType.Base64 },
{ encoding: 'base64' },
)
}

Expand Down Expand Up @@ -299,9 +296,9 @@ class PdfReader extends React.Component<Props, State> {
const { renderType } = this.state
switch (renderType!) {
case 'GOOGLE_DRIVE_VIEWER': {
break;
break
}

case 'URL_TO_BASE64': {
const data = await fetchPdfAsync(source)
await writeWebViewReaderFileAsync(
Expand Down Expand Up @@ -335,7 +332,7 @@ class PdfReader extends React.Component<Props, State> {
}

this.setState({ ready: true })
} catch (error) {
} catch (error: any) {
alert(`Sorry, an error occurred. ${error.message}`)
console.error(error)
}
Expand All @@ -353,7 +350,7 @@ class PdfReader extends React.Component<Props, State> {
}

if (useGoogleDriveViewer) {
return 'GOOGLE_DRIVE_VIEWER';
return 'GOOGLE_DRIVE_VIEWER'
}

if (Platform.OS === 'ios') {
Expand Down Expand Up @@ -386,7 +383,7 @@ class PdfReader extends React.Component<Props, State> {
case 'GOOGLE_READER':
return { uri: getGoogleReaderUrl(uri!) }
case 'GOOGLE_DRIVE_VIEWER':
return { uri: getGoogleDriveUrl(uri) };
return { uri: getGoogleDriveUrl(uri!) }
case 'DIRECT_BASE64':
case 'URL_TO_BASE64':
return { uri: htmlPath }
Expand Down Expand Up @@ -429,15 +426,15 @@ class PdfReader extends React.Component<Props, State> {
) {
try {
removeFilesAsync()
} catch (error) {
} catch (error: any) {
alert(`Error on removing file. ${error.message}`)
console.error(error)
}
}
}

render() {
const { ready, renderedOnce } = this.state
const { ready } = this.state

const {
style: containerStyle,
Expand All @@ -462,10 +459,10 @@ class PdfReader extends React.Component<Props, State> {
const source: WebViewSource | undefined = this.getWebviewSource()
return (
<View style={[styles.container, containerStyle]}>
<WebView
<WebView<any>
{...{
originWhitelist,
onLoad: (event) => {
onLoad: (event: any) => {
this.setState({ renderedOnce: true })
if (onLoad) {
onLoad(event)
Expand All @@ -475,7 +472,7 @@ class PdfReader extends React.Component<Props, State> {
onError,
onHttpError: onError,
style,
source: renderedOnce || !isAndroid ? source : undefined,
source: source || { uri: null },
}}
allowFileAccess={isAndroid}
allowFileAccessFromFileURLs={isAndroid}
Expand Down
19 changes: 15 additions & 4 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
{
"include": ["src"],
"include": [
"src"
],
"compilerOptions": {
"declaration": true,
"outDir": "./lib",
Expand Down Expand Up @@ -28,8 +30,17 @@
"resolveJsonModule": true,
"noFallthroughCasesInSwitch": true,
"strictPropertyInitialization": false,
"lib": ["dom", "esnext"],
"typeRoots": ["./node_modules/@types", "./@types"]
"lib": [
"dom",
"esnext"
],
"typeRoots": [
"./node_modules/@types",
"./@types"
]
},
"exclude": ["node_modules"]
"exclude": [
"node_modules"
],
"extends": "expo/tsconfig.base"
}
Loading