How To Create React Native File Viewer?

React Native is a framework for building native mobile applications using JavaScript and the React framework. To display a file using React Native, you can use the react-native-file-viewer library. Here's an example of how you can use it:

  1. Install the library:

npm install react-native-file-viewer

or

yarn add react-native-file-viewer

2. Link the library to your project:

react-native link react-native-file-viewer

3. Import the library in your code:

import FileViewer from 'react-native-file-viewer';

4. Use the open function to display the file:

const filePath = '/path/to/file.pdf';

FileViewer.open(filePath)
  .then(() => {
    // success
  })
  .catch(error => {
    // error
  });

This will open the file in the default viewer for the file type on the user's device. If the file type is not supported by the device, the promise returned by open will be rejected with an error.

Note: If you are using Android, you will need to add a file provider to your AndroidManifest.xml file in order to use the react-native-file-viewer library. You can find more information on how to do this in the library's documentation.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to Lxadm.com.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.