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

Fix/error as unknow #180

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
234d253
chore: update dependencies to handle react 17, expo 44 and expo-file-…
renishv8 Feb 16, 2022
7d8ca27
Merge pull request #1 from renishv8/chore/update-dependencies
renishv8 Feb 16, 2022
15071fa
chore: update expo last version allowed
renishv8 Feb 16, 2022
78e5e5d
Merge pull request #2 from renishv8/chore/update-dependencies
renishv8 Feb 16, 2022
687013f
chore: change versions conditions allowed
renishv8 Feb 16, 2022
0a6104a
Merge pull request #3 from renishv8/chore/update-dependencies
renishv8 Feb 16, 2022
5edafdd
feat: google drive url can be undefined
renishv8 Feb 16, 2022
7a13cb4
Merge pull request #4 from renishv8/fix/googledriveurl-cant-be-undefined
renishv8 Feb 16, 2022
35f7b57
chore: init fork and update dependencies
renishv8 Feb 17, 2022
1f2dad4
Merge pull request #5 from renishv8/chore/init-fork-and-update-depend…
renishv8 Feb 17, 2022
52aa94e
chore: update package name
renishv8 Feb 17, 2022
6b270d3
Merge pull request #6 from renishv8/chore/update-package
renishv8 Feb 17, 2022
4a388c0
chore: update supported versions of react and expo dependencies
renishv8 Sep 22, 2022
9d1caf8
Merge pull request #7 from renishv8/chore/up-supported-versions
renishv8 Sep 22, 2022
73536fb
chore: update package.json
renishv8 Sep 22, 2022
b49f4b1
Merge pull request #8 from renishv8/chore/up-supported-versions
renishv8 Sep 22, 2022
01dcc27
chore: update packages
renishv8 Sep 22, 2022
d295e27
chore: up app version
renishv8 Sep 22, 2022
31b4bf9
Merge pull request #9 from renishv8/chore/update-packages
renishv8 Sep 22, 2022
8be31f8
fix: error as unknow and lint
renishv8 Sep 22, 2022
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
71 changes: 37 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<h1 align="center">PDF Reader</h1>

<h2 align="center">Project forked from <a href="https://github.com/xcarpentier/rn-pdf-reader-js">xcarpentier rn-pdf-reader-js</a> to support recent dependencies</h2>

<p align="center">Android support 🚀</p>

<p align="center">
Expand All @@ -23,7 +26,7 @@
- 👉**Install expo-file-system** on your own!
- 👉**Install expo-constants** on your own!
- Use it into Expo app (from expo client, Standalone app or ExpoKit app).
- Only React-Native 0.59-0.60+ support, **Expo SDK 33-36+**
- Only React-Native 0.59-0.60+ support, **Expo SDK 33-44+**

[PRs are welcome...](https://github.com/xcarpentier/rn-pdf-reader-js/pulls)

Expand All @@ -35,15 +38,15 @@ import { View } from 'react-native'
import PDFReader from 'rn-pdf-reader-js'

export default class App extends React.Component {
render() {
return (
<PDFReader
source={{
uri: 'http://gahp.net/wp-content/uploads/2017/09/sample.pdf',
}}
/>
)
}
render() {
return (
<PDFReader
source={{
uri: 'http://gahp.net/wp-content/uploads/2017/09/sample.pdf',
}}
/>
)
}
}
```

Expand All @@ -53,33 +56,33 @@ See more detailed example into `App.tsx` file.

```tsx
interface Source {
uri?: string // can be local or served on the web (ie. start with `https://` or `file://`)
base64?: string // should start with `data:application/pdf;base64,`. A base64 encoded pdf file tends to start with `JVBERi0xL` so your complete string should look something like this: `data:application/pdf;base64,JVBERi0xL...`
headers?: { [key: string]: string }
uri?: string // can be local or served on the web (ie. start with `https://` or `file://`)
base64?: string // should start with `data:application/pdf;base64,`. A base64 encoded pdf file tends to start with `JVBERi0xL` so your complete string should look something like this: `data:application/pdf;base64,JVBERi0xL...`
headers?: { [key: string]: string }
}

interface Props {
source: Source
style?: View['props']['style'] // style props to override default container style
webviewStyle?: WebView['props']['style'] // style props to override default WebView style
webviewProps?: WebView['props']
noLoader?: boolean
useGoogleReader?: boolean // If you are not worried about confidentiality
withScroll?: boolean // Can cause performance issue
withPinchZoom?: boolean
customStyle?: {
readerContainer?: CSS.Properties
readerContainerDocument?: CSS.Properties
readerContainerNumbers?: CSS.Properties
readerContainerNumbersContent?: CSS.Properties
readerContainerZoomContainer?: CSS.Properties
readerContainerZoomContainerButton?: CSS.Properties
readerContainerNavigate?: CSS.Properties
readerContainerNavigateArrow?: CSS.Properties
}
onLoad?(): void // callback that runs after WebView is loaded
onLoadEnd?(): void // callback that runs after WebView is loaded
onError?(): void // callback that runs when WebView is on error
source: Source
style?: View['props']['style'] // style props to override default container style
webviewStyle?: WebView['props']['style'] // style props to override default WebView style
webviewProps?: WebView['props']
noLoader?: boolean
useGoogleReader?: boolean // If you are not worried about confidentiality
withScroll?: boolean // Can cause performance issue
withPinchZoom?: boolean
customStyle?: {
readerContainer?: CSS.Properties
readerContainerDocument?: CSS.Properties
readerContainerNumbers?: CSS.Properties
readerContainerNumbersContent?: CSS.Properties
readerContainerZoomContainer?: CSS.Properties
readerContainerZoomContainerButton?: CSS.Properties
readerContainerNavigate?: CSS.Properties
readerContainerNavigateArrow?: CSS.Properties
}
onLoad?(): void // callback that runs after WebView is loaded
onLoadEnd?(): void // callback that runs after WebView is loaded
onError?(): void // callback that runs when WebView is on error
}
```

Expand Down
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
60 changes: 32 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "rn-pdf-reader-js",
"version": "4.1.1",
"description": "PDF reader for Expo",
"name": "@renishv8/rn-pdf-reader-js-improved",
"version": "1.3.1",
"description": "PDF reader forked to update dependencies and add improvements",
"main": "node_modules/expo/AppEntry.js",
"types": "lib/index.d.ts",
"author": "Xavier Carpentier <xcapetir@gmail.com> (https://xaviercarpentier.com/)",
"author": "Renan de Mullenheim <renandemull@gmail.com>",
"license": "MIT",
"scripts": {
"start": "yarn config:dev && expo start -c",
"tsc": "node_modules/.bin/tsc --noEmit",
"tsc": "tsc --noEmit",
"bundle": "./scripts/gen_bundle_string.js",
"build": "yarn bundle && rm -rf lib/ && node_modules/.bin/tsc",
"config:dev": "json -I -f package.json -e 'this.main=\"node_modules/expo/AppEntry.js\"'",
Expand All @@ -31,37 +31,41 @@
],
"repository": {
"type": "git",
"url": "git+https://github.com/xcarpentier/rn-pdf-reader-js.git"
"url": "git+https://github.com/renishv8/rn-pdf-reader-js.git"
},
"peerDependencies": {
"expo": ">= 33.0.x < 41.0.x",
"expo": ">= 33.0.x <= 46.x",
"expo-constants": ">= 5.0.0 < 9.x",
"expo-file-system": ">= 5.0.0 < 9.x",
"react": "16.x",
"expo-file-system": ">= 5.0.0 <= 14.x",
"react": ">= 16.x <= 18.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.0.0",
"@types/react-dom": "~18.0.0",
"@types/react-native": "~0.69.1",
"babel-preset-expo": "~9.2.0",
"crypto": "^1.0.1",
"expo": "^46.0.0",
"expo-constants": "~13.2.4",
"expo-file-system": "~14.1.0",
"json": "^11.0.0",
"react": "18.0.0",
"react-native": "0.69.5",
"react-native-webview": "11.23.0",
"tslint": "^6.1.3",
"tslint-config-prettier": "^1.18.0",
"typescript": "3.7.4"
}
"typescript": "^4.6.3"
},
"bugs": {
"url": "https://github.com/renishv8/rn-pdf-reader-js/issues"
},
"homepage": "https://github.com/renishv8/rn-pdf-reader-js#readme"
}
4 changes: 2 additions & 2 deletions src/bundleContainer.ts

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class PdfReader extends React.Component<Props, State> {
case 'GOOGLE_DRIVE_VIEWER': {
break;
}

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

this.setState({ ready: true })
} catch (error) {
alert(`Sorry, an error occurred. ${error.message}`)
console.error(error)
} catch (e: any) {
alert(`Sorry, an error occurred. ${e.message}`)
console.error(e)
}
}

Expand Down Expand Up @@ -386,7 +386,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,9 +429,9 @@ class PdfReader extends React.Component<Props, State> {
) {
try {
removeFilesAsync()
} catch (error) {
alert(`Error on removing file. ${error.message}`)
console.error(error)
} catch (e: any) {
alert(`Error on removing file. ${e.message}`)
console.error(e)
}
}
}
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