Document Viewer
The viewer module is designed to work with the files that the document picker module returns. It supports both uri and bookmark coming from open and import modes, also supports virtual files and long-term access to the files.
The call to viewDocument returns a promise that resolves with null in case of success or rejects with an error. It is a "fire-and-forget" function, meaning that the promise resolves right after the package asks the OS to present the preview.
How it works
- Android
- iOS
viewDocument uses Intent.ACTION_VIEW internally.
viewDocument uses the QuickLook framework internally.
View a document given a uri
Uri would come from the open or import modes of the document picker.
See more in the API reference
import { viewDocument } from '@react-native-documents/viewer'
return (
<Button
title="view the last imported file"
onPress={() => {
const uriToOpen = 'file:///path/to/your/file'
viewDocument({ uri: uriToOpen, mimeType: 'some-mime' }).catch(handleError)
}}
/>
)
View a document given a bookmark
bookmark would come from the open mode, with the requestLongTermAccess option set to true.
See more in the API reference
import { viewDocument } from '@react-native-documents/viewer'
return (
<Button
title="view the last imported file"
onPress={() => {
const bookmark = '...'
viewDocument({ bookmark }).catch(handleError)
}}
/>
)