Skip to content

Commit

Permalink
fix handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
xcarpentier committed Jan 7, 2020
1 parent f97b877 commit 0b8ef32
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 20 deletions.
55 changes: 38 additions & 17 deletions App.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import React from 'react'
import PdfReader from './src/'
import { WebViewErrorEvent } from 'react-native-webview/lib/WebViewTypes'
import { View, Text } from 'react-native'

const base64 =
'data:application/pdf;base64,JVBERi0xLjcKCjEgMCBvYmogICUgZW50cnkgcG9pbnQKPDwKICAvVHlwZSAvQ2F0YWxvZwog' +
Expand All @@ -16,25 +18,44 @@ const base64 =
'MDAwIG4gCjAwMDAwMDAzODAgMDAwMDAgbiAKdHJhaWxlcgo8PAogIC9TaXplIDYKICAvUm9v' +
'dCAxIDAgUgo+PgpzdGFydHhyZWYKNDkyCiUlRU9G'

export default class App extends React.Component {
render() {
function App() {
const [error, setError] = React.useState<WebViewErrorEvent | undefined>(
undefined,
)
if (error) {
return (
<PdfReader
source={{
// uri: 'http://gahp.net/wp-content/uploads/2017/09/sample.pdf',
base64,
<View
style={{
flex: 1,
justifyContent: 'center',
alignItems: 'center',
padding: 15,
}}
style={{ paddingTop: 20 }}
customStyle={{
readerContainerZoomContainer: {
borderRadius: 30,
backgroundColor: '#a0a',
},
readerContainerZoomContainerButton: {
borderRadius: 30,
},
}}
/>
>
<Text style={{ color: 'red', textAlign: 'center' }}>
{error.nativeEvent.description}
</Text>
</View>
)
}
return (
<PdfReader
source={{
uri: 'http://gahp.net/wp-content/uploads/2017/09/sample.pdf',
}}
onError={setError}
style={{ paddingTop: 20 }}
customStyle={{
readerContainerZoomContainer: {
borderRadius: 30,
backgroundColor: '#a0a',
},
readerContainerZoomContainerButton: {
borderRadius: 30,
},
}}
/>
)
}

export default App
10 changes: 7 additions & 3 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import * as CSS from 'csstype'
import { View, ActivityIndicator, Platform, StyleSheet } from 'react-native'
import { WebView } from 'react-native-webview'
import * as FileSystem from 'expo-file-system'
import {
WebViewErrorEvent,
WebViewNavigationEvent,
} from 'react-native-webview/lib/WebViewTypes'

const {
cacheDirectory,
Expand Down Expand Up @@ -147,9 +151,9 @@ interface Props {
webviewProps?: WebView['props']
noLoader?: boolean
customStyle?: CustomStyle
onLoad?(): void
onLoadEnd?(): void
onError?(): void
onLoad?(event: WebViewNavigationEvent): void
onLoadEnd?(event: WebViewNavigationEvent | WebViewErrorEvent): void
onError?(event: WebViewErrorEvent): void
}

interface State {
Expand Down

0 comments on commit 0b8ef32

Please sign in to comment.