Skip to content

Commit

Permalink
feat: new render type google drive viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
muhammadady07 authored and xcarpentier committed Apr 12, 2021
1 parent a603099 commit d660e8a
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export type RenderType =
| 'BASE64_TO_LOCAL_PDF'
| 'URL_TO_BASE64'
| 'GOOGLE_READER'
| 'GOOGLE_DRIVE_VIEWER';

export interface CustomStyle {
readerContainer?: CSS.Properties<any>
Expand All @@ -50,6 +51,7 @@ export interface Props {
noLoader?: boolean
customStyle?: CustomStyle
useGoogleReader?: boolean
useGoogleDriveViewer?: boolean
withScroll?: boolean
withPinchZoom?: boolean
maximumPinchZoomScale?: number
Expand Down Expand Up @@ -224,6 +226,8 @@ async function urlToBlob(source: Source): Promise<Blob | undefined> {

const getGoogleReaderUrl = (url: string) =>
`https://docs.google.com/viewer?url=${url}`
const getGoogleDriveUrl = (url: string) =>
`https://drive.google.com/viewerng/viewer?embedded=true&url=${url}`

const Loader = () => (
<View
Expand Down Expand Up @@ -259,6 +263,7 @@ class PdfReader extends React.Component<Props, State> {
} else if (
(renderType === 'DIRECT_URL' ||
renderType === 'GOOGLE_READER' ||
renderType === 'GOOGLE_DRIVE_VIEWER' ||
renderType === 'URL_TO_BASE64') &&
(!source.uri ||
!(
Expand Down Expand Up @@ -293,6 +298,10 @@ class PdfReader extends React.Component<Props, State> {
} = this.props
const { renderType } = this.state
switch (renderType!) {
case 'GOOGLE_DRIVE_VIEWER': {
break;
}

case 'URL_TO_BASE64': {
const data = await fetchPdfAsync(source)
await writeWebViewReaderFileAsync(
Expand Down Expand Up @@ -335,13 +344,18 @@ class PdfReader extends React.Component<Props, State> {
getRenderType = () => {
const {
useGoogleReader,
useGoogleDriveViewer,
source: { uri, base64 },
} = this.props

if (useGoogleReader) {
return 'GOOGLE_READER'
}

if (useGoogleDriveViewer) {
return 'GOOGLE_DRIVE_VIEWER';
}

if (Platform.OS === 'ios') {
if (uri !== undefined) {
return 'DIRECT_URL'
Expand Down Expand Up @@ -371,6 +385,8 @@ class PdfReader extends React.Component<Props, State> {
switch (renderType!) {
case 'GOOGLE_READER':
return { uri: getGoogleReaderUrl(uri!) }
case 'GOOGLE_DRIVE_VIEWER':
return { uri: getGoogleDriveUrl(uri) };
case 'DIRECT_BASE64':
case 'URL_TO_BASE64':
return { uri: htmlPath }
Expand Down

0 comments on commit d660e8a

Please sign in to comment.