Gathering detailed insights and metrics for react-native-file-viewer
Gathering detailed insights and metrics for react-native-file-viewer
Gathering detailed insights and metrics for react-native-file-viewer
Gathering detailed insights and metrics for react-native-file-viewer
@react-native-oh-tpl/react-native-file-viewer
Native file viewer for react-native
react-native-file-viewer-turbo
Native file viewer for react-native - now with TurboModules support
react-native-file-viewer-mod
Native file viewer for react-native
react-native-files-viewer
React Native Native Module Bridge Quicklock Document Viewer for IOS + Android supports pdf, png, jpg, xls, ppt, doc, docx, pptx, xlx + Video Player mp4 supported
Native file viewer for React Native. Preview any type of file supported by the mobile device.
npm install react-native-file-viewer
Typescript
Module System
Node Version
NPM Version
Java (36.98%)
Objective-C (27.86%)
C# (21.96%)
JavaScript (8.93%)
Ruby (4.27%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
442 Stars
86 Commits
108 Forks
4 Watchers
5 Branches
15 Contributors
Updated on Jul 09, 2025
Latest Version
2.1.5
Package Id
react-native-file-viewer@2.1.5
Unpacked Size
53.75 kB
Size
15.40 kB
File Count
23
NPM Version
6.14.14
Node Version
14.17.5
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
1
Native file viewer for react-native. Preview any type of file supported by the mobile device.
iOS: it uses QuickLook Framework
Android: it uses ACTION_VIEW
Intent to start the default app associated with the specified file.
Windows: Start the default app associated with the specified file.
$ npm install react-native-file-viewer --save
or
$ yarn add react-native-file-viewer
# RN >= 0.60
cd ios && pod install
# RN < 0.60
react-native link react-native-file-viewer
If your app is targeting Android 11 (API level 30) or newer, the following extra step is required, as described in Declaring package visibility needs and Package visibility in Android 11.
Specifically:
If your app targets Android 11 or higher and needs to interact with apps other than the ones that are visible automatically, add the
element in your app's manifest file. Within the element, specify the other apps by package name, by intent signature, or by provider authority, as described in the following sections.
For example, if you know upfront that your app is supposed to open PDF files, the following lines should be added to your AndroidManifest.xml
.
1 ... 2 </application> 3+ <queries> 4+ <intent> 5+ <action android:name="android.intent.action.VIEW" /> 6+ <!-- If you don't know the MIME type in advance, set "mimeType" to "*/*". --> 7+ <data android:mimeType="application/pdf" /> 8+ </intent> 9+ </queries> 10</manifest>
IMPORTANT: Try to be as granular as possible when defining your own queries. This might affect your Play Store approval, as mentioned in Package visibility filtering on Android.
If you publish your app on Google Play, your app's use of this permission is subject to approval based on an upcoming policy.
If your project is based on Expo, you need to eject your project by switching to the Bare workflow, in order to use this library.
Add the following to your Podfile:
pod 'RNFileViewer', :path => '../node_modules/react-native-file-viewer'
Libraries
➜ Add Files to [your project's name]
node_modules
➜ react-native-file-viewer
and add RNFileViewer.xcodeproj
libRNFileViewer.a
to your project's Build Phases
➜ Link Binary With Libraries
Cmd+R
)android/app/src/main/java/[...]/MainApplication.java
import com.vinzscam.reactnativefileviewer.RNFileViewerPackage;
to the imports at the top of the filenew RNFileViewerPackage()
to the list returned by the getPackages()
methodAppend the following lines to android/settings.gradle
:
include ':react-native-file-viewer'
project(':react-native-file-viewer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-file-viewer/android')
Insert the following lines inside the dependencies block in android/app/build.gradle
:
compile project(':react-native-file-viewer')
Locate react-native-file-viewer
inside node_modules
folder and copy android/src/main/res/xml/file_viewer_provider_paths.xml
to your project res/xml/
directory
Add the following lines to AndroidManifest.xml
between the main <application></application>
tag:
...
<application>
...
<provider
android:name="com.vinzscam.reactnativefileviewer.FileProvider"
android:authorities="${applicationId}.provider"
android:exported="false"
android:grantUriPermissions="true">
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_viewer_provider_paths"
/>
</provider>
</application>
....
Follow the instructions in the 'Linking Libraries' documentation on the react-native-windows GitHub repo. For the first step of adding the project to the Visual Studio solution file, the path to the project should be ../node_modules/react-native-file-viewer/windows/RNFileViewer/RNFileViewer.csproj
.
1import FileViewer from "react-native-file-viewer"; 2 3const path = FileViewer.open(path) // absolute-path-to-my-local-file. 4 .then(() => { 5 // success 6 }) 7 .catch((error) => { 8 // error 9 });
1import FileViewer from "react-native-file-viewer"; 2import DocumentPicker from "react-native-document-picker"; 3 4try { 5 const res = await DocumentPicker.pick({ 6 type: [DocumentPicker.types.allFiles], 7 }); 8 await FileViewer.open(res.uri); 9} catch (e) { 10 // error 11}
1import FileViewer from "react-native-file-viewer"; 2import ImagePicker from "react-native-image-crop-picker"; 3 4ImagePicker.openPicker({}) 5 .then((image) => FileViewer.open(image.path)) 6 .catch((error) => { 7 // error 8 });
1import FileViewer from "react-native-file-viewer"; 2 3const path = FileViewer.open(path, { showOpenWithDialog: true }) // absolute-path-to-my-local-file. 4 .then(() => { 5 // success 6 }) 7 .catch((error) => { 8 // error 9 });
Since the library works only with absolute paths and Android assets folder doesn't have any absolute path, the file needs to be copied first. Use copyFileAssets of react-native-fs.
Example (using react-native-fs):
1import FileViewer from "react-native-file-viewer"; 2import RNFS from "react-native-fs"; 3 4const file = "file-to-open.doc"; // this is your file name 5 6// feel free to change main path according to your requirements 7const dest = `${RNFS.DocumentDirectoryPath}/${file}`; 8 9RNFS.copyFileAssets(file, dest) 10 .then(() => FileViewer.open(dest)) 11 .then(() => { 12 // success 13 }) 14 .catch((error) => { 15 /* */ 16 });
No function about file downloading has been implemented in this package. Use react-native-fs or any similar library for this purpose.
Example (using react-native-fs):
1import RNFS from "react-native-fs"; 2import FileViewer from "react-native-file-viewer"; 3import { Platform } from "react-native"; 4 5const url = 6 "https://github.com/vinzscam/react-native-file-viewer/raw/master/docs/react-native-file-viewer-certificate.pdf"; 7 8// *IMPORTANT*: The correct file extension is always required. 9// You might encounter issues if the file's extension isn't included 10// or if it doesn't match the mime type of the file. 11// https://stackoverflow.com/a/47767860 12function getUrlExtension(url) { 13 return url.split(/[#?]/)[0].split(".").pop().trim(); 14} 15 16const extension = getUrlExtension(url); 17 18// Feel free to change main path according to your requirements. 19const localFile = `${RNFS.DocumentDirectoryPath}/temporaryfile.${extension}`; 20 21const options = { 22 fromUrl: url, 23 toFile: localFile, 24}; 25RNFS.downloadFile(options) 26 .promise.then(() => FileViewer.open(localFile)) 27 .then(() => { 28 // success 29 }) 30 .catch((error) => { 31 // error 32 });
open(filepath: string, options?: Object): Promise<void>
Parameter | Type | Description |
---|---|---|
filepath | string | The absolute path where the file is stored. The file needs to have a valid extension to be successfully detected. Use react-native-fs constants to determine the absolute path correctly. |
options (optional) | Object | Some options to customize the behaviour. See below. |
Parameter | Type | Description |
---|---|---|
displayName (optional) | string | Customize the QuickLook title (iOS only). |
onDismiss (optional) | function | Callback invoked when the viewer is being dismissed (iOS and Android only). |
showOpenWithDialog (optional) | boolean | If there is more than one app that can open the file, show an Open With dialogue box (Android only). |
showAppsSuggestions (optional) | boolean | If there is not an installed app that can open the file, open the Play Store with suggested apps (Android only). |
The library supports Android X and React Native 0.60+.
If you're using React Native < 0.60, please append the following snippet to your android/app/build.gradle
file:
preBuild.doFirst {
ant.replaceregexp(match:'androidx.core.content.', replace:'android.support.v4.content.', flags:'g', byline:true) {
fileset(dir: '../../node_modules/react-native-file-viewer/android/src/main/java/com/vinzscam/reactnativefileviewer', includes: '*.java')
}
}
If you prefer to not touch your gradle file, you can still use version 1.0.15
which is perfectly compatible.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
0 existing vulnerabilities detected
Reason
Found 2/26 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More