react-native-doc-viewer
A React Native bridge module: Document Viewer for files (pdf, png, jpg, xls, doc, ppt, xlsx, docx, pptx etc.)
2017 Roadmap
- Download Progess Event Listener for big Files Android
2018 Roadmap
- Android file without external Application
- Windows Phone Support
IMPORTANT INFORMATION: THIS IS A OPEN SOURCE PROJECT, SOMETIMES I HAVE NO TIME TO DEVELOP THIS PROJECT. THANK YOU FOR YOUR PULL REQUEST AND YOUR SUPPORT. I will continue to develop it as it is possible in time.
Changelog:
2.7.8 - XLS Exmaple Local File IOS 97-2003
2.7.7 - "react": "^16.3.0-alpha.1","react-native": "0.54.3"
2.7.5 - Pull Request local file from LeMinh1995 + Pull Request podspec Form Linh1987
2.7.3 - Example Local File
2.7.2 - Progress Download Feedback in example and Done Button Callback IOS
2.7.1 - Fix Progress IOS Download
2.6.9 - Progress IOS DOWNLOAD Document Callback in Native Code
2.6.0 - Android Openbase64
2.5.2 - OpenDocAndroid
2.5.1 - Cleanings
2.5.0 - Update Project for React Native 0.50.3
Getting started
$ npm install react-native-doc-viewer --save
Automatic installation
$ react-native link react-native-doc-viewer
CocoaPods installation
If your project uses CocoaPods to manage React installation (especially with Expo-detached project), most likely you will run into issue with header files not found as described here (https://docs.expo.io/versions/latest/guides/expokit.html#changing-native-dependencies "Changing Native Dependencies"). It will be helpful to follow these steps to have it compiled successfully:
-
npm install react-native-doc-viewer --save
-
Add the plugin dependency to your Podfile, pointing at the path where NPM installed it:
pod 'RNReactNativeDocViewer', path: '../node_modules/react-native-doc-viewer'
- Run
pod install
Manual installation
iOS
-
In XCode, in the project navigator, right click
Libraries
➜Add Files to [your project's name]
-
Go to
node_modules
➜react-native-doc-viewer
and addRNReactNativeDocViewer.xcodeproj
-
In XCode, in the project navigator, select your project. Add
libRNReactNativeDocViewer.a
to your project'sBuild Phases
➜Link Binary With Libraries
-
Linked Frameworks and Libraries must have this 2 Libraries (AssetsLibrary.framework & QuickLock.framework). When not you have to add them.
-
When you Show http Links don't forget to set APP Transport Security Settings -> Allow Arbitrary Loads to YES
- Run your project (
Cmd+R
)<
Android
- Open up
android/app/src/main/java/[...]/MainApplication.java
- Add
import com.reactlibrary.RNReactNativeDocViewerPackage;
to the imports at the top of the file - Add
new RNReactNativeDocViewerPackage()
to the list returned by thegetPackages()
method
- Append the following lines to
android/settings.gradle
:include ':react-native-doc-viewer' project(':react-native-doc-viewer').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-doc-viewer/android')
- Insert the following lines inside the dependencies block in
android/app/build.gradle
:compile project(':react-native-doc-viewer')
Windows on the Roadmap
- In Visual Studio add the
RNReactNativeDocViewer.sln
innode_modules/react-native-react-native-doc-viewer/windows/RNReactNativeDocViewer.sln
folder to their solution, reference from their app. - Open up your
MainPage.cs
app
- Add
using Com.Reactlibrary.RNReactNativeDocViewer;
to the usings at the top of the file - Add
new RNReactNativeDocViewerPackage()
to theList<IReactPackage>
returned by thePackages
method
API DOC
IOS Document Viewer Doc
resource | description |
---|---|
DoneButtonEvent |
return true |
RNDownloaderProgress |
return Progress Float |
resource | description |
---|---|
openDoc |
{url:String,fileNameOptional:String (optional)} |
openDocb64 |
{url:String,fileName:String,fileType:String } |
openDocBinaryinUrl |
{url:String,fileName:String,fileType:String } |
Android Document Viewer Doc
resource | description |
---|---|
openDoc |
{url:String,fileName:String, cache:boolean} |
openDocb64 |
{url:String,fileName:String,fileType:String, cache:boolean } |
openDocBinaryinUrl |
not implemented yet |
Usage
;;;var RNFS = ;var SavePath = PlatformOS === 'ios' ? RNFSMainBundlePath : RNFSDocumentDirectoryPath; { superprops; thisstate = animating: false progress: "" donebuttonclicked: false thiseventEmitter = NativeModulesRNReactNativeDocViewer; thiseventEmitter thisdidPressToObjcButton = thisdidPressToObjcButton; } { // download progress thiseventEmitter; } { thiseventEmitter; } /* * Handle WWW File Method * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url the File Extension is missing. */ { ifPlatformOS === 'ios' //IOS OpenFile else //Android OpenFile } /* * Binary in URL * Binary String in Url * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url you dont have an File Extensions */ { ifPlatformOS === 'ios' //IOS OpenFile else //Android Alert } /* * Handle local File Method * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url you dont have an File Extensions */ { ifPlatformOS === 'ios' OpenFile else //Android OpenFile } /* * Base64String * put only the base64 String without data:application/octet-stream;base64 * fileType Default == "" you can use it, to set the File Extension (pdf,doc,xls,ppt etc) when in the Url you dont have an File Extensions */ { ifPlatformOS === 'ios' OpenFile else //Android OpenFile /* * Video File */ { ifPlatformOS === 'ios' OpenFile else Alert; } <Button onPress=thishandlePress title="Press Me Open Doc Url" accessibilityLabel="See a Document" /> <Button onPress=thishandlePressBinaryinUrl title="Press Me Open BinaryinUrl" accessibilityLabel="See a Document" /> <Button onPress=thishandlePressb64 title="Press Me Open Base64 String" accessibilityLabel="See a Document" /> <Button onPress=this title="Press Me Open Video" accessibilityLabel="See a Document" />}
Screenshots
Copyright (c) 2017-present, Philipp Hecht philipp.hecht@icloud.com
Donation
If this project help you reduce time to develop, you can give me a cup of coffee :)
Bitcoin wallet: 122dhCT98R6jrP5ahCKMRA1UupawtU9cVP
Etherum wallet: 0x68b93b03eb61a27b125416a5963f1e17c3ebad21