Skip to content

Commit

Permalink
Fixed PDF not rendering on Android
Browse files Browse the repository at this point in the history
Issue was with WebView permissions not being set in time, fixed using react-native-webview/react-native-webview#656 (comment)
  • Loading branch information
ALEEF02 committed Nov 19, 2019
1 parent da41ff5 commit d3cdd63
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
4 changes: 2 additions & 2 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "The BullETin",
"slug": "BulletinMagExpo",
"privacy": "public",
"sdkVersion": "34.0.0",
"sdkVersion": "35.0.0",
"platforms": [
"ios",
"android"
Expand Down Expand Up @@ -49,7 +49,7 @@
"com.sec.android.provider.badge.permission.READ",
"com.sec.android.provider.badge.permission.WRITE",
"com.sonyericsson.home.permission.BROADCAST_BADGE"
],
]
},
"description": "The BullETin Magazine",
"githubUrl": "https://github.com/ALEEF02/Bulletin-Magazine-Mobile-App"
Expand Down
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"react-native-fetch-blob": "^0.10.8",
"react-native-gesture-handler": "~1.3.0",
"react-native-pdf": "^5.1.4",
"react-native-webview": "^7.5.1",
"react-native-webview": "^5.12.1",
"react-navigation": "^3.0.9",
"rn-fetch-blob": "^0.10.15",
"rn-pdf-reader-js": "^0.2.1"
Expand Down
10 changes: 6 additions & 4 deletions rn-pdf-reader-js/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ type State = {
}

class PdfReader extends Component<Props, State> {
state = { ready: false, android: false, ios: false, data: undefined }
state = { ready: false, android: false, ios: false, data: undefined, renderedOnce: false }

async init() {
try {
Expand Down Expand Up @@ -158,6 +158,7 @@ class PdfReader extends Component<Props, State> {
}

this.setState({ ready, data })
this.setState({ renderedOnce: true })
} catch (error) {
alert('Sorry, an error occurred.')
console.error(error)
Expand All @@ -176,7 +177,7 @@ class PdfReader extends Component<Props, State> {
}

render() {
const { ready, data, ios, android } = this.state
const { ready, data, ios, android, renderedOnce } = this.state
const { style } = this.props

if (data && ios) {
Expand All @@ -194,17 +195,18 @@ class PdfReader extends Component<Props, State> {
}

if (ready && data && android) {
console.log("Rendering Android...\n" + htmlPath + "\n" + JSON.stringify(styles.container));
console.log("Rendering Android...\n" + htmlPath + "\n" + JSON.stringify(styles.container) + "\nRendered Once: " + renderedOnce);
return (
<View style={[styles.container, style]}>
<WebView
allowFileAccess={true}
allowContentAccess={true}
allowFileAccessFromFileURLs={true}
allowUniversalAccessFromFileURLs={true}
domStorageEnabled={true}
androidHardwareAccelerationDisabled={true}
style={styles.webview}
source={{ uri: htmlPath }}
source={renderedOnce ? { uri: htmlPath } : undefined}
originWhitelist={["*"]}
mixedContentMode="always"
/>
Expand Down

0 comments on commit d3cdd63

Please sign in to comment.