├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ └── bug_report.md └── workflows │ ├── jsBuilder.yml │ └── npm_publish.yml ├── .gitignore ├── .hygen.js ├── .npmignore ├── API.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── RNPdftron.podspec ├── _templates ├── generator │ ├── help │ │ └── index.ejs.t │ ├── new │ │ └── hello.ejs.t │ └── with-prompt │ │ ├── hello.ejs.t │ │ └── prompt.js ├── listener-generator │ └── new │ │ ├── ConstantsjavaEvent.ejs.t │ │ ├── ConstantsjavaKey.ejs.t │ │ ├── DocumentViewjava.ejs.t │ │ ├── DocumentViewtsxOnChange.ejs.t │ │ ├── DocumentViewtsxProp.ejs.t │ │ ├── RNTPTDocumentViewManagerm.ejs.t │ │ ├── RNTPTDocumentViewh.ejs.t │ │ └── index.js ├── method-generator │ └── new │ │ ├── DocumentViewModule.ejs.t │ │ ├── DocumentViewViewManagerjava.ejs.t │ │ ├── DocumentViewjava.ejs.t │ │ ├── DocumentViewtsx.ejs.t │ │ ├── RNTPTDocumentViewManagerh.ejs.t │ │ ├── RNTPTDocumentViewManagerm.ejs.t │ │ ├── RNTPTDocumentViewModulem.ejs.t │ │ ├── RNTPTDocumentViewh.ejs.t │ │ ├── RNTPTDocumentViewm.ejs.t │ │ └── index.js └── prop-generator │ └── new │ ├── DocumentViewJava.ejs.t │ ├── DocumentViewViewManagerJava.ejs.t │ ├── DocumentViewtsx.ejs.t │ ├── RNTPTDocumentViewManager.ejs.t │ ├── RNTPTDocumentViewh.ejs.t │ ├── RNTPTDocumentViewm.ejs.t │ └── index.js ├── android ├── README.md ├── build.gradle └── src │ └── main │ ├── AndroidManifest.xml │ ├── java │ └── com │ │ └── pdftron │ │ └── reactnative │ │ ├── RNPdftronPackage.java │ │ ├── modules │ │ ├── DocumentViewModule.java │ │ └── RNPdftronModule.java │ │ ├── nativeviews │ │ ├── RNCollabViewerTabHostFragment.java │ │ ├── RNPdfViewCtrlTabFragment.java │ │ └── RNPdfViewCtrlTabHostFragment.java │ │ ├── utils │ │ ├── Constants.java │ │ ├── DocumentViewUtils.kt │ │ └── ReactUtils.java │ │ ├── viewmanagers │ │ ├── DocumentViewViewManager.java │ │ └── PDFViewCtrlViewManager.java │ │ └── views │ │ ├── DocumentView.java │ │ └── PDFViewCtrlView.java │ └── res │ └── values │ ├── arrays.xml │ └── styles.xml ├── application.properties ├── example ├── .buckconfig ├── .bundle │ └── config ├── .eslintrc.js ├── .flowconfig ├── .gitignore ├── .prettierrc.js ├── .ruby-version ├── .watchmanconfig ├── App.js ├── Gemfile ├── README.md ├── __tests__ │ └── App-test.js ├── android │ ├── app │ │ ├── _BUCK │ │ ├── build.gradle │ │ ├── build_defs.bzl │ │ ├── debug.keystore │ │ ├── proguard-rules.pro │ │ └── src │ │ │ ├── debug │ │ │ ├── AndroidManifest.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── example │ │ │ │ └── ReactNativeFlipper.java │ │ │ └── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── java │ │ │ └── com │ │ │ │ └── example │ │ │ │ ├── MainActivity.java │ │ │ │ ├── MainApplication.java │ │ │ │ └── newarchitecture │ │ │ │ ├── MainApplicationReactNativeHost.java │ │ │ │ ├── components │ │ │ │ └── MainComponentsRegistry.java │ │ │ │ └── modules │ │ │ │ └── MainApplicationTurboModuleManagerDelegate.java │ │ │ ├── jni │ │ │ ├── Android.mk │ │ │ ├── MainApplicationModuleProvider.cpp │ │ │ ├── MainApplicationModuleProvider.h │ │ │ ├── MainApplicationTurboModuleManagerDelegate.cpp │ │ │ ├── MainApplicationTurboModuleManagerDelegate.h │ │ │ ├── MainComponentsRegistry.cpp │ │ │ ├── MainComponentsRegistry.h │ │ │ └── OnLoad.cpp │ │ │ └── res │ │ │ ├── drawable │ │ │ └── rn_edit_text_material.xml │ │ │ ├── mipmap-hdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-mdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── mipmap-xxxhdpi │ │ │ ├── ic_launcher.png │ │ │ └── ic_launcher_round.png │ │ │ ├── raw │ │ │ └── getting_started.pdf │ │ │ └── values │ │ │ ├── strings.xml │ │ │ └── styles.xml │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle ├── app.json ├── babel.config.js ├── index.js ├── ios │ ├── .xcode.env │ ├── Podfile │ ├── example.xcodeproj │ │ ├── project.pbxproj │ │ └── xcshareddata │ │ │ └── xcschemes │ │ │ └── example.xcscheme │ ├── example │ │ ├── AppDelegate.h │ │ ├── AppDelegate.mm │ │ ├── Images.xcassets │ │ │ ├── AppIcon.appiconset │ │ │ │ └── Contents.json │ │ │ ├── Contents.json │ │ │ └── ic_close_black_24px.imageset │ │ │ │ ├── Contents.json │ │ │ │ ├── ic_close_black_24px.png │ │ │ │ ├── ic_close_black_24px@2x.png │ │ │ │ └── ic_close_black_24px@3x.png │ │ ├── Info.plist │ │ ├── LaunchScreen.storyboard │ │ └── main.m │ ├── exampleTests │ │ ├── Info.plist │ │ └── exampleTests.m │ ├── getting_started.pdf │ ├── ic_close_black_24px.png │ ├── ic_close_black_24px@2x.png │ └── ic_close_black_24px@3x.png ├── metro.config.js └── package.json ├── index.ts ├── ios ├── DocumentViewController │ ├── RNTPTCollaborationDocumentController.h │ ├── RNTPTCollaborationDocumentController.m │ ├── RNTPTCollaborationDocumentViewController.h │ ├── RNTPTCollaborationDocumentViewController.m │ ├── RNTPTDocumentController.h │ ├── RNTPTDocumentController.m │ ├── RNTPTDocumentViewController.h │ └── RNTPTDocumentViewController.m ├── RNPdftron.h ├── RNPdftron.m ├── RNPdftron.xcodeproj │ └── project.pbxproj ├── RNTPTDocumentView.h ├── RNTPTDocumentView.m ├── RNTPTDocumentViewManager.h ├── RNTPTDocumentViewManager.m ├── RNTPTDocumentViewModule.h ├── RNTPTDocumentViewModule.m ├── RNTPTNavigationController.h ├── RNTPTNavigationController.m ├── RNTPTPDFViewCtrl.h ├── RNTPTPDFViewCtrl.m ├── RNTPTPDFViewCtrlManager.h └── RNTPTPDFViewCtrlManager.m ├── lib ├── index.js └── src │ ├── AnnotOptions │ └── AnnotOptions.js │ ├── Config │ └── Config.js │ ├── DocumentView │ └── DocumentView.js │ └── PDFViewCtrl │ └── PDFViewCtrl.js ├── package-lock.json ├── package.json ├── polaris.yml ├── scripts ├── README.md ├── fileCopy.py ├── ios │ └── run_polaris.sh ├── newPodspecMessage.py ├── postpublish.sh ├── prepare.sh └── update_version.js ├── src ├── AnnotOptions │ └── AnnotOptions.ts ├── Config │ └── Config.ts ├── DocumentView │ └── DocumentView.tsx ├── PDFViewCtrl │ └── PDFViewCtrl.tsx └── index.d.ts └── tsconfig.json /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | 12 | 13 | **Steps to Reproduce the Problem** 14 | 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | 22 | 23 | **Screenshots** 24 | 25 | 26 | **Platform/Device Information (please complete the following information if applicable):** 27 | - Platform:[e.g. iOS or Android] 28 | - Device: [e.g. iPhone6, Google Pixel 4] 29 | - OS: [e.g. iOS8.1, Android Nougat] 30 | 31 | **Additional context** 32 | 33 | -------------------------------------------------------------------------------- /.github/workflows/jsBuilder.yml: -------------------------------------------------------------------------------- 1 | name: Transpile TS and Update package.json 2 | 3 | on: 4 | pull_request: 5 | branches: [master] 6 | 7 | jobs: 8 | transpile-ts: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - name: Checkout repository 13 | uses: actions/checkout@v2 14 | with: 15 | persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token. 16 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo. 17 | ref: ${{ github.event.pull_request.head.sha }} # checks out the branch being merged into `master` 18 | 19 | - name: Node setup 20 | uses: actions/setup-node@v2 21 | with: 22 | node-version: '16' 23 | # cache: 'npm' 24 | 25 | - name: Install dependencies 26 | run: | 27 | npm i @types/react-native@0.68.1 --save-dev 28 | npm i react-native@0.68.2 29 | 30 | - name: Build JavaScript files 31 | run: | # Change line to your build script command. 32 | npm run start 33 | 34 | - name: Force add JS files to override .gitignore 35 | run: git add --force ./lib # <-- Change this to your build path. 36 | 37 | - name: Commit files 38 | run: | # Change last line to your preferred commit message (I like `chore: build js files`). 39 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 40 | git config --local user.name "github-actions[bot]" 41 | git commit -m "Updating JS files" || echo "No commit needed. JS files are already up-to-date" 42 | 43 | - name: Push changes 44 | uses: ad-m/github-push-action@v0.6.0 45 | with: 46 | github_token: ${{ secrets.GITHUB_TOKEN }} 47 | branch: ${{ github.event.pull_request.head.ref }} # pushes the commit to the branch being merged into `master` 48 | 49 | package-json-update: 50 | needs: transpile-ts 51 | runs-on: ubuntu-latest 52 | 53 | steps: 54 | - name: Checkout repository 55 | uses: actions/checkout@v2 56 | with: 57 | persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token. 58 | fetch-depth: 0 # otherwise, you will failed to push refs to dest repo. 59 | ref: ${{ github.event.pull_request.head.sha }} # checks out the branch being merged into `master` 60 | 61 | - name: Node setup 62 | uses: actions/setup-node@v2 63 | with: 64 | node-version: 16 65 | registry-url: https://registry.npmjs.org/ 66 | 67 | - name: Get Latest package.json 68 | run: | 69 | git pull origin ${{ github.head_ref }} 70 | git checkout origin/master package.json 71 | 72 | - name: Update package.json 73 | run: node scripts/update_version.js 74 | 75 | - name: Commit files 76 | run: | # Change last line to your preferred commit message (I like `chore: build js files`). 77 | git add package.json 78 | git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" 79 | git config --local user.name "github-actions[bot]" 80 | git commit -m "Updating package version" || echo "No commit needed. Package.json is already up-to-date" 81 | 82 | - name: Push changes 83 | uses: ad-m/github-push-action@v0.6.0 84 | with: 85 | github_token: ${{ secrets.GITHUB_TOKEN }} 86 | branch: ${{ github.event.pull_request.head.ref }} # pushes the commit to the branch being merged into `master` 87 | -------------------------------------------------------------------------------- /.github/workflows/npm_publish.yml: -------------------------------------------------------------------------------- 1 | # This workflow will publish a package to GitHub Packages when a release is created 2 | # For more information see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages 3 | 4 | name: NPM Publish 5 | 6 | on: 7 | push: 8 | branches: 9 | - master 10 | 11 | jobs: 12 | build: 13 | if: github.repository == 'ApryseSDK/pdftron-react-native' 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v2 17 | - uses: actions/setup-node@v2 18 | with: 19 | node-version: 16 20 | 21 | publish-npm: 22 | needs: build 23 | runs-on: ubuntu-latest 24 | steps: 25 | - uses: actions/checkout@v2 26 | - uses: actions/setup-node@v2 27 | with: 28 | node-version: 16 29 | registry-url: https://registry.npmjs.org/ 30 | 31 | - run: npm install json 32 | 33 | - name: Publish Package 34 | run: npm publish --access public 35 | env: 36 | NODE_AUTH_TOKEN: ${{secrets.NPM_AUTH_TOKEN}} 37 | 38 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # OSX 3 | # 4 | .DS_Store 5 | 6 | # node.js 7 | # 8 | node_modules/ 9 | npm-debug.log 10 | yarn-error.log 11 | 12 | 13 | # Xcode 14 | # 15 | build/ 16 | Pods/ 17 | *.pbxuser 18 | !default.pbxuser 19 | *.mode1v3 20 | !default.mode1v3 21 | *.mode2v3 22 | !default.mode2v3 23 | *.perspectivev3 24 | !default.perspectivev3 25 | xcuserdata 26 | *.xccheckout 27 | *.moved-aside 28 | DerivedData 29 | *.hmap 30 | *.ipa 31 | *.xcuserstate 32 | *.xcworkspace 33 | project.xcworkspace 34 | 35 | 36 | # Android/IntelliJ 37 | # 38 | build/ 39 | .idea 40 | .gradle 41 | local.properties 42 | *.iml 43 | 44 | # BUCK 45 | buck-out/ 46 | \.buckd/ 47 | *.keystore 48 | 49 | example/android/app/src/main/assets/index.android.bundle 50 | example/android/app/src/main/assets/index.android.bundle.meta 51 | 52 | # Build 53 | /lib -------------------------------------------------------------------------------- /.hygen.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | helpers: { 3 | /** 4 | * Converts the parameter list of a React Native function into a parameter list of an Android function. 5 | * e.g. 'flag: boolean, page: int' => 'boolean flag, int page' or 'final boolean flag, final int page' 6 | * @param params React Native parameter list string 7 | * @param setFinal Whether to add the 'final' keyword in front of each parameter 8 | * @returns {string} Android parameter list string 9 | */ 10 | androidParams: (params, setFinal) => { 11 | let arguments = '' 12 | let finalWord = setFinal ? 'final ' : '' 13 | 14 | // assuming no nested maps, remove the params inside maps (in between {} or Record<>) 15 | // so that the top level parameters can be properly split by commas 16 | params = params.replace(/((?<=\{)(.*?)(?=}))|((?<=Record<)(.*?)(?=>))/g, '') 17 | 18 | params.split(',').forEach(param => { 19 | let name = param.substring(0, param.indexOf(':')).trim() 20 | let type = param.substring(param.indexOf(':') + 1).trim() 21 | 22 | if ((type.startsWith('{') && type.endsWith('}')) || 23 | (type.startsWith('Record<') && type.endsWith('>')) || 24 | type.startsWith('AnnotOptions.')) { 25 | type = 'ReadableMap' 26 | } else if (type.startsWith('Config.') || type === 'string') { 27 | type = 'String' 28 | } else if (type.startsWith('Array<') && type.endsWith('>')) { 29 | type = 'ReadableArray' 30 | } 31 | 32 | arguments += finalWord + type + ' ' + name + ', ' 33 | }) 34 | 35 | arguments = arguments.substring(0, arguments.length - 2) 36 | return arguments 37 | }, 38 | /** 39 | * Converts the parameter list of a React Native function into a parameter list of an iOS function. 40 | * e.g. 'flag: boolean, page: int' => 'flag:(BOOL)flag page:(NSInteger)page' 41 | * @param params React Native parameter list string 42 | * @param format Whether to separate each parameter by newlines 43 | * @returns {string} iOS parameter list string 44 | */ 45 | iOSParams: (params, format) => { 46 | let arguments = '' 47 | let formatStr = format ? '\n ' : ' ' 48 | 49 | params = params.replace(/((?<=\{)(.*?)(?=}))|((?<=Record<)(.*?)(?=>))/g, '') 50 | 51 | params.split(',').forEach(param => { 52 | let name = param.substring(0, param.indexOf(':')).trim() 53 | let type = param.substring(param.indexOf(':') + 1).trim() 54 | 55 | if ((type.startsWith('{') && type.endsWith('}')) || 56 | (type.startsWith('Record<') && type.endsWith('>')) || 57 | type.startsWith('AnnotOptions.')) { 58 | type = 'NSDictionary *' 59 | } else if (type === 'boolean') { 60 | type = 'BOOL' 61 | } else if (type === 'int') { 62 | type = 'NSInteger' 63 | } else if (type.startsWith('Config.') || type === 'string') { 64 | type = 'NSString *' 65 | } else if (type.startsWith('Array<') && type.endsWith('>')) { 66 | type = 'NSArray *' 67 | } 68 | 69 | arguments += name + ':(' + type + ')' + name + formatStr 70 | }) 71 | 72 | arguments = arguments.substring(0, arguments.length - formatStr.length) 73 | return arguments 74 | }, 75 | /** 76 | * Converts the parameter list of a React Native function into arguments when calling an Android function. 77 | * e.g. 'flag: boolean, page: int' => 'flag, page' 78 | * @param params React Native parameter list string 79 | * @returns {string} Android arguments string 80 | */ 81 | androidArgs: params => { 82 | let arguments = '' 83 | 84 | params = params.replace(/((?<=\{)(.*?)(?=}))|((?<=Record<)(.*?)(?=>))/g, '') 85 | 86 | params.split(',').forEach(param => { 87 | arguments += param.substring(0, param.indexOf(':')).trim() + ', ' 88 | }) 89 | 90 | arguments = arguments.substring(0, arguments.length - 2) 91 | return arguments 92 | }, 93 | /** 94 | * Converts the parameter list of a React Native function into arguments when calling an iOS function. 95 | * e.g. 'flag: boolean, page: int' => 'flag:flag page:page' 96 | * @param params React Native parameter list string 97 | * @returns {string} iOS arguments string 98 | */ 99 | iOSArgs: params => { 100 | let arguments = '' 101 | 102 | params = params.replace(/((?<=\{)(.*?)(?=}))|((?<=Record<)(.*?)(?=>))/g, '') 103 | 104 | params.split(',').forEach(param => { 105 | let name = param.substring(0, param.indexOf(':')).trim() 106 | arguments += name + ':' + name + ' ' 107 | }) 108 | 109 | arguments = arguments.substring(0, arguments.length - 1) 110 | return arguments 111 | }, 112 | /** 113 | * Converts the React Native prop type into a corresponding Android type. 114 | * @param type React Native prop type 115 | * @returns {string|*} Android prop type; returns given param if no match is found 116 | */ 117 | androidPropType: type => { 118 | if (type === 'bool') { 119 | return 'boolean' 120 | } else if (type === 'string' || type === 'oneOf') { 121 | return 'String' 122 | } else if (type === 'arrayOf') { 123 | return '@NonNull ReadableArray' 124 | } else { 125 | return type 126 | } 127 | }, 128 | /** 129 | * Converts the React Native function return type into a corresponding Android type. 130 | * @param type React Native function return type 131 | * @returns {string|*} Android return type; returns given param if no match is found 132 | */ 133 | androidReturnType: type => { 134 | if (type.startsWith('Config.') || type === 'string') { 135 | return 'String' 136 | } else if ((type.startsWith('{') && type.endsWith('}')) || 137 | (type.startsWith('Record<') && type.endsWith('>')) || 138 | type.startsWith('AnnotOptions.')) { 139 | return 'WritableMap' 140 | } else if (type.startsWith('Array<') && type.endsWith('>')) { 141 | return 'WritableArray' 142 | } else { 143 | return type 144 | } 145 | }, 146 | /** 147 | * Converts the React Native function return type into a corresponding iOS type. 148 | * @param type React Native function return type 149 | * @returns {string|*} iOS return type; returns given param if no match is found 150 | */ 151 | iOSReturnType: type => { 152 | if (type === 'boolean') { 153 | return 'BOOL' 154 | } else if (type === 'int') { 155 | return 'NSInteger' 156 | } else if (type.startsWith('Config.') || type === 'string') { 157 | return 'NSString *' 158 | } else if ((type.startsWith('{') && type.endsWith('}')) || 159 | (type.startsWith('Record<') && type.endsWith('>')) || 160 | type.startsWith('AnnotOptions.')) { 161 | return 'NSDictionary *' 162 | } else if (type.startsWith('Array<') && type.endsWith('>')) { 163 | return 'NSArray *' 164 | } else { 165 | return type 166 | } 167 | } 168 | } 169 | } 170 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | 2 | # OSX 3 | # 4 | .DS_Store 5 | 6 | # node.js 7 | # 8 | node_modules/ 9 | npm-debug.log 10 | yarn-error.log 11 | 12 | 13 | # Xcode 14 | # 15 | build/ 16 | Pods/ 17 | *.pbxuser 18 | !default.pbxuser 19 | *.mode1v3 20 | !default.mode1v3 21 | *.mode2v3 22 | !default.mode2v3 23 | *.perspectivev3 24 | !default.perspectivev3 25 | xcuserdata 26 | *.xccheckout 27 | *.moved-aside 28 | DerivedData 29 | *.hmap 30 | *.ipa 31 | *.xcuserstate 32 | project.xcworkspace 33 | 34 | 35 | # Android/IntelliJ 36 | # 37 | build/ 38 | .idea 39 | .gradle 40 | local.properties 41 | *.iml 42 | 43 | # BUCK 44 | buck-out/ 45 | \.buckd/ 46 | *.keystore 47 | 48 | example/android/app/src/main/assets/index.android.bundle 49 | example/android/app/src/main/assets/index.android.bundle.meta -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to PDFTron - React Native 2 | 3 | ## Issues 4 | 1. Check existing issues (open/closed) to avoid duplicates. 5 | 2. Be clear about what the problem is. 6 | 3. Make sure to paste error output or logs. 7 | 4. Code snapshot or demos on online code editor will be very helpful. 8 | 9 | ## Pull requests 10 | 1. Fork the repository. 11 | 2. Create a branch from `master`. 12 | 3. Update the source code (in `*.ts` files). 13 | 4. Commit and push the changes with descriptive messages. 14 | 4. Create a pull request to `master`. 15 | 16 | Please note: 17 | - All pull requests should be tied to an issue, and all but the most trivial pull requests should be discussed beforehand. 18 | - Every PR needs 1 approving review to be merged into `master` (unless you are an administrator of the repo). 19 | - When PRs are made from a fork, the GitHub Actions script that updates and commits JS files will not succeed due to safety reasons. Instead, the JS files will have to be updated manually. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2019 PDFTron Systems Inc. All rights reserved. 2 | 3 | PDFTron ReactNative project/codebase or any derived works is only permitted 4 | in solutions with an active commercial PDFTron mobile SDK license. 5 | 6 | For exact licensing terms please refer to your commercial PDFTron license. 7 | 8 | For use in other scenario, please contact sales@pdftron.com 9 | -------------------------------------------------------------------------------- /RNPdftron.podspec: -------------------------------------------------------------------------------- 1 | require "json" 2 | 3 | package = JSON.parse(File.read(File.join(__dir__, "package.json"))) 4 | 5 | Pod::Spec.new do |s| 6 | s.name = "RNPdftron" 7 | s.version = package["version"] 8 | s.summary = package["description"] 9 | s.description = <<-DESC 10 | RNPdftron 11 | DESC 12 | s.homepage = "https://github.com/ApryseSDK/pdftron-react-native" 13 | s.license = "MIT" 14 | # s.license = { :type => "MIT", :file => "FILE_LICENSE" } 15 | s.author = { "author" => "author@domain.cn" } 16 | s.platform = :ios, "11.0" 17 | s.source = { :git => "https://github.com/ApryseSDK/pdftron-react-native.git", :tag => "#{s.version}" } 18 | 19 | s.source_files = "ios/**/*.{h,m}" 20 | s.requires_arc = true 21 | 22 | s.dependency 'React-Core' 23 | s.dependency 'PDFNet' 24 | 25 | s.pod_target_xcconfig = { 26 | 'FRAMEWORK_SEARCH_PATHS' => '"$(PODS_ROOT)/PDFNet"' 27 | } 28 | end 29 | 30 | 31 | -------------------------------------------------------------------------------- /_templates/generator/help/index.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | message: | 3 | hygen {bold generator new} --name [NAME] --action [ACTION] 4 | hygen {bold generator with-prompt} --name [NAME] --action [ACTION] 5 | --- -------------------------------------------------------------------------------- /_templates/generator/new/hello.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t 3 | --- 4 | --- 5 | to: app/hello.js 6 | --- 7 | const hello = ``` 8 | Hello! 9 | This is your first hygen template. 10 | 11 | Learn what it can do here: 12 | 13 | https://github.com/jondot/hygen 14 | ``` 15 | 16 | console.log(hello) 17 | 18 | 19 | -------------------------------------------------------------------------------- /_templates/generator/with-prompt/hello.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | to: _templates/<%= name %>/<%= action || 'new' %>/hello.ejs.t 3 | --- 4 | --- 5 | to: app/hello.js 6 | --- 7 | const hello = ``` 8 | Hello! 9 | This is your first prompt based hygen template. 10 | 11 | Learn what it can do here: 12 | 13 | https://github.com/jondot/hygen 14 | ``` 15 | 16 | console.log(hello) 17 | 18 | 19 | -------------------------------------------------------------------------------- /_templates/generator/with-prompt/prompt.js: -------------------------------------------------------------------------------- 1 | --- 2 | to: _templates/<%= name %>/<%= action || 'new' %>/prompt.js 3 | --- 4 | 5 | // see types of prompts: 6 | // https://github.com/enquirer/enquirer/tree/master/examples 7 | // 8 | module.exports = [ 9 | { 10 | type: 'input', 11 | name: 'message', 12 | message: "What's your message?" 13 | } 14 | ] 15 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/ConstantsjavaEvent.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/utils/Constants.java 4 | after: // Hygen Generated Event Listeners 5 | --- 6 | public static final String <%= h.changeCase.constantCase(name) %> = "<%= name %>";<% -%> 7 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/ConstantsjavaKey.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/utils/Constants.java 4 | after: // Hygen Generated Keys 5 | --- 6 | <% keys = '' 7 | if (params !== '') { 8 | params.split(',').forEach(param => { 9 | argName = param.split(':')[0].trim() 10 | keys += ' public static final String KEY_' + h.changeCase.constantCase(argName) + ' = "' + argName + '";\n' 11 | }) 12 | keys = keys.substring(0, keys.length - 1) 13 | } 14 | -%> 15 | <%- keys %><% -%> 16 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/DocumentViewjava.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/views/DocumentView.java 4 | after: // Hygen Generated Event Listeners 5 | --- 6 | <%# injecting lines to put the parameters into the WritableMap, e.g. params.putInt(KEY_PAGE_NUMBER, ); -%> 7 | <% putArgs = '' 8 | if (params !== '') { 9 | params.split(',').forEach(param => { 10 | argName = param.substring(0, param.indexOf(':')).trim() 11 | argType = param.substring(param.indexOf(':') + 1).trim() 12 | 13 | if (argType.startsWith('AnnotOptions.')) { 14 | argType = 'Map' 15 | } else if (argType.startsWith('Config.') || argType === 'string') { 16 | argType = 'String' 17 | } else if (argType.startsWith('Array<') && argType.endsWith('>')) { 18 | argType = 'Array' 19 | } else { 20 | argType = h.changeCase.upperCaseFirst(argType) 21 | } 22 | 23 | putArgs += '\n // params.put' + argType + '(KEY_' + h.changeCase.constantCase(argName) + ', );' 24 | }) 25 | } 26 | -%> 27 | // uncomment and use to implement <%= name %> 28 | // WritableMap params = Arguments.createMap(); 29 | // params.putString(<%= h.changeCase.constantCase(name) %>, <%= h.changeCase.constantCase(name) %>);<%- putArgs %> 30 | 31 | // onReceiveNativeEvent(params); 32 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/DocumentViewtsxOnChange.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: src/DocumentView/DocumentView.tsx 4 | after: // Hygen Generated Event Listeners 5 | --- 6 | <%# injecting lines for each parameter, e.g. 'pageNumber': event.nativeEvent.pageNumber, -%> 7 | <% args = '' 8 | if (params !== '') { 9 | args += '{' 10 | params.split(',').forEach(param => { 11 | argName = param.split(':')[0].trim() 12 | args += '\n \'' + argName + '\': event.nativeEvent.' + argName + ',' 13 | }) 14 | args += '\n }' 15 | } 16 | -%> 17 | } else if (event.nativeEvent.<%= name %>) { 18 | if (this.props.<%= name %>) { 19 | this.props.<%= name %>(<%- args %>); 20 | }<% -%> 21 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/DocumentViewtsxProp.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: src/DocumentView/DocumentView.tsx 4 | after: // Hygen Generated Props 5 | --- 6 | <% args = params.trim() 7 | if (args !== '') { 8 | args = 'event: { ' + args.replace(/\bint\b|\bdouble\b/g, 'number') + ' }' 9 | } 10 | -%> 11 | <%= name %>: func<(<%- args %>) => void>(),<% -%> 12 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/RNTPTDocumentViewManagerm.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentViewManager.m 4 | after: // Hygen Generated Event Listeners 5 | --- 6 | <%# injecting lines for each parameter, e.g. @"pageNumber": @(pageNumber), -%> 7 | <% args = '' 8 | if (params !== '') { 9 | params.split(',').forEach(param => { 10 | argName = param.substring(0, param.indexOf(':')).trim() 11 | argType = param.substring(param.indexOf(':') + 1).trim() 12 | 13 | if (argType === 'int' || argType === 'double' || argType === 'boolean' ) { 14 | args += '\n @"' + argName + '": @(' + argName + '),' 15 | } else { 16 | args += '\n @"' + argName + '": ' + argName + ',' 17 | } 18 | }) 19 | } 20 | -%> 21 | - (void)<%= name %>:(RNTPTDocumentView *)sender<%- params === '' ? '' : ' ' + h.iOSParams(params, false) %> 22 | { 23 | if (sender.onChange) { 24 | sender.onChange(@{ 25 | @"<%= name %>": @"<%= name %>",<%- args %> 26 | }); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/RNTPTDocumentViewh.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentView.h 4 | after: // Hygen Generated Event Listeners 5 | --- 6 | - (void)<%= name %>:(RNTPTDocumentView *)sender<%- params === '' ? '' : ' ' + h.iOSParams(params, false) %>; 7 | -------------------------------------------------------------------------------- /_templates/listener-generator/new/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | prompt: ({ inquirer }) => { 3 | // defining questions in arrays ensures all questions are asked before next prompt is executed 4 | const questions = [ 5 | { 6 | type: 'input', 7 | name: 'name', 8 | message: 'Name of event listener? (ex: onLayoutChanged)', 9 | }, 10 | { 11 | type: 'input', 12 | name: 'params', 13 | message: 'Parameter list of React Native listener (comma separated)? Use either int or double for number\n (ex: previousPageNumber: int, pageNumber: int, ...)\n', 14 | } 15 | ] 16 | 17 | // returning the answers to the prompt 18 | return inquirer 19 | .prompt(questions) 20 | }, 21 | } 22 | -------------------------------------------------------------------------------- /_templates/method-generator/new/DocumentViewModule.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/modules/DocumentViewModule.java 4 | after: // Hygen Generated Methods 5 | --- 6 | <% parameters = params === '' ? '' : h.androidParams(params, true) + ', ' 7 | args = params === '' ? '' : ', ' + h.androidArgs(params) 8 | returnVar = returnType === 'void' ? '' : h.androidReturnType(returnType) + ' field = ' 9 | -%> 10 | 11 | @ReactMethod 12 | public void <%= name %>(<%- parameters %>final Promise promise) { 13 | getReactApplicationContext().runOnUiQueueThread(new Runnable() { 14 | @Override 15 | public void run() { 16 | try { 17 | <%= returnVar %>mDocumentViewInstance.<%= name %>(tag<%= args %>); 18 | promise.resolve(<%= returnType === 'void' ? 'null' : 'field' %>); 19 | } catch (Exception ex) { 20 | promise.reject(ex); 21 | } 22 | } 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /_templates/method-generator/new/DocumentViewViewManagerjava.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/viewmanagers/DocumentViewViewManager.java 4 | after: // Hygen Generated Methods 5 | --- 6 | <% parameters = params === '' ? '' : ', ' + h.androidParams(params, false) -%> 7 | 8 | public <%- h.androidReturnType(returnType) %> <%= name %>(int tag<%- parameters %>) throws PDFNetException { 9 | DocumentView documentView = mDocumentViews.get(tag); 10 | if (documentView != null) { 11 | return documentView.<%= name %>(<%= h.androidArgs(params) %>); 12 | } else { 13 | throw new PDFNetException("", 0L, getName(), "<%= name %>", "Unable to find DocumentView."); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /_templates/method-generator/new/DocumentViewjava.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/views/DocumentView.java 4 | after: // Hygen Generated Methods 5 | --- 6 | 7 | public <%- h.androidReturnType(returnType) %> <%= name %>(<%- params === '' ? '' : h.androidParams(params, false) %>) { 8 | 9 | } 10 | -------------------------------------------------------------------------------- /_templates/method-generator/new/DocumentViewtsx.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: src/DocumentView/DocumentView.tsx 4 | after: // Hygen Generated Methods 5 | --- 6 | <% promiseType = returnType 7 | if (promiseType === 'void') { 8 | promiseType = 'Promise' 9 | } else { 10 | promiseType = 'Promise' 11 | } 12 | promiseType = promiseType.replace(/\bint\b|\bdouble\b/g, 'number'); 13 | parameters = params.replace(/\bint\b|\bdouble\b/g, 'number'); 14 | -%> 15 | <%= name %> = (<%- parameters %>): <%- promiseType %> => { 16 | const tag = findNodeHandle(this._viewerRef); 17 | if (tag != null) { 18 | return DocumentViewManager.<%= name %>(tag<%= params === '' ? '' : ', ' + h.androidArgs(params) %>); 19 | } 20 | return Promise.resolve(); 21 | } 22 | -------------------------------------------------------------------------------- /_templates/method-generator/new/RNTPTDocumentViewManagerh.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentViewManager.h 4 | after: Hygen Generated Methods 5 | --- 6 | 7 | - (<%= h.iOSReturnType(returnType) %>)<%= name %>ForDocumentViewTag:(NSNumber *)tag<%= params === '' ? '' : ' ' + h.iOSParams(params) %>;<% -%> 8 | -------------------------------------------------------------------------------- /_templates/method-generator/new/RNTPTDocumentViewManagerm.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentViewManager.m 4 | after: Hygen Generated Methods 5 | --- 6 | <% args = h.iOSArgs(params) -%> 7 | - (<%= h.iOSReturnType(returnType) %>)<%= name %>ForDocumentViewTag:(NSNumber *)tag<%= params === '' ? '' : ' ' + h.iOSParams(params) %> 8 | { 9 | RNTPTDocumentView *documentView = self.documentViews[tag]; 10 | if (documentView) { 11 | <%= returnType === 'void' ? '' : 'return ' %>[documentView <%= name %><%= params === '' ? '' : ':' + args.substring(args.indexOf(':') + 1) %>]; 12 | } else { 13 | @throw [NSException exceptionWithName:NSInvalidArgumentException reason:@"Unable to get field for tag" userInfo:nil];<%= returnType === 'void' ? '' : '\n return nil;' %> 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /_templates/method-generator/new/RNTPTDocumentViewModulem.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentViewModule.m 4 | after: Hygen Generated Methods 5 | --- 6 | <% returnVar = h.iOSReturnType(returnType) 7 | if (returnVar === 'void') { 8 | returnVar = '' 9 | } else if (!returnVar.endsWith('*')) { 10 | returnVar = returnVar + ' result = ' 11 | } else { 12 | returnVar = returnVar + 'result = ' 13 | } 14 | -%> 15 | RCT_REMAP_METHOD(<%= name %>, 16 | <%= name %>ForDocumentViewTag:(nonnull NSNumber *)tag<%= params === '' ? '' : '\n ' + h.iOSParams(params, true) %> 17 | resolver:(RCTPromiseResolveBlock)resolve 18 | rejecter:(RCTPromiseRejectBlock)reject) 19 | { 20 | @try { 21 | <%= returnVar %>[[self documentViewManager] <%= name %>ForDocumentViewTag:tag<%= params === '' ? '' : ' ' + h.iOSArgs(params) %>]; 22 | resolve(<%= returnType === 'void' ? 'nil' : 'result' %>); 23 | } 24 | @catch (NSException *exception) { 25 | reject(@"<%= h.changeCase.snakeCase(name) %>", @"Failed to <%= h.changeCase.noCase(name) %>", [self errorFromException:exception]); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /_templates/method-generator/new/RNTPTDocumentViewh.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentView.h 4 | after: Hygen Generated Methods 5 | --- 6 | <% parameters = '' 7 | if (params !== '') { 8 | parameters = h.iOSParams(params) 9 | // chopping off the parameter name of the first parameter to follow proper syntax 10 | parameters = ':' + parameters.substring(parameters.indexOf(':') + 1) 11 | } 12 | -%> 13 | - (<%= h.iOSReturnType(returnType) %>)<%= name %><%= parameters %>; 14 | -------------------------------------------------------------------------------- /_templates/method-generator/new/RNTPTDocumentViewm.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentView.m 4 | after: Hygen Generated Props/Methods 5 | --- 6 | <% parameters = '' 7 | if (params !== '') { 8 | parameters = h.iOSParams(params) 9 | // chopping off the parameter name of the first parameter to follow proper syntax 10 | parameters = ':' + parameters.substring(parameters.indexOf(':') + 1) 11 | } 12 | -%> 13 | 14 | - (<%= h.iOSReturnType(returnType) %>)<%= name %><%= parameters %> 15 | { 16 | 17 | }<% -%> 18 | -------------------------------------------------------------------------------- /_templates/method-generator/new/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | prompt: ({ inquirer }) => { 3 | // defining questions in arrays ensures all questions are asked before next prompt is executed 4 | const questions = [ 5 | { 6 | type: 'input', 7 | name: 'name', 8 | message: 'Name of method?', 9 | }, 10 | { 11 | type: 'input', 12 | name: 'params', 13 | message: 'Parameter list of React Native method (comma separated)? Use either int or double for number\n (ex: flag: boolean, page: int, options: { annotList: Array }, ...)\n', 14 | }, 15 | { 16 | type: 'input', 17 | name: 'returnType', 18 | message: 'Return type of React Native method? Use either int or double for number\n (ex: void, boolean, int, { fieldName: string, fieldValue?: any }, ...)\n', 19 | } 20 | ] 21 | 22 | // returning the answers to the prompt 23 | return inquirer 24 | .prompt(questions) 25 | }, 26 | } 27 | -------------------------------------------------------------------------------- /_templates/prop-generator/new/DocumentViewJava.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/views/DocumentView.java 4 | after: // Hygen Generated Props 5 | --- 6 | public void set<%= h.changeCase.pascalCase(name) %>(<%= h.androidPropType(propType) %> <%= paramName %>) { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /_templates/prop-generator/new/DocumentViewViewManagerJava.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: android/src/main/java/com/pdftron/reactnative/viewmanagers/DocumentViewViewManager.java 4 | after: // Hygen Generated Props 5 | --- 6 | @ReactProp(name = "<%= name %>") 7 | public void set<%= h.changeCase.pascalCase(name) %>(DocumentView documentView, <%= h.androidPropType(propType) %> <%= paramName %>) { 8 | documentView.set<%= h.changeCase.pascalCase(name) %>(<%= paramName %>); 9 | } 10 | -------------------------------------------------------------------------------- /_templates/prop-generator/new/DocumentViewtsx.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: src/DocumentView/DocumentView.tsx 4 | after: // Hygen Generated Props 5 | --- 6 | 7 | <% type = propType.trim() 8 | if (type === 'oneOf' || type === 'arrayOf') { 9 | type = type + '<' + configType + '>(' + configType + ')' 10 | } else if (type === 'int' || type === 'double') { 11 | type = 'PropTypes.number' 12 | } else { 13 | type = 'PropTypes.' + type 14 | } 15 | -%> 16 | <%= name %>: <%- type %>,<% -%> 17 | -------------------------------------------------------------------------------- /_templates/prop-generator/new/RNTPTDocumentViewManager.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentViewManager.m 4 | after: // Hygen Generated Props 5 | --- 6 | <%# converting the React Native prop type into the corresponding iOS type as an argument to the RCTConvert function -%> 7 | <% type = propType 8 | if (type === 'bool') { 9 | type = 'BOOL' 10 | } else if (type === 'string' || type === 'oneOf') { 11 | type = 'NSString' 12 | } else if (type === 'arrayOf') { 13 | type = 'NSArray' 14 | } 15 | -%> 16 | RCT_CUSTOM_VIEW_PROPERTY(<%= name %>, <%= type %>, RNTPTDocumentView) 17 | { 18 | if (json) { 19 | view.<%= paramName %> = [RCTConvert <%= type %>:json]; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /_templates/prop-generator/new/RNTPTDocumentViewh.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentView.h 4 | after: // Hygen Generated Props 5 | --- 6 | <%# converting the React Native prop type into the corresponding iOS type, along with appropriate keywords -%> 7 | <% type = propType 8 | if (type === 'bool') { 9 | type = '(nonatomic, assign) BOOL ' 10 | } else if (type === 'string' || type === 'oneOf') { 11 | type = '(nonatomic, copy, nullable) NSString *' 12 | } else if (type === 'arrayOf') { 13 | type = '(nonatomic, copy, nullable) NSArray ' 14 | } else { 15 | type = '(nonatomic, assign) ' + type + ' ' 16 | } 17 | -%> 18 | @property <%- type %><%= name %>; <% -%> 19 | -------------------------------------------------------------------------------- /_templates/prop-generator/new/RNTPTDocumentViewm.ejs.t: -------------------------------------------------------------------------------- 1 | --- 2 | inject: true 3 | to: ios/RNTPTDocumentView.m 4 | after: Hygen Generated Props/Methods 5 | --- 6 | <%# converting the React Native prop type into the corresponding iOS type -%> 7 | <% type = propType 8 | if (type === 'bool') { 9 | type = 'BOOL' 10 | } else if (type === 'string' || type === 'oneOf') { 11 | type = 'NSString *' 12 | } else if (type === 'arrayOf') { 13 | type = 'NSArray *' 14 | } 15 | -%> 16 | 17 | - (void)set<%= h.changeCase.pascalCase(name) %>:(<%= type %>)<%= paramName %> 18 | { 19 | 20 | }<% -%> 21 | -------------------------------------------------------------------------------- /_templates/prop-generator/new/index.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | prompt: ({ inquirer }) => { 3 | // defining questions in arrays ensures all questions are asked before next prompt is executed 4 | const questions = [ 5 | { 6 | type: 'input', 7 | name: 'name', 8 | message: 'Name of prop?', 9 | }, 10 | { 11 | type: 'input', 12 | name: 'propType', 13 | message: 'Type of prop? Choose from: bool, string, int, double, oneOf, arrayOf\n', 14 | } 15 | ] 16 | 17 | return inquirer 18 | .prompt(questions) 19 | .then(answers => { 20 | // using the answers from the previous prompt to determine which questions to ask next 21 | const propType = answers.propType.trim() 22 | const questions = [ 23 | { 24 | type: 'input', 25 | name: 'paramName', 26 | message: 'Name of parameter?', 27 | default: answers.name, 28 | } 29 | ] 30 | 31 | if (propType === 'oneOf' || propType === 'arrayOf') { 32 | questions.unshift({ 33 | type: 'input', 34 | name: 'configType', 35 | message: 'Name of the Config constant type for the ' + propType + '? (ex: Config.LayoutMode)', 36 | }) 37 | } 38 | 39 | // return the merged set of answers from the previous prompt and this prompt 40 | return inquirer.prompt(questions).then(nextAnswers => Object.assign({}, answers, nextAnswers)) 41 | }) 42 | }, 43 | } 44 | -------------------------------------------------------------------------------- /android/README.md: -------------------------------------------------------------------------------- 1 | 2 | README 3 | ====== 4 | 5 | If you want to publish the lib as a maven dependency, follow these steps before publishing a new version to npm: 6 | 7 | 1. Be sure to have the Android [SDK](https://developer.android.com/studio/index.html) and [NDK](https://developer.android.com/ndk/guides/index.html) installed 8 | 2. Be sure to have a `local.properties` file in this folder that points to the Android SDK and NDK 9 | ``` 10 | ndk.dir=/Users/{username}/Library/Android/sdk/ndk-bundle 11 | sdk.dir=/Users/{username}/Library/Android/sdk 12 | ``` 13 | 3. Delete the `maven` folder 14 | 4. Run `sudo ./gradlew installArchives` 15 | 5. Verify that latest set of generated files is in the maven folder with the correct version number 16 | -------------------------------------------------------------------------------- /android/build.gradle: -------------------------------------------------------------------------------- 1 | 2 | buildscript { 3 | def kotlinVersion = rootProject.ext.has('kotlinVersion') ? rootProject.ext.get('kotlinVersion') : "1.8.22" 4 | repositories { 5 | google() 6 | mavenCentral() 7 | } 8 | 9 | dependencies { 10 | classpath 'com.android.tools.build:gradle:4.2.0' 11 | classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion" 12 | } 13 | } 14 | 15 | rootProject.allprojects { 16 | repositories { 17 | google() 18 | mavenCentral() 19 | maven { 20 | url "https://pdftron-maven.s3.amazonaws.com/release" 21 | } 22 | } 23 | } 24 | 25 | apply plugin: 'com.android.library' 26 | apply plugin: 'kotlin-android' 27 | apply plugin: 'kotlin-kapt' 28 | 29 | android { 30 | compileSdkVersion 33 31 | buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : "30.0.2" 32 | 33 | defaultConfig { 34 | minSdkVersion 21 35 | targetSdkVersion 33 36 | versionCode 1 37 | versionName "1.0" 38 | vectorDrawables.useSupportLibrary = true 39 | } 40 | compileOptions { 41 | sourceCompatibility JavaVersion.VERSION_17 42 | targetCompatibility JavaVersion.VERSION_17 43 | } 44 | kotlinOptions { 45 | jvmTarget = '17' 46 | } 47 | lintOptions { 48 | abortOnError false 49 | } 50 | } 51 | 52 | repositories { 53 | maven { 54 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 55 | // Matches the RN Hello World template 56 | // https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/local-cli/templates/HelloWorld/android/build.gradle#L21 57 | url "$projectDir/../node_modules/react-native/android" 58 | } 59 | mavenCentral() 60 | } 61 | 62 | dependencies { 63 | implementation "com.facebook.react:react-native:+" 64 | 65 | implementation 'androidx.fragment:fragment:1.5.1' 66 | 67 | implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.5.1' 68 | implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1' 69 | 70 | implementation "com.pdftron:pdftron:11.5.0" 71 | implementation "com.pdftron:tools:11.5.0" 72 | implementation "com.pdftron:collab:11.5.0" 73 | } 74 | -------------------------------------------------------------------------------- /android/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/RNPdftronPackage.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative; 2 | 3 | import com.facebook.react.ReactPackage; 4 | import com.facebook.react.bridge.NativeModule; 5 | import com.facebook.react.bridge.ReactApplicationContext; 6 | import com.facebook.react.uimanager.ViewManager; 7 | import com.pdftron.reactnative.modules.DocumentViewModule; 8 | import com.pdftron.reactnative.modules.RNPdftronModule; 9 | import com.pdftron.reactnative.viewmanagers.DocumentViewViewManager; 10 | import com.pdftron.reactnative.viewmanagers.PDFViewCtrlViewManager; 11 | 12 | import java.util.Arrays; 13 | import java.util.List; 14 | 15 | public class RNPdftronPackage implements ReactPackage { 16 | 17 | private DocumentViewViewManager mDocumentViewViewManager; 18 | 19 | @Override 20 | public List createNativeModules(ReactApplicationContext reactContext) { 21 | if (null == mDocumentViewViewManager) { 22 | mDocumentViewViewManager = new DocumentViewViewManager(); 23 | } 24 | return Arrays.asList( 25 | new RNPdftronModule(reactContext), 26 | new DocumentViewModule(reactContext, mDocumentViewViewManager) 27 | ); 28 | } 29 | 30 | @Override 31 | public List createViewManagers(ReactApplicationContext reactContext) { 32 | if (null == mDocumentViewViewManager) { 33 | mDocumentViewViewManager = new DocumentViewViewManager(); 34 | } 35 | return Arrays.asList( 36 | new PDFViewCtrlViewManager(), 37 | mDocumentViewViewManager 38 | ); 39 | } 40 | } -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/modules/RNPdftronModule.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.modules; 2 | 3 | import androidx.annotation.NonNull; 4 | import androidx.annotation.Nullable; 5 | 6 | import com.facebook.react.bridge.Promise; 7 | import com.facebook.react.bridge.ReactApplicationContext; 8 | import com.facebook.react.bridge.ReactContextBaseJavaModule; 9 | import com.facebook.react.bridge.ReactMethod; 10 | import com.facebook.react.bridge.ReadableMap; 11 | import com.pdftron.pdf.Convert; 12 | import com.pdftron.pdf.OfficeToPDFOptions; 13 | import com.pdftron.pdf.PDFDoc; 14 | import com.pdftron.pdf.PDFNet; 15 | import com.pdftron.pdf.model.StandardStampOption; 16 | import com.pdftron.pdf.utils.AppUtils; 17 | import com.pdftron.pdf.utils.PdfViewCtrlSettingsManager; 18 | import com.pdftron.pdf.utils.PdfViewCtrlTabsManager; 19 | import com.pdftron.pdf.utils.RecentFilesManager; 20 | import com.pdftron.pdf.utils.Utils; 21 | import com.pdftron.pdf.utils.ViewerUtils; 22 | import com.pdftron.reactnative.utils.ReactUtils; 23 | import com.pdftron.sdf.SDFDoc; 24 | 25 | import java.io.File; 26 | 27 | public class RNPdftronModule extends ReactContextBaseJavaModule { 28 | 29 | private static final String REACT_CLASS = "RNPdftron"; 30 | 31 | public RNPdftronModule(ReactApplicationContext reactContext) { 32 | super(reactContext); 33 | } 34 | 35 | @Override 36 | public String getName() { 37 | return REACT_CLASS; 38 | } 39 | 40 | @ReactMethod 41 | public void initialize(@NonNull String key) { 42 | try { 43 | AppUtils.initializePDFNetApplication(getReactApplicationContext(), key); 44 | } catch (Exception ex) { 45 | ex.printStackTrace(); 46 | } 47 | } 48 | 49 | @ReactMethod 50 | public void enableJavaScript(boolean enabled) { 51 | try { 52 | PDFNet.enableJavaScript(enabled); 53 | } catch (Exception ex) { 54 | ex.printStackTrace(); 55 | } 56 | } 57 | 58 | @ReactMethod 59 | public void getSystemFontList(final Promise promise) { 60 | String fontList = null; 61 | Exception exception = null; 62 | try { 63 | fontList = PDFNet.getSystemFontList(); 64 | } catch (Exception e) { 65 | exception = e; 66 | } 67 | 68 | String finalFontList = fontList; 69 | Exception finalException = exception; 70 | getReactApplicationContext().runOnUiQueueThread(new Runnable() { 71 | 72 | @Override 73 | public void run() { 74 | if (finalFontList != null) { 75 | promise.resolve(finalFontList); 76 | } else { 77 | promise.reject(finalException); 78 | } 79 | } 80 | }); 81 | } 82 | 83 | @ReactMethod 84 | public void clearRubberStampCache(final Promise promise) { 85 | StandardStampOption.clearCache(getReactApplicationContext()); 86 | getReactApplicationContext().runOnUiQueueThread(new Runnable() { 87 | @Override 88 | public void run() { 89 | promise.resolve(null); 90 | } 91 | }); 92 | } 93 | 94 | @ReactMethod 95 | public void encryptDocument(final String filePath, final String password, final String currentPassword, final Promise promise) { 96 | try { 97 | String oldPassword = currentPassword; 98 | if (Utils.isNullOrEmpty(currentPassword)) { 99 | oldPassword = ""; 100 | } 101 | PDFDoc pdfDoc = new PDFDoc(filePath); 102 | if (pdfDoc.initStdSecurityHandler(oldPassword)) { 103 | ViewerUtils.passwordDoc(pdfDoc, password); 104 | pdfDoc.lock(); 105 | pdfDoc.save(filePath, SDFDoc.SaveMode.REMOVE_UNUSED, null); 106 | pdfDoc.unlock(); 107 | promise.resolve(null); 108 | } else { 109 | promise.reject("password", "Current password is incorrect."); 110 | } 111 | } catch (Exception ex) { 112 | promise.reject(ex); 113 | } 114 | } 115 | 116 | @ReactMethod 117 | public void getVersion(final Promise promise) { 118 | getReactApplicationContext().runOnUiQueueThread(new Runnable() { 119 | @Override 120 | public void run() { 121 | try { 122 | promise.resolve(Double.toString(PDFNet.getVersion())); 123 | } catch (Exception ex) { 124 | promise.reject(ex); 125 | } 126 | } 127 | }); 128 | } 129 | 130 | @ReactMethod 131 | public void getPlatformVersion(final Promise promise) { 132 | getReactApplicationContext().runOnUiQueueThread(new Runnable() { 133 | @Override 134 | public void run() { 135 | try { 136 | promise.resolve("Android " + android.os.Build.VERSION.RELEASE); 137 | } catch (Exception ex) { 138 | promise.reject(ex); 139 | } 140 | } 141 | }); 142 | } 143 | 144 | @ReactMethod 145 | public void pdfFromOffice(final String docxPath, final @Nullable ReadableMap options, final Promise promise) { 146 | try { 147 | PDFDoc doc = new PDFDoc(); 148 | OfficeToPDFOptions conversionOptions = new OfficeToPDFOptions(); 149 | 150 | if (options != null) { 151 | if (options.hasKey("applyPageBreaksToSheet")) { 152 | if (!options.isNull("applyPageBreaksToSheet")) { 153 | conversionOptions.setApplyPageBreaksToSheet(options.getBoolean("applyPageBreaksToSheet")); 154 | } 155 | } 156 | 157 | if (options.hasKey("displayChangeTracking")) { 158 | if (!options.isNull("displayChangeTracking")) { 159 | conversionOptions.setDisplayChangeTracking(options.getBoolean("displayChangeTracking")); 160 | } 161 | } 162 | 163 | if (options.hasKey("excelDefaultCellBorderWidth")) { 164 | if (!options.isNull("excelDefaultCellBorderWidth")) { 165 | conversionOptions.setExcelDefaultCellBorderWidth(options.getDouble("excelDefaultCellBorderWidth")); 166 | } 167 | } 168 | 169 | if (options.hasKey("excelMaxAllowedCellCount")) { 170 | if (!options.isNull("excelMaxAllowedCellCount")) { 171 | conversionOptions.setExcelMaxAllowedCellCount(options.getInt("excelMaxAllowedCellCount")); 172 | } 173 | } 174 | 175 | if (options.hasKey("locale")) { 176 | if (!options.isNull("locale")) { 177 | conversionOptions.setLocale(options.getString("locale")); 178 | } 179 | } 180 | } 181 | 182 | Convert.officeToPdf(doc, docxPath, conversionOptions); 183 | File resultPdf = File.createTempFile("tmp", ".pdf", getReactApplicationContext().getFilesDir()); 184 | doc.save(resultPdf.getAbsolutePath(), SDFDoc.SaveMode.NO_FLAGS, null); 185 | promise.resolve(resultPdf.getAbsolutePath()); 186 | } catch (Exception e) { 187 | promise.reject(e); 188 | } 189 | } 190 | 191 | @ReactMethod 192 | public void pdfFromOfficeTemplate(final String docxPath, final ReadableMap json, final Promise promise) { 193 | try { 194 | PDFDoc doc = new PDFDoc(); 195 | OfficeToPDFOptions options = new OfficeToPDFOptions(); 196 | options.setTemplateParamsJson(ReactUtils.convertMapToJson(json).toString()); 197 | Convert.officeToPdf(doc, docxPath, options); 198 | File resultPdf = File.createTempFile("tmp", ".pdf", getReactApplicationContext().getFilesDir()); 199 | doc.save(resultPdf.getAbsolutePath(), SDFDoc.SaveMode.NO_FLAGS, null); 200 | promise.resolve(resultPdf.getAbsolutePath()); 201 | } catch (Exception e) { 202 | promise.reject(e); 203 | } 204 | } 205 | 206 | @ReactMethod 207 | public void exportAsImage(int pageNumber, double dpi, String exportFormat, final String filePath, boolean transparent, final Promise promise) { 208 | try { 209 | PDFDoc doc = new PDFDoc(filePath); 210 | doc.lockRead(); 211 | String imagePath = ReactUtils.exportAsImageHelper(doc, pageNumber, dpi, exportFormat, transparent); 212 | doc.unlockRead(); 213 | promise.resolve(imagePath); 214 | } catch (Exception e) { 215 | promise.reject(e); 216 | } 217 | } 218 | 219 | @ReactMethod 220 | public void clearSavedViewerState(final Promise promise) { 221 | try { 222 | RecentFilesManager.getInstance().clearFiles(getReactApplicationContext()); 223 | PdfViewCtrlTabsManager.getInstance().cleanup(); 224 | PdfViewCtrlTabsManager.getInstance().clearAllPdfViewCtrlTabInfo(getReactApplicationContext()); 225 | PdfViewCtrlSettingsManager.setOpenUrlAsyncCache(getReactApplicationContext(), ""); 226 | PdfViewCtrlSettingsManager.setOpenUrlPageStateAsyncCache(getReactApplicationContext(), ""); 227 | promise.resolve(null); 228 | } catch (Exception e) { 229 | promise.reject(e); 230 | } 231 | } 232 | } -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/nativeviews/RNCollabViewerTabHostFragment.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.nativeviews; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import androidx.annotation.NonNull; 6 | import androidx.annotation.Nullable; 7 | 8 | import com.pdftron.collab.ui.viewer.CollabViewerTabHostFragment2; 9 | 10 | public class RNCollabViewerTabHostFragment extends CollabViewerTabHostFragment2 { 11 | 12 | private RNPdfViewCtrlTabHostFragment.RNHostFragmentListener mListener; 13 | 14 | public void setRNHostFragmentListener(RNPdfViewCtrlTabHostFragment.RNHostFragmentListener listener) { 15 | mListener = listener; 16 | } 17 | 18 | @Override 19 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 20 | super.onViewCreated(view, savedInstanceState); 21 | 22 | if (mListener != null) { 23 | mListener.onHostFragmentViewCreated(); 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/nativeviews/RNPdfViewCtrlTabFragment.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.nativeviews; 2 | 3 | import android.graphics.PointF; 4 | import android.util.Pair; 5 | import androidx.fragment.app.FragmentActivity; 6 | 7 | import com.facebook.react.bridge.Arguments; 8 | import com.facebook.react.bridge.ReactContext; 9 | import com.facebook.react.bridge.WritableMap; 10 | import com.facebook.react.uimanager.events.RCTEventEmitter; 11 | import com.pdftron.pdf.PDFDoc; 12 | import com.pdftron.pdf.controls.PdfViewCtrlTabBaseFragment; 13 | import com.pdftron.pdf.controls.PdfViewCtrlTabFragment2; 14 | import com.pdftron.pdf.tools.ToolManager; 15 | import com.pdftron.pdf.utils.AnalyticsHandlerAdapter; 16 | import com.pdftron.pdf.utils.DialogGoToPage; 17 | import com.pdftron.pdf.utils.Utils; 18 | import com.pdftron.pdf.utils.ViewerUtils; 19 | 20 | import org.apache.commons.io.FilenameUtils; 21 | 22 | import java.io.File; 23 | 24 | import javax.annotation.Nullable; 25 | 26 | import static com.pdftron.reactnative.utils.Constants.KEY_HORIZONTAL; 27 | import static com.pdftron.reactnative.utils.Constants.KEY_VERTICAL; 28 | import static com.pdftron.reactnative.utils.Constants.ON_SCROLL_CHANGED; 29 | import static com.pdftron.reactnative.utils.Constants.ON_ZOOM_FINISHED; 30 | import static com.pdftron.reactnative.utils.Constants.ZOOM_KEY; 31 | 32 | public class RNPdfViewCtrlTabFragment extends PdfViewCtrlTabFragment2 { 33 | 34 | @Nullable 35 | private ReactContext mReactContext; 36 | private int mViewId; 37 | 38 | @Override 39 | public void imageStamperSelected(PointF targetPoint) { 40 | // in react native, intent must be sent from the activity 41 | // to be able to receive by the activity 42 | FragmentActivity activity = getActivity(); 43 | if (null == activity) { 44 | return; 45 | } 46 | this.mImageCreationMode = ToolManager.ToolMode.STAMPER; 47 | this.mAnnotTargetPoint = targetPoint; 48 | this.mOutputFileUri = ViewerUtils.openImageIntent(activity); 49 | } 50 | 51 | @Override 52 | public void imageSignatureSelected(PointF targetPoint, int targetPage, Long widget) { 53 | // in react native, intent must be sent from the activity 54 | // to be able to receive by the activity 55 | FragmentActivity activity = getActivity(); 56 | if (null == activity) { 57 | return; 58 | } 59 | mImageCreationMode = ToolManager.ToolMode.SIGNATURE; 60 | mAnnotTargetPoint = targetPoint; 61 | mAnnotTargetPage = targetPage; 62 | mTargetWidget = widget; 63 | mOutputFileUri = ViewerUtils.openImageIntent(activity); 64 | } 65 | 66 | @Override 67 | public void attachFileSelected(PointF targetPoint) { 68 | // in react native, intent must be sent from the activity 69 | // to be able to receive by the activity 70 | FragmentActivity activity = getActivity(); 71 | if (null == activity) { 72 | return; 73 | } 74 | mAnnotTargetPoint = targetPoint; 75 | ViewerUtils.openFileIntent(activity); 76 | } 77 | 78 | @Override 79 | public boolean onScaleEnd(float x, float y) { 80 | WritableMap params = Arguments.createMap(); 81 | params.putString(ON_ZOOM_FINISHED, ON_ZOOM_FINISHED); 82 | params.putDouble(ZOOM_KEY, mPdfViewCtrl.getZoom()); 83 | onReceiveNativeEvent(params); 84 | 85 | return super.onScaleEnd(x, y); 86 | } 87 | 88 | @Override 89 | public void onScrollChanged(int l, int t, int oldl, int oldt) { 90 | super.onScrollChanged(l, t, oldl, oldt); 91 | 92 | WritableMap params = Arguments.createMap(); 93 | params.putString(ON_SCROLL_CHANGED, ON_SCROLL_CHANGED); 94 | params.putInt(KEY_HORIZONTAL, l); 95 | params.putInt(KEY_VERTICAL, t); 96 | onReceiveNativeEvent(params); 97 | } 98 | 99 | public void shareCopy(boolean flattening) { 100 | FragmentActivity activity = getActivity(); 101 | if (activity == null) { 102 | return; 103 | } 104 | if (flattening) { 105 | File tempFile = new File(activity.getCacheDir(), getTabTitleWithExtension()); 106 | String tempPath = Utils.getFileNameNotInUse(tempFile.getAbsolutePath()); 107 | PdfViewCtrlTabBaseFragment.SaveFolderWrapper wrapper = new PdfViewCtrlTabBaseFragment.SaveFolderWrapper( 108 | activity.getCacheDir(), FilenameUtils.getName(tempPath), true, null); 109 | PDFDoc copyDoc = wrapper.getDoc(); 110 | if (copyDoc != null) { 111 | ViewerUtils.flattenDoc(copyDoc); 112 | Pair result = wrapper.save(copyDoc); 113 | Utils.sharePdfFile(activity, new File(result.second)); 114 | } 115 | } else { 116 | handleOnlineShare(); 117 | } 118 | } 119 | 120 | public void setReactContext(@Nullable ReactContext reactContext, int id) { 121 | mReactContext = reactContext; 122 | mViewId = id; 123 | } 124 | 125 | public void onReceiveNativeEvent(WritableMap event) { 126 | if (mReactContext == null) { 127 | return; 128 | } 129 | mReactContext.getJSModule(RCTEventEmitter.class).receiveEvent( 130 | mViewId, 131 | "topChange", 132 | event); 133 | } 134 | 135 | public void showGoToPageView() { 136 | FragmentActivity activity = getActivity(); 137 | if (null == activity) { 138 | return; 139 | } 140 | DialogGoToPage dlgGotoPage = new DialogGoToPage(activity, mPdfViewCtrl, new DialogGoToPage.DialogGoToPageListener() { 141 | @Override 142 | public void onPageSet(int pageNum) { 143 | setCurrentPageHelper(pageNum, true); 144 | if (mReflowControl != null) { 145 | try { 146 | mReflowControl.setCurrentPage(pageNum); 147 | } catch (Exception e) { 148 | AnalyticsHandlerAdapter.getInstance().sendException(e); 149 | } 150 | } 151 | } 152 | }); 153 | dlgGotoPage.show(); 154 | } 155 | } 156 | -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/nativeviews/RNPdfViewCtrlTabHostFragment.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.nativeviews; 2 | 3 | import android.os.Bundle; 4 | import android.view.View; 5 | import androidx.annotation.NonNull; 6 | import androidx.annotation.Nullable; 7 | 8 | import com.pdftron.pdf.controls.PdfViewCtrlTabHostFragment2; 9 | 10 | public class RNPdfViewCtrlTabHostFragment extends PdfViewCtrlTabHostFragment2 { 11 | 12 | private RNHostFragmentListener mListener; 13 | 14 | public void setRNHostFragmentListener(RNHostFragmentListener listener) { 15 | mListener = listener; 16 | } 17 | 18 | public interface RNHostFragmentListener { 19 | void onHostFragmentViewCreated(); 20 | } 21 | 22 | @Override 23 | public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) { 24 | super.onViewCreated(view, savedInstanceState); 25 | 26 | if (mListener != null) { 27 | mListener.onHostFragmentViewCreated(); 28 | } 29 | } 30 | 31 | public void setItemEnabled(int itemId, boolean enabled) { 32 | mAnnotationToolbarComponent.setItemEnabled(itemId, enabled); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/utils/DocumentViewUtils.kt: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.utils 2 | 3 | import kotlinx.coroutines.CoroutineScope 4 | import kotlinx.coroutines.Dispatchers 5 | import kotlinx.coroutines.Job 6 | import kotlinx.coroutines.launch 7 | import java.io.File 8 | import java.io.FileOutputStream 9 | import java.net.URL 10 | 11 | interface DownloadFileCallback { 12 | fun downloadSuccess(path : String) 13 | 14 | fun downloadFailed(e : Exception) 15 | } 16 | 17 | fun downloadFromURL(link : String, path: String, callback : DownloadFileCallback) { 18 | CoroutineScope(Job() + Dispatchers.IO).launch { 19 | try { 20 | URL(link).openStream().use { input -> 21 | FileOutputStream(File(path)).use { output -> 22 | input.copyTo(output) 23 | callback.downloadSuccess(path) 24 | } 25 | } 26 | 27 | } catch (e : Exception) { 28 | e.printStackTrace() 29 | callback.downloadFailed(e) 30 | } 31 | } 32 | } 33 | 34 | 35 | -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/utils/ReactUtils.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.utils; 2 | 3 | import android.content.ContentResolver; 4 | import android.content.Context; 5 | import android.net.Uri; 6 | import android.util.Base64; 7 | import android.util.Log; 8 | import android.webkit.URLUtil; 9 | 10 | import com.facebook.react.bridge.ReadableArray; 11 | import com.facebook.react.bridge.ReadableMap; 12 | import com.facebook.react.bridge.ReadableMapKeySetIterator; 13 | import com.pdftron.pdf.PDFDraw; 14 | import com.pdftron.pdf.Page; 15 | import com.pdftron.pdf.utils.Utils; 16 | import com.pdftron.pdf.PDFDoc; 17 | 18 | import org.apache.commons.io.FilenameUtils; 19 | import org.apache.commons.io.IOUtils; 20 | import org.json.JSONArray; 21 | import org.json.JSONException; 22 | import org.json.JSONObject; 23 | 24 | import java.io.File; 25 | import java.io.FileOutputStream; 26 | import java.net.URLEncoder; 27 | 28 | import static com.pdftron.reactnative.utils.Constants.*; 29 | 30 | public class ReactUtils { 31 | 32 | private static final String TAG = ReactUtils.class.getName(); 33 | 34 | public static Uri getUri(Context context, String path, boolean isBase64, String base64Extension) { 35 | if (context == null || path == null) { 36 | return null; 37 | } 38 | try { 39 | if (isBase64) { 40 | byte[] data = Base64.decode(path, Base64.DEFAULT); 41 | File tempFile = File.createTempFile("tmp", base64Extension); 42 | FileOutputStream fos = null; 43 | try { 44 | fos = new FileOutputStream(tempFile); 45 | IOUtils.write(data, fos); 46 | return Uri.fromFile(tempFile); 47 | } finally { 48 | IOUtils.closeQuietly(fos); 49 | } 50 | } 51 | Uri fileUri = Uri.parse(path); 52 | if (ContentResolver.SCHEME_ANDROID_RESOURCE.equals(fileUri.getScheme())) { 53 | String resNameWithExtension = fileUri.getLastPathSegment(); 54 | String extension = FilenameUtils.getExtension(resNameWithExtension); 55 | String resName = FilenameUtils.removeExtension(resNameWithExtension); 56 | int resId = Utils.getResourceRaw(context, resName); 57 | if (resId != 0) { 58 | File file = Utils.copyResourceToLocal(context, resId, 59 | resName, "." + extension); 60 | if (null != file && file.exists()) { 61 | fileUri = Uri.fromFile(file); 62 | } 63 | } 64 | } else if (ContentResolver.SCHEME_FILE.equals(fileUri.getScheme())) { 65 | File file = new File(fileUri.getPath()); 66 | fileUri = Uri.fromFile(file); 67 | } else if (URLUtil.isHttpUrl(path) || URLUtil.isHttpsUrl(path)) { 68 | // this is a link uri, let's encode the file name 69 | if (path.contains(" ")) { 70 | String filename = FilenameUtils.getName(path); 71 | if (filename.contains("?")) { 72 | filename = filename.substring(0, filename.indexOf("?")); // remove query params 73 | } 74 | String encodedName = URLEncoder.encode(filename, "UTF-8").replace("+", "%20"); 75 | String newUrl = path.replace(filename, encodedName); 76 | return Uri.parse(newUrl); 77 | } 78 | } 79 | return fileUri; 80 | } catch (Exception ex) { 81 | Log.e(TAG, ex.getMessage() != null ? ex.getMessage() : "unknown error"); 82 | ex.printStackTrace(); 83 | } 84 | return null; 85 | } 86 | 87 | public static JSONObject convertMapToJson(ReadableMap readableMap) throws JSONException { 88 | JSONObject object = new JSONObject(); 89 | ReadableMapKeySetIterator iterator = readableMap.keySetIterator(); 90 | while (iterator.hasNextKey()) { 91 | String key = iterator.nextKey(); 92 | switch (readableMap.getType(key)) { 93 | case Null: 94 | object.put(key, JSONObject.NULL); 95 | break; 96 | case Boolean: 97 | object.put(key, readableMap.getBoolean(key)); 98 | break; 99 | case Number: 100 | object.put(key, readableMap.getDouble(key)); 101 | break; 102 | case String: 103 | object.put(key, readableMap.getString(key)); 104 | break; 105 | case Map: 106 | object.put(key, convertMapToJson(readableMap.getMap(key))); 107 | break; 108 | case Array: 109 | object.put(key, convertArrayToJson(readableMap.getArray(key))); 110 | break; 111 | } 112 | } 113 | return object; 114 | } 115 | 116 | public static JSONArray convertArrayToJson(ReadableArray readableArray) throws JSONException { 117 | JSONArray array = new JSONArray(); 118 | for (int i = 0; i < readableArray.size(); i++) { 119 | switch (readableArray.getType(i)) { 120 | case Null: 121 | break; 122 | case Boolean: 123 | array.put(readableArray.getBoolean(i)); 124 | break; 125 | case Number: 126 | array.put(readableArray.getDouble(i)); 127 | break; 128 | case String: 129 | array.put(readableArray.getString(i)); 130 | break; 131 | case Map: 132 | array.put(convertMapToJson(readableArray.getMap(i))); 133 | break; 134 | case Array: 135 | array.put(convertArrayToJson(readableArray.getArray(i))); 136 | break; 137 | } 138 | } 139 | return array; 140 | } 141 | 142 | public static String exportAsImageHelper(PDFDoc doc, int pageNumber, double dpi, String exportFormat, boolean transparent) { 143 | PDFDraw draw = null; 144 | try { 145 | draw = new PDFDraw(); 146 | draw.setDPI(dpi); 147 | draw.setPageTransparent(transparent); 148 | if (pageNumber <= doc.getPageCount() && pageNumber >= 1) { 149 | Page pg = doc.getPage(pageNumber); 150 | String ext = "png"; 151 | if (KEY_EXPORT_FORMAT_BMP.equals(exportFormat)) { 152 | ext = "bmp"; 153 | } else if (KEY_EXPORT_FORMAT_JPEG.equals(exportFormat)) { 154 | ext = "jpeg"; 155 | } 156 | File tempFile = File.createTempFile("tmp", "." + ext); 157 | draw.export(pg, tempFile.getAbsolutePath(), exportFormat); 158 | return tempFile.getAbsolutePath(); 159 | } 160 | return null; 161 | } catch (Exception ex) { 162 | throw new RuntimeException(ex); 163 | } finally { 164 | if (draw != null) { 165 | try { 166 | draw.destroy(); 167 | } catch (Exception ignored) { 168 | } 169 | } 170 | } 171 | } 172 | } 173 | -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/viewmanagers/PDFViewCtrlViewManager.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.viewmanagers; 2 | 3 | import com.facebook.react.uimanager.ThemedReactContext; 4 | import com.facebook.react.uimanager.ViewGroupManager; 5 | import com.facebook.react.uimanager.annotations.ReactProp; 6 | import com.pdftron.reactnative.views.PDFViewCtrlView; 7 | 8 | import javax.annotation.Nonnull; 9 | 10 | public class PDFViewCtrlViewManager extends ViewGroupManager { 11 | private static final String REACT_CLASS = "RCTPDFViewCtrl"; 12 | 13 | @Override 14 | public String getName() { 15 | return REACT_CLASS; 16 | } 17 | 18 | @Override 19 | protected PDFViewCtrlView createViewInstance(ThemedReactContext reactContext) { 20 | PDFViewCtrlView pdfViewCtrlView = new PDFViewCtrlView(reactContext, null); 21 | pdfViewCtrlView.setup(reactContext); 22 | 23 | return pdfViewCtrlView; 24 | } 25 | 26 | @ReactProp(name = "document") 27 | public void setDocument(PDFViewCtrlView ctrl, @Nonnull String fileUriStr) { 28 | ctrl.setDocument(fileUriStr); 29 | } 30 | 31 | @Override 32 | public boolean needsCustomLayoutForChildren() { 33 | return true; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /android/src/main/java/com/pdftron/reactnative/views/PDFViewCtrlView.java: -------------------------------------------------------------------------------- 1 | package com.pdftron.reactnative.views; 2 | 3 | import android.content.Context; 4 | import android.net.Uri; 5 | import android.util.AttributeSet; 6 | import android.util.Log; 7 | import android.view.ViewGroup; 8 | 9 | import androidx.appcompat.app.AppCompatActivity; 10 | 11 | import com.facebook.react.uimanager.ThemedReactContext; 12 | import com.pdftron.pdf.PDFDoc; 13 | import com.pdftron.pdf.PDFViewCtrl; 14 | import com.pdftron.pdf.config.ToolManagerBuilder; 15 | import com.pdftron.pdf.utils.AppUtils; 16 | import com.pdftron.pdf.utils.Utils; 17 | import com.pdftron.reactnative.utils.ReactUtils; 18 | 19 | import javax.annotation.Nonnull; 20 | 21 | public class PDFViewCtrlView extends PDFViewCtrl { 22 | 23 | private static final String TAG = PDFViewCtrlView.class.getSimpleName(); 24 | 25 | private PDFDoc mPdfDoc = null; 26 | 27 | public PDFViewCtrlView(Context context, AttributeSet attrs) { 28 | super(context, attrs); 29 | } 30 | 31 | public PDFViewCtrlView(Context context, AttributeSet attrs, int defStyle) { 32 | super(context, attrs, defStyle); 33 | } 34 | 35 | public void setup(ThemedReactContext reactContext) { 36 | int width = ViewGroup.LayoutParams.MATCH_PARENT; 37 | int height = ViewGroup.LayoutParams.MATCH_PARENT; 38 | ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(width, height); 39 | setLayoutParams(params); 40 | try { 41 | AppUtils.setupPDFViewCtrl(this); 42 | } catch (Exception ex) { 43 | ex.printStackTrace(); 44 | } 45 | if (reactContext.getCurrentActivity() instanceof AppCompatActivity) { 46 | ToolManagerBuilder.from().build((AppCompatActivity) reactContext.getCurrentActivity(), this); 47 | } 48 | } 49 | 50 | public void setDocument(@Nonnull String path) { 51 | try { 52 | Uri fileUri = ReactUtils.getUri(getContext(), path, false, null); 53 | mPdfDoc = openPDFUri(fileUri, ""); 54 | } catch (Exception ex) { 55 | Log.e(TAG, ex.getMessage() != null ? ex.getMessage() : "unknown error"); 56 | ex.printStackTrace(); 57 | } 58 | } 59 | 60 | @Override 61 | protected void onAttachedToWindow() { 62 | super.onAttachedToWindow(); 63 | 64 | } 65 | 66 | @Override 67 | protected void onDetachedFromWindow() { 68 | super.onDetachedFromWindow(); 69 | 70 | destroy(); 71 | if (mPdfDoc != null) { 72 | Utils.closeQuietly(mPdfDoc); 73 | } 74 | } 75 | 76 | private final Runnable mLayoutRunnable = new Runnable() { 77 | @Override 78 | public void run() { 79 | measure( 80 | MeasureSpec.makeMeasureSpec(getWidth(), MeasureSpec.EXACTLY), 81 | MeasureSpec.makeMeasureSpec(getHeight(), MeasureSpec.EXACTLY)); 82 | layout(getLeft(), getTop(), getRight(), getBottom()); 83 | } 84 | }; 85 | 86 | @Override 87 | public void requestLayout() { 88 | super.requestLayout(); 89 | 90 | post(mLayoutRunnable); 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /android/src/main/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | STAMPER 5 | 6 | -------------------------------------------------------------------------------- /android/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 10 | 11 | 14 | 15 | -------------------------------------------------------------------------------- /application.properties: -------------------------------------------------------------------------------- 1 | detect.project.name=ApryseSDK/pdftron_react_native 2 | -------------------------------------------------------------------------------- /example/.buckconfig: -------------------------------------------------------------------------------- 1 | 2 | [android] 3 | target = Google Inc.:Google APIs:23 4 | 5 | [maven_repositories] 6 | central = https://repo1.maven.org/maven2 7 | -------------------------------------------------------------------------------- /example/.bundle/config: -------------------------------------------------------------------------------- 1 | BUNDLE_PATH: "vendor/bundle" 2 | BUNDLE_FORCE_RUBY_PLATFORM: 1 3 | -------------------------------------------------------------------------------- /example/.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: '@react-native-community', 4 | }; 5 | -------------------------------------------------------------------------------- /example/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore "BUCK" generated dirs 6 | /\.buckd/ 7 | 8 | ; Ignore polyfills 9 | node_modules/react-native/Libraries/polyfills/.* 10 | 11 | ; Flow doesn't support platforms 12 | .*/Libraries/Utilities/LoadingView.js 13 | 14 | .*/node_modules/resolve/test/resolver/malformed_package_json/package\.json$ 15 | 16 | [untyped] 17 | .*/node_modules/@react-native-community/cli/.*/.* 18 | 19 | [include] 20 | 21 | [libs] 22 | node_modules/react-native/interface.js 23 | node_modules/react-native/flow/ 24 | 25 | [options] 26 | emoji=true 27 | 28 | exact_by_default=true 29 | 30 | format.bracket_spacing=false 31 | 32 | module.file_ext=.js 33 | module.file_ext=.json 34 | module.file_ext=.ios.js 35 | 36 | munge_underscores=true 37 | 38 | module.name_mapper='^react-native/\(.*\)$' -> '/node_modules/react-native/\1' 39 | module.name_mapper='^@?[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> '/node_modules/react-native/Libraries/Image/RelativeImageStub' 40 | 41 | suppress_type=$FlowIssue 42 | suppress_type=$FlowFixMe 43 | suppress_type=$FlowFixMeProps 44 | suppress_type=$FlowFixMeState 45 | 46 | [lints] 47 | sketchy-null-number=warn 48 | sketchy-null-mixed=warn 49 | sketchy-number=warn 50 | untyped-type-import=warn 51 | nonstrict-import=warn 52 | deprecated-type=warn 53 | unsafe-getters-setters=warn 54 | unnecessary-invariant=warn 55 | signature-verification-failure=warn 56 | 57 | [strict] 58 | deprecated-type 59 | nonstrict-import 60 | sketchy-null 61 | unclear-type 62 | unsafe-getters-setters 63 | untyped-import 64 | untyped-type-import 65 | 66 | [version] 67 | ^0.176.3 68 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | build/ 8 | *.pbxuser 9 | !default.pbxuser 10 | *.mode1v3 11 | !default.mode1v3 12 | *.mode2v3 13 | !default.mode2v3 14 | *.perspectivev3 15 | !default.perspectivev3 16 | xcuserdata 17 | *.xccheckout 18 | *.moved-aside 19 | DerivedData 20 | *.hmap 21 | *.ipa 22 | *.xcuserstate 23 | ios/.xcode.env.local 24 | 25 | # Android/IntelliJ 26 | # 27 | build/ 28 | .idea 29 | .gradle 30 | local.properties 31 | *.iml 32 | *.hprof 33 | 34 | # node.js 35 | # 36 | node_modules/ 37 | npm-debug.log 38 | yarn-error.log 39 | 40 | # BUCK 41 | buck-out/ 42 | \.buckd/ 43 | *.keystore 44 | !debug.keystore 45 | 46 | # fastlane 47 | # 48 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 49 | # screenshots whenever they are needed. 50 | # For more information about the recommended setup visit: 51 | # https://docs.fastlane.tools/best-practices/source-control/ 52 | 53 | **/fastlane/report.xml 54 | **/fastlane/Preview.html 55 | **/fastlane/screenshots 56 | **/fastlane/test_output 57 | 58 | # Bundle artifact 59 | *.jsbundle 60 | 61 | # Ruby / CocoaPods 62 | /ios/Pods/ 63 | /vendor/bundle 64 | /ios/Podfile.lock 65 | -------------------------------------------------------------------------------- /example/.prettierrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'avoid', 3 | bracketSameLine: true, 4 | bracketSpacing: false, 5 | singleQuote: true, 6 | trailingComma: 'all', 7 | }; 8 | -------------------------------------------------------------------------------- /example/.ruby-version: -------------------------------------------------------------------------------- 1 | 2.7.5 2 | -------------------------------------------------------------------------------- /example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} -------------------------------------------------------------------------------- /example/App.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react'; 2 | import { 3 | Platform, 4 | StyleSheet, 5 | Text, 6 | View, 7 | PermissionsAndroid, 8 | BackHandler, 9 | Alert 10 | } from 'react-native'; 11 | 12 | import { DocumentView, RNPdftron, Config } from 'react-native-pdftron'; 13 | 14 | type Props = {}; 15 | export default class App extends Component { 16 | 17 | constructor(props) { 18 | super(props); 19 | } 20 | 21 | onLeadingNavButtonPressed = () => { 22 | console.log('leading nav button pressed'); 23 | if (this._viewer) { 24 | this._viewer.setStampImageData().then((annotationId, pageNumber, stampImageDataUrl) => { 25 | annotationID = '75911d3a-f1fa-7a4f-8137-5885e3a4c4ae', 26 | pageNumber = 1, 27 | stampImageData = 'https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png'; 28 | }); 29 | } 30 | 31 | if (Platform.OS === 'ios') { 32 | Alert.alert( 33 | 'App', 34 | 'onLeadingNavButtonPressed', 35 | [ 36 | {text: 'OK', onPress: () => console.log('OK Pressed')}, 37 | ], 38 | { cancelable: true } 39 | ) 40 | } else { 41 | BackHandler.exitApp(); 42 | } 43 | } 44 | 45 | onDocumentLoaded = () => { 46 | // if (this._viewer) { 47 | // const xfdf = '\n\n\t\n\t\t\n\t\t\n\t\t\n\t\t\n\t\t\tfont: Roboto 24pt;color: #363636\n\t\t\t 1 1 1 RG 1 1 1 rg /F0 24 Tf \n\t\t\tHELLO PDFTRON!!!\n\t\t\t\n\t\t\n\t\t\n\t\n\t\n\t\t\n\t\n\t\n'; 48 | // this._viewer.importAnnotations(xfdf); 49 | // } 50 | } 51 | 52 | onAnnotationChanged = ({action, annotations}) => { 53 | // console.log('action', action); 54 | // console.log('annotations', annotations); 55 | // if (this._viewer) { 56 | // this._viewer.exportAnnotations({annotList: annotations}).then((xfdf) => { 57 | // console.log('xfdf for annotations', xfdf); 58 | // }); 59 | // } 60 | } 61 | 62 | onZoomChanged = ({zoom}) => { 63 | // console.log('zoom', zoom); 64 | } 65 | 66 | onExportAnnotationCommand = ({action, xfdfCommand}) => { 67 | console.log('action', action); 68 | console.log('xfdfCommand', xfdfCommand); 69 | } 70 | 71 | setStampImageData = ({annotationId, pageNumber, stampImageDataUrl}) => { 72 | annotationID = '75911d3a-f1fa-7a4f-8137-5885e3a4c4ae', 73 | pageNumber = 1, 74 | stampImageData = 'https://media.sproutsocial.com/uploads/2017/02/10x-featured-social-media-image-size.png'; 75 | } 76 | 77 | render() { 78 | const path = "https://pdftron.s3.amazonaws.com/downloads/pl/PDFTRON_about.pdf"; 79 | const myToolbar = { 80 | [Config.CustomToolbarKey.Id]: 'myToolbar', 81 | [Config.CustomToolbarKey.Name]: 'myToolbar', 82 | [Config.CustomToolbarKey.Icon]: Config.ToolbarIcons.FillAndSign, 83 | [Config.CustomToolbarKey.Items]: [Config.Tools.annotationCreateArrow, Config.Tools.annotationCreateCallout, Config.Buttons.undo] 84 | }; 85 | 86 | return ( 87 | this._viewer = c} 89 | // hideDefaultAnnotationToolbars={[Config.DefaultToolbars.Annotate]} 90 | // annotationToolbars={[Config.DefaultToolbars.Annotate, myToolbar]} 91 | hideAnnotationToolbarSwitcher={false} 92 | hideTopToolbars={false} 93 | hideTopAppNavBar={false} 94 | document={path} 95 | padStatusBar={true} 96 | showLeadingNavButton={true} 97 | leadingNavButtonIcon={Platform.OS === 'ios' ? 'ic_close_black_24px.png' : 'ic_arrow_back_white_24dp'} 98 | onLeadingNavButtonPressed={this.onLeadingNavButtonPressed} 99 | onDocumentLoaded={this.onDocumentLoaded} 100 | onAnnotationChanged={this.onAnnotationChanged} 101 | onExportAnnotationCommand={this.onExportAnnotationCommand} 102 | onZoomChanged={this.onZoomChanged} 103 | readOnly={false} 104 | disabledElements={[Config.Buttons.userBookmarkListButton]} 105 | disabledTools={[Config.Tools.annotationCreateLine, Config.Tools.annotationCreateRectangle]} 106 | fitMode={Config.FitMode.FitPage} 107 | layoutMode={Config.LayoutMode.Continuous} 108 | setStampImageData = {this.setStampImageData} 109 | openOutlineList = {true} 110 | /> 111 | ); 112 | } 113 | } 114 | 115 | const styles = StyleSheet.create({ 116 | container: { 117 | flex: 1, 118 | } 119 | }); 120 | -------------------------------------------------------------------------------- /example/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | # You may use http://rbenv.org/ or https://rvm.io/ to install and use this version 4 | ruby '2.7.5' 5 | 6 | gem 'cocoapods', '~> 1.11', '>= 1.11.2' 7 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # Usage 2 | 3 | 1. Install dependencies by running `yarn install`. This will also run `pod install` for iOS automatically. 4 | 2. Build and run the app by running: 5 | - iOS: `yarn ios` 6 | - Android: `yarn android` -------------------------------------------------------------------------------- /example/__tests__/App-test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import 'react-native'; 6 | import React from 'react'; 7 | import App from '../App'; 8 | 9 | // Note: test renderer must be required after react-native. 10 | import renderer from 'react-test-renderer'; 11 | 12 | it('renders correctly', () => { 13 | renderer.create(); 14 | }); 15 | -------------------------------------------------------------------------------- /example/android/app/_BUCK: -------------------------------------------------------------------------------- 1 | # To learn about Buck see [Docs](https://buckbuild.com/). 2 | # To run your application with Buck: 3 | # - install Buck 4 | # - `npm start` - to start the packager 5 | # - `cd android` 6 | # - `keytool -genkey -v -keystore keystores/debug.keystore -storepass android -alias androiddebugkey -keypass android -dname "CN=Android Debug,O=Android,C=US"` 7 | # - `./gradlew :app:copyDownloadableDepsToLibs` - make all Gradle compile dependencies available to Buck 8 | # - `buck install -r android/app` - compile, install and run application 9 | # 10 | 11 | load(":build_defs.bzl", "create_aar_targets", "create_jar_targets") 12 | 13 | lib_deps = [] 14 | 15 | create_aar_targets(glob(["libs/*.aar"])) 16 | 17 | create_jar_targets(glob(["libs/*.jar"])) 18 | 19 | android_library( 20 | name = "all-libs", 21 | exported_deps = lib_deps, 22 | ) 23 | 24 | android_library( 25 | name = "app-code", 26 | srcs = glob([ 27 | "src/main/java/**/*.java", 28 | ]), 29 | deps = [ 30 | ":all-libs", 31 | ":build_config", 32 | ":res", 33 | ], 34 | ) 35 | 36 | android_build_config( 37 | name = "build_config", 38 | package = "com.example", 39 | ) 40 | 41 | android_resource( 42 | name = "res", 43 | package = "com.example", 44 | res = "src/main/res", 45 | ) 46 | 47 | android_binary( 48 | name = "app", 49 | keystore = "//android/keystores:debug", 50 | manifest = "src/main/AndroidManifest.xml", 51 | package_type = "debug", 52 | deps = [ 53 | ":app-code", 54 | ], 55 | ) 56 | -------------------------------------------------------------------------------- /example/android/app/build_defs.bzl: -------------------------------------------------------------------------------- 1 | """Helper definitions to glob .aar and .jar targets""" 2 | 3 | def create_aar_targets(aarfiles): 4 | for aarfile in aarfiles: 5 | name = "aars__" + aarfile[aarfile.rindex("/") + 1:aarfile.rindex(".aar")] 6 | lib_deps.append(":" + name) 7 | android_prebuilt_aar( 8 | name = name, 9 | aar = aarfile, 10 | ) 11 | 12 | def create_jar_targets(jarfiles): 13 | for jarfile in jarfiles: 14 | name = "jars__" + jarfile[jarfile.rindex("/") + 1:jarfile.rindex(".jar")] 15 | lib_deps.append(":" + name) 16 | prebuilt_jar( 17 | name = name, 18 | binary_jar = jarfile, 19 | ) 20 | -------------------------------------------------------------------------------- /example/android/app/debug.keystore: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/debug.keystore -------------------------------------------------------------------------------- /example/android/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /usr/local/Cellar/android-sdk/24.3.3/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | -------------------------------------------------------------------------------- /example/android/app/src/debug/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /example/android/app/src/debug/java/com/example/ReactNativeFlipper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. 3 | * 4 | *

This source code is licensed under the MIT license found in the LICENSE file in the root 5 | * directory of this source tree. 6 | */ 7 | package com.example; 8 | 9 | import android.content.Context; 10 | import com.facebook.flipper.android.AndroidFlipperClient; 11 | import com.facebook.flipper.android.utils.FlipperUtils; 12 | import com.facebook.flipper.core.FlipperClient; 13 | import com.facebook.flipper.plugins.crashreporter.CrashReporterPlugin; 14 | import com.facebook.flipper.plugins.databases.DatabasesFlipperPlugin; 15 | import com.facebook.flipper.plugins.fresco.FrescoFlipperPlugin; 16 | import com.facebook.flipper.plugins.inspector.DescriptorMapping; 17 | import com.facebook.flipper.plugins.inspector.InspectorFlipperPlugin; 18 | import com.facebook.flipper.plugins.network.FlipperOkhttpInterceptor; 19 | import com.facebook.flipper.plugins.network.NetworkFlipperPlugin; 20 | import com.facebook.flipper.plugins.react.ReactFlipperPlugin; 21 | import com.facebook.flipper.plugins.sharedpreferences.SharedPreferencesFlipperPlugin; 22 | import com.facebook.react.ReactInstanceEventListener; 23 | import com.facebook.react.ReactInstanceManager; 24 | import com.facebook.react.bridge.ReactContext; 25 | import com.facebook.react.modules.network.NetworkingModule; 26 | import okhttp3.OkHttpClient; 27 | 28 | public class ReactNativeFlipper { 29 | public static void initializeFlipper(Context context, ReactInstanceManager reactInstanceManager) { 30 | if (FlipperUtils.shouldEnableFlipper(context)) { 31 | final FlipperClient client = AndroidFlipperClient.getInstance(context); 32 | 33 | client.addPlugin(new InspectorFlipperPlugin(context, DescriptorMapping.withDefaults())); 34 | client.addPlugin(new ReactFlipperPlugin()); 35 | client.addPlugin(new DatabasesFlipperPlugin(context)); 36 | client.addPlugin(new SharedPreferencesFlipperPlugin(context)); 37 | client.addPlugin(CrashReporterPlugin.getInstance()); 38 | 39 | NetworkFlipperPlugin networkFlipperPlugin = new NetworkFlipperPlugin(); 40 | NetworkingModule.setCustomClientBuilder( 41 | new NetworkingModule.CustomClientBuilder() { 42 | @Override 43 | public void apply(OkHttpClient.Builder builder) { 44 | builder.addNetworkInterceptor(new FlipperOkhttpInterceptor(networkFlipperPlugin)); 45 | } 46 | }); 47 | client.addPlugin(networkFlipperPlugin); 48 | client.start(); 49 | 50 | // Fresco Plugin needs to ensure that ImagePipelineFactory is initialized 51 | // Hence we run if after all native modules have been initialized 52 | ReactContext reactContext = reactInstanceManager.getCurrentReactContext(); 53 | if (reactContext == null) { 54 | reactInstanceManager.addReactInstanceEventListener( 55 | new ReactInstanceEventListener() { 56 | @Override 57 | public void onReactContextInitialized(ReactContext reactContext) { 58 | reactInstanceManager.removeReactInstanceEventListener(this); 59 | reactContext.runOnNativeModulesQueueThread( 60 | new Runnable() { 61 | @Override 62 | public void run() { 63 | client.addPlugin(new FrescoFlipperPlugin()); 64 | } 65 | }); 66 | } 67 | }); 68 | } else { 69 | client.addPlugin(new FrescoFlipperPlugin()); 70 | } 71 | } 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /example/android/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | 16 | 17 | 20 | 21 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import com.facebook.react.ReactActivity; 4 | import com.facebook.react.ReactActivityDelegate; 5 | import com.facebook.react.ReactRootView; 6 | 7 | public class MainActivity extends ReactActivity { 8 | 9 | /** 10 | * Returns the name of the main component registered from JavaScript. This is used to schedule 11 | * rendering of the component. 12 | */ 13 | @Override 14 | protected String getMainComponentName() { 15 | return "example"; 16 | } 17 | 18 | /** 19 | * Returns the instance of the {@link ReactActivityDelegate}. There the RootView is created and 20 | * you can specify the renderer you wish to use - the new renderer (Fabric) or the old renderer 21 | * (Paper). 22 | */ 23 | @Override 24 | protected ReactActivityDelegate createReactActivityDelegate() { 25 | return new MainActivityDelegate(this, getMainComponentName()); 26 | } 27 | 28 | public static class MainActivityDelegate extends ReactActivityDelegate { 29 | public MainActivityDelegate(ReactActivity activity, String mainComponentName) { 30 | super(activity, mainComponentName); 31 | } 32 | 33 | @Override 34 | protected ReactRootView createRootView() { 35 | ReactRootView reactRootView = new ReactRootView(getContext()); 36 | // If you opted-in for the New Architecture, we enable the Fabric Renderer. 37 | reactRootView.setIsFabric(BuildConfig.IS_NEW_ARCHITECTURE_ENABLED); 38 | return reactRootView; 39 | } 40 | 41 | @Override 42 | protected boolean isConcurrentRootEnabled() { 43 | // If you opted-in for the New Architecture, we enable Concurrent Root (i.e. React 18). 44 | // More on this on https://reactjs.org/blog/2022/03/29/react-v18.html 45 | return BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/MainApplication.java: -------------------------------------------------------------------------------- 1 | package com.example; 2 | 3 | import androidx.multidex.MultiDexApplication; 4 | import android.content.Context; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactApplication; 7 | import com.facebook.react.ReactInstanceManager; 8 | import com.facebook.react.ReactNativeHost; 9 | import com.facebook.react.ReactPackage; 10 | import com.facebook.react.config.ReactFeatureFlags; 11 | import com.facebook.soloader.SoLoader; 12 | import com.example.newarchitecture.MainApplicationReactNativeHost; 13 | import java.lang.reflect.InvocationTargetException; 14 | import java.util.List; 15 | 16 | public class MainApplication extends MultiDexApplication implements ReactApplication { 17 | 18 | private final ReactNativeHost mReactNativeHost = 19 | new ReactNativeHost(this) { 20 | @Override 21 | public boolean getUseDeveloperSupport() { 22 | return BuildConfig.DEBUG; 23 | } 24 | 25 | @Override 26 | protected List getPackages() { 27 | @SuppressWarnings("UnnecessaryLocalVariable") 28 | List packages = new PackageList(this).getPackages(); 29 | // Packages that cannot be autolinked yet can be added manually here, for example: 30 | // packages.add(new MyReactNativePackage()); 31 | return packages; 32 | } 33 | 34 | @Override 35 | protected String getJSMainModuleName() { 36 | return "index"; 37 | } 38 | }; 39 | 40 | private final ReactNativeHost mNewArchitectureNativeHost = 41 | new MainApplicationReactNativeHost(this); 42 | 43 | @Override 44 | public ReactNativeHost getReactNativeHost() { 45 | if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) { 46 | return mNewArchitectureNativeHost; 47 | } else { 48 | return mReactNativeHost; 49 | } 50 | } 51 | 52 | @Override 53 | public void onCreate() { 54 | super.onCreate(); 55 | // If you opted-in for the New Architecture, we enable the TurboModule system 56 | ReactFeatureFlags.useTurboModules = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED; 57 | SoLoader.init(this, /* native exopackage */ false); 58 | initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 59 | } 60 | 61 | /** 62 | * Loads Flipper in React Native templates. Call this in the onCreate method with something like 63 | * initializeFlipper(this, getReactNativeHost().getReactInstanceManager()); 64 | * 65 | * @param context 66 | * @param reactInstanceManager 67 | */ 68 | private static void initializeFlipper( 69 | Context context, ReactInstanceManager reactInstanceManager) { 70 | if (BuildConfig.DEBUG) { 71 | try { 72 | /* 73 | We use reflection here to pick up the class that initializes Flipper, 74 | since Flipper library is not available in release mode 75 | */ 76 | Class aClass = Class.forName("com.example.ReactNativeFlipper"); 77 | aClass 78 | .getMethod("initializeFlipper", Context.class, ReactInstanceManager.class) 79 | .invoke(null, context, reactInstanceManager); 80 | } catch (ClassNotFoundException e) { 81 | e.printStackTrace(); 82 | } catch (NoSuchMethodException e) { 83 | e.printStackTrace(); 84 | } catch (IllegalAccessException e) { 85 | e.printStackTrace(); 86 | } catch (InvocationTargetException e) { 87 | e.printStackTrace(); 88 | } 89 | } 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/newarchitecture/MainApplicationReactNativeHost.java: -------------------------------------------------------------------------------- 1 | package com.example.newarchitecture; 2 | 3 | import android.app.Application; 4 | import androidx.annotation.NonNull; 5 | import com.facebook.react.PackageList; 6 | import com.facebook.react.ReactInstanceManager; 7 | import com.facebook.react.ReactNativeHost; 8 | import com.facebook.react.ReactPackage; 9 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 10 | import com.facebook.react.bridge.JSIModulePackage; 11 | import com.facebook.react.bridge.JSIModuleProvider; 12 | import com.facebook.react.bridge.JSIModuleSpec; 13 | import com.facebook.react.bridge.JSIModuleType; 14 | import com.facebook.react.bridge.JavaScriptContextHolder; 15 | import com.facebook.react.bridge.ReactApplicationContext; 16 | import com.facebook.react.bridge.UIManager; 17 | import com.facebook.react.fabric.ComponentFactory; 18 | import com.facebook.react.fabric.CoreComponentsRegistry; 19 | import com.facebook.react.fabric.FabricJSIModuleProvider; 20 | import com.facebook.react.fabric.ReactNativeConfig; 21 | import com.facebook.react.uimanager.ViewManagerRegistry; 22 | import com.example.BuildConfig; 23 | import com.example.newarchitecture.components.MainComponentsRegistry; 24 | import com.example.newarchitecture.modules.MainApplicationTurboModuleManagerDelegate; 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | 28 | /** 29 | * A {@link ReactNativeHost} that helps you load everything needed for the New Architecture, both 30 | * TurboModule delegates and the Fabric Renderer. 31 | * 32 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 33 | * `newArchEnabled` property). Is ignored otherwise. 34 | */ 35 | public class MainApplicationReactNativeHost extends ReactNativeHost { 36 | public MainApplicationReactNativeHost(Application application) { 37 | super(application); 38 | } 39 | 40 | @Override 41 | public boolean getUseDeveloperSupport() { 42 | return BuildConfig.DEBUG; 43 | } 44 | 45 | @Override 46 | protected List getPackages() { 47 | List packages = new PackageList(this).getPackages(); 48 | // Packages that cannot be autolinked yet can be added manually here, for example: 49 | // packages.add(new MyReactNativePackage()); 50 | // TurboModules must also be loaded here providing a valid TurboReactPackage implementation: 51 | // packages.add(new TurboReactPackage() { ... }); 52 | // If you have custom Fabric Components, their ViewManagers should also be loaded here 53 | // inside a ReactPackage. 54 | return packages; 55 | } 56 | 57 | @Override 58 | protected String getJSMainModuleName() { 59 | return "index"; 60 | } 61 | 62 | @NonNull 63 | @Override 64 | protected ReactPackageTurboModuleManagerDelegate.Builder 65 | getReactPackageTurboModuleManagerDelegateBuilder() { 66 | // Here we provide the ReactPackageTurboModuleManagerDelegate Builder. This is necessary 67 | // for the new architecture and to use TurboModules correctly. 68 | return new MainApplicationTurboModuleManagerDelegate.Builder(); 69 | } 70 | 71 | @Override 72 | protected JSIModulePackage getJSIModulePackage() { 73 | return new JSIModulePackage() { 74 | @Override 75 | public List getJSIModules( 76 | final ReactApplicationContext reactApplicationContext, 77 | final JavaScriptContextHolder jsContext) { 78 | final List specs = new ArrayList<>(); 79 | 80 | // Here we provide a new JSIModuleSpec that will be responsible of providing the 81 | // custom Fabric Components. 82 | specs.add( 83 | new JSIModuleSpec() { 84 | @Override 85 | public JSIModuleType getJSIModuleType() { 86 | return JSIModuleType.UIManager; 87 | } 88 | 89 | @Override 90 | public JSIModuleProvider getJSIModuleProvider() { 91 | final ComponentFactory componentFactory = new ComponentFactory(); 92 | CoreComponentsRegistry.register(componentFactory); 93 | 94 | // Here we register a Components Registry. 95 | // The one that is generated with the template contains no components 96 | // and just provides you the one from React Native core. 97 | MainComponentsRegistry.register(componentFactory); 98 | 99 | final ReactInstanceManager reactInstanceManager = getReactInstanceManager(); 100 | 101 | ViewManagerRegistry viewManagerRegistry = 102 | new ViewManagerRegistry( 103 | reactInstanceManager.getOrCreateViewManagers(reactApplicationContext)); 104 | 105 | return new FabricJSIModuleProvider( 106 | reactApplicationContext, 107 | componentFactory, 108 | ReactNativeConfig.DEFAULT_CONFIG, 109 | viewManagerRegistry); 110 | } 111 | }); 112 | return specs; 113 | } 114 | }; 115 | } 116 | } 117 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/newarchitecture/components/MainComponentsRegistry.java: -------------------------------------------------------------------------------- 1 | package com.example.newarchitecture.components; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.proguard.annotations.DoNotStrip; 5 | import com.facebook.react.fabric.ComponentFactory; 6 | import com.facebook.soloader.SoLoader; 7 | 8 | /** 9 | * Class responsible to load the custom Fabric Components. This class has native methods and needs a 10 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 11 | * folder for you). 12 | * 13 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 14 | * `newArchEnabled` property). Is ignored otherwise. 15 | */ 16 | @DoNotStrip 17 | public class MainComponentsRegistry { 18 | static { 19 | SoLoader.loadLibrary("fabricjni"); 20 | } 21 | 22 | @DoNotStrip private final HybridData mHybridData; 23 | 24 | @DoNotStrip 25 | private native HybridData initHybrid(ComponentFactory componentFactory); 26 | 27 | @DoNotStrip 28 | private MainComponentsRegistry(ComponentFactory componentFactory) { 29 | mHybridData = initHybrid(componentFactory); 30 | } 31 | 32 | @DoNotStrip 33 | public static MainComponentsRegistry register(ComponentFactory componentFactory) { 34 | return new MainComponentsRegistry(componentFactory); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /example/android/app/src/main/java/com/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate.java: -------------------------------------------------------------------------------- 1 | package com.example.newarchitecture.modules; 2 | 3 | import com.facebook.jni.HybridData; 4 | import com.facebook.react.ReactPackage; 5 | import com.facebook.react.ReactPackageTurboModuleManagerDelegate; 6 | import com.facebook.react.bridge.ReactApplicationContext; 7 | import com.facebook.soloader.SoLoader; 8 | import java.util.List; 9 | 10 | /** 11 | * Class responsible to load the TurboModules. This class has native methods and needs a 12 | * corresponding C++ implementation/header file to work correctly (already placed inside the jni/ 13 | * folder for you). 14 | * 15 | *

Please note that this class is used ONLY if you opt-in for the New Architecture (see the 16 | * `newArchEnabled` property). Is ignored otherwise. 17 | */ 18 | public class MainApplicationTurboModuleManagerDelegate 19 | extends ReactPackageTurboModuleManagerDelegate { 20 | 21 | private static volatile boolean sIsSoLibraryLoaded; 22 | 23 | protected MainApplicationTurboModuleManagerDelegate( 24 | ReactApplicationContext reactApplicationContext, List packages) { 25 | super(reactApplicationContext, packages); 26 | } 27 | 28 | protected native HybridData initHybrid(); 29 | 30 | native boolean canCreateTurboModule(String moduleName); 31 | 32 | public static class Builder extends ReactPackageTurboModuleManagerDelegate.Builder { 33 | protected MainApplicationTurboModuleManagerDelegate build( 34 | ReactApplicationContext context, List packages) { 35 | return new MainApplicationTurboModuleManagerDelegate(context, packages); 36 | } 37 | } 38 | 39 | @Override 40 | protected synchronized void maybeLoadOtherSoLibraries() { 41 | if (!sIsSoLibraryLoaded) { 42 | // If you change the name of your application .so file in the Android.mk file, 43 | // make sure you update the name here as well. 44 | SoLoader.loadLibrary("example_appmodules"); 45 | sIsSoLibraryLoaded = true; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/Android.mk: -------------------------------------------------------------------------------- 1 | THIS_DIR := $(call my-dir) 2 | 3 | include $(REACT_ANDROID_DIR)/Android-prebuilt.mk 4 | 5 | # If you wish to add a custom TurboModule or Fabric component in your app you 6 | # will have to include the following autogenerated makefile. 7 | # include $(GENERATED_SRC_DIR)/codegen/jni/Android.mk 8 | include $(CLEAR_VARS) 9 | 10 | LOCAL_PATH := $(THIS_DIR) 11 | 12 | # You can customize the name of your application .so file here. 13 | LOCAL_MODULE := example_appmodules 14 | 15 | LOCAL_C_INCLUDES := $(LOCAL_PATH) 16 | LOCAL_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.cpp) 17 | LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH) 18 | 19 | # If you wish to add a custom TurboModule or Fabric component in your app you 20 | # will have to uncomment those lines to include the generated source 21 | # files from the codegen (placed in $(GENERATED_SRC_DIR)/codegen/jni) 22 | # 23 | # LOCAL_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 24 | # LOCAL_SRC_FILES += $(wildcard $(GENERATED_SRC_DIR)/codegen/jni/*.cpp) 25 | # LOCAL_EXPORT_C_INCLUDES += $(GENERATED_SRC_DIR)/codegen/jni 26 | 27 | # Here you should add any native library you wish to depend on. 28 | LOCAL_SHARED_LIBRARIES := \ 29 | libfabricjni \ 30 | libfbjni \ 31 | libfolly_runtime \ 32 | libglog \ 33 | libjsi \ 34 | libreact_codegen_rncore \ 35 | libreact_debug \ 36 | libreact_nativemodule_core \ 37 | libreact_render_componentregistry \ 38 | libreact_render_core \ 39 | libreact_render_debug \ 40 | libreact_render_graphics \ 41 | librrc_view \ 42 | libruntimeexecutor \ 43 | libturbomodulejsijni \ 44 | libyoga 45 | 46 | LOCAL_CFLAGS := -DLOG_TAG=\"ReactNative\" -fexceptions -frtti -std=c++17 -Wall 47 | 48 | include $(BUILD_SHARED_LIBRARY) 49 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/MainApplicationModuleProvider.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationModuleProvider.h" 2 | 3 | #include 4 | 5 | namespace facebook { 6 | namespace react { 7 | 8 | std::shared_ptr MainApplicationModuleProvider( 9 | const std::string moduleName, 10 | const JavaTurboModule::InitParams ¶ms) { 11 | // Here you can provide your own module provider for TurboModules coming from 12 | // either your application or from external libraries. The approach to follow 13 | // is similar to the following (for a library called `samplelibrary`: 14 | // 15 | // auto module = samplelibrary_ModuleProvider(moduleName, params); 16 | // if (module != nullptr) { 17 | // return module; 18 | // } 19 | // return rncore_ModuleProvider(moduleName, params); 20 | return rncore_ModuleProvider(moduleName, params); 21 | } 22 | 23 | } // namespace react 24 | } // namespace facebook 25 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/MainApplicationModuleProvider.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | std::shared_ptr MainApplicationModuleProvider( 12 | const std::string moduleName, 13 | const JavaTurboModule::InitParams ¶ms); 14 | 15 | } // namespace react 16 | } // namespace facebook 17 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.cpp: -------------------------------------------------------------------------------- 1 | #include "MainApplicationTurboModuleManagerDelegate.h" 2 | #include "MainApplicationModuleProvider.h" 3 | 4 | namespace facebook { 5 | namespace react { 6 | 7 | jni::local_ref 8 | MainApplicationTurboModuleManagerDelegate::initHybrid( 9 | jni::alias_ref) { 10 | return makeCxxInstance(); 11 | } 12 | 13 | void MainApplicationTurboModuleManagerDelegate::registerNatives() { 14 | registerHybrid({ 15 | makeNativeMethod( 16 | "initHybrid", MainApplicationTurboModuleManagerDelegate::initHybrid), 17 | makeNativeMethod( 18 | "canCreateTurboModule", 19 | MainApplicationTurboModuleManagerDelegate::canCreateTurboModule), 20 | }); 21 | } 22 | 23 | std::shared_ptr 24 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 25 | const std::string name, 26 | const std::shared_ptr jsInvoker) { 27 | // Not implemented yet: provide pure-C++ NativeModules here. 28 | return nullptr; 29 | } 30 | 31 | std::shared_ptr 32 | MainApplicationTurboModuleManagerDelegate::getTurboModule( 33 | const std::string name, 34 | const JavaTurboModule::InitParams ¶ms) { 35 | return MainApplicationModuleProvider(name, params); 36 | } 37 | 38 | bool MainApplicationTurboModuleManagerDelegate::canCreateTurboModule( 39 | std::string name) { 40 | return getTurboModule(name, nullptr) != nullptr || 41 | getTurboModule(name, {.moduleName = name}) != nullptr; 42 | } 43 | 44 | } // namespace react 45 | } // namespace facebook 46 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/MainApplicationTurboModuleManagerDelegate.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | namespace facebook { 8 | namespace react { 9 | 10 | class MainApplicationTurboModuleManagerDelegate 11 | : public jni::HybridClass< 12 | MainApplicationTurboModuleManagerDelegate, 13 | TurboModuleManagerDelegate> { 14 | public: 15 | // Adapt it to the package you used for your Java class. 16 | static constexpr auto kJavaDescriptor = 17 | "Lcom/example/newarchitecture/modules/MainApplicationTurboModuleManagerDelegate;"; 18 | 19 | static jni::local_ref initHybrid(jni::alias_ref); 20 | 21 | static void registerNatives(); 22 | 23 | std::shared_ptr getTurboModule( 24 | const std::string name, 25 | const std::shared_ptr jsInvoker) override; 26 | std::shared_ptr getTurboModule( 27 | const std::string name, 28 | const JavaTurboModule::InitParams ¶ms) override; 29 | 30 | /** 31 | * Test-only method. Allows user to verify whether a TurboModule can be 32 | * created by instances of this class. 33 | */ 34 | bool canCreateTurboModule(std::string name); 35 | }; 36 | 37 | } // namespace react 38 | } // namespace facebook 39 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/MainComponentsRegistry.cpp: -------------------------------------------------------------------------------- 1 | #include "MainComponentsRegistry.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | MainComponentsRegistry::MainComponentsRegistry(ComponentFactory *delegate) {} 12 | 13 | std::shared_ptr 14 | MainComponentsRegistry::sharedProviderRegistry() { 15 | auto providerRegistry = CoreComponentsRegistry::sharedProviderRegistry(); 16 | 17 | // Custom Fabric Components go here. You can register custom 18 | // components coming from your App or from 3rd party libraries here. 19 | // 20 | // providerRegistry->add(concreteComponentDescriptorProvider< 21 | // AocViewerComponentDescriptor>()); 22 | return providerRegistry; 23 | } 24 | 25 | jni::local_ref 26 | MainComponentsRegistry::initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate) { 29 | auto instance = makeCxxInstance(delegate); 30 | 31 | auto buildRegistryFunction = 32 | [](EventDispatcher::Weak const &eventDispatcher, 33 | ContextContainer::Shared const &contextContainer) 34 | -> ComponentDescriptorRegistry::Shared { 35 | auto registry = MainComponentsRegistry::sharedProviderRegistry() 36 | ->createComponentDescriptorRegistry( 37 | {eventDispatcher, contextContainer}); 38 | 39 | auto mutableRegistry = 40 | std::const_pointer_cast(registry); 41 | 42 | mutableRegistry->setFallbackComponentDescriptor( 43 | std::make_shared( 44 | ComponentDescriptorParameters{ 45 | eventDispatcher, contextContainer, nullptr})); 46 | 47 | return registry; 48 | }; 49 | 50 | delegate->buildRegistryFunction = buildRegistryFunction; 51 | return instance; 52 | } 53 | 54 | void MainComponentsRegistry::registerNatives() { 55 | registerHybrid({ 56 | makeNativeMethod("initHybrid", MainComponentsRegistry::initHybrid), 57 | }); 58 | } 59 | 60 | } // namespace react 61 | } // namespace facebook 62 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/MainComponentsRegistry.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace facebook { 9 | namespace react { 10 | 11 | class MainComponentsRegistry 12 | : public facebook::jni::HybridClass { 13 | public: 14 | // Adapt it to the package you used for your Java class. 15 | constexpr static auto kJavaDescriptor = 16 | "Lcom/example/newarchitecture/components/MainComponentsRegistry;"; 17 | 18 | static void registerNatives(); 19 | 20 | MainComponentsRegistry(ComponentFactory *delegate); 21 | 22 | private: 23 | static std::shared_ptr 24 | sharedProviderRegistry(); 25 | 26 | static jni::local_ref initHybrid( 27 | jni::alias_ref, 28 | ComponentFactory *delegate); 29 | }; 30 | 31 | } // namespace react 32 | } // namespace facebook 33 | -------------------------------------------------------------------------------- /example/android/app/src/main/jni/OnLoad.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "MainApplicationTurboModuleManagerDelegate.h" 3 | #include "MainComponentsRegistry.h" 4 | 5 | JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { 6 | return facebook::jni::initialize(vm, [] { 7 | facebook::react::MainApplicationTurboModuleManagerDelegate:: 8 | registerNatives(); 9 | facebook::react::MainComponentsRegistry::registerNatives(); 10 | }); 11 | } 12 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/drawable/rn_edit_text_material.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 21 | 22 | 23 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /example/android/app/src/main/res/raw/getting_started.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/app/src/main/res/raw/getting_started.pdf -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | example 3 | 4 | -------------------------------------------------------------------------------- /example/android/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /example/android/build.gradle: -------------------------------------------------------------------------------- 1 | import org.apache.tools.ant.taskdefs.condition.Os 2 | 3 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 4 | 5 | buildscript { 6 | ext { 7 | buildToolsVersion = "31.0.0" 8 | minSdkVersion = 21 9 | compileSdkVersion = 34 10 | targetSdkVersion = 34 11 | 12 | if (System.properties['os.arch'] == "aarch64") { 13 | // For M1 Users we need to use the NDK 24 which added support for aarch64 14 | ndkVersion = "24.0.8215888" 15 | } else { 16 | // Otherwise we default to the side-by-side NDK version from AGP. 17 | ndkVersion = "21.4.7075529" 18 | } 19 | } 20 | repositories { 21 | google() 22 | mavenCentral() 23 | } 24 | dependencies { 25 | classpath("com.android.tools.build:gradle:7.1.1") 26 | classpath("com.facebook.react:react-native-gradle-plugin") 27 | classpath("de.undercouch:gradle-download-task:5.0.1") 28 | // NOTE: Do not place your application dependencies here; they belong 29 | // in the individual module build.gradle files 30 | } 31 | } 32 | 33 | allprojects { 34 | repositories { 35 | maven { 36 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 37 | url("$rootDir/../node_modules/react-native/android") 38 | } 39 | maven { 40 | // Android JSC is installed from npm 41 | url("$rootDir/../node_modules/jsc-android/dist") 42 | } 43 | mavenCentral { 44 | // We don't want to fetch react-native from Maven Central as there are 45 | // older versions over there. 46 | content { 47 | excludeGroup "com.facebook.react" 48 | } 49 | } 50 | google() 51 | maven { url 'https://www.jitpack.io' } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx512m -XX:MaxMetaspaceSize=256m 13 | org.gradle.jvmargs=-Xmx2048m -XX:MaxMetaspaceSize=512m 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true 19 | 20 | # AndroidX package structure to make it clearer which packages are bundled with the 21 | # Android operating system, and which are packaged with your app's APK 22 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 23 | android.useAndroidX=true 24 | # Automatically convert third-party libraries to use AndroidX 25 | android.enableJetifier=true 26 | 27 | # Version of flipper SDK to use with React Native 28 | FLIPPER_VERSION=0.125.0 29 | 30 | # Use this property to specify which architecture you want to build. 31 | # You can also override it from the CLI using 32 | # ./gradlew -PreactNativeArchitectures=x86_64 33 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 34 | 35 | # Use this property to enable support to the new architecture. 36 | # This will allow you to use TurboModules and the Fabric render in 37 | # your application. You should enable this flag either if you want 38 | # to write custom TurboModules/Fabric components OR use libraries that 39 | # are providing them. 40 | newArchEnabled=false 41 | 42 | PDFTRON_LICENSE_KEY= 43 | -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /example/android/gradlew: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Copyright © 2015-2021 the original authors. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # https://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | ############################################################################## 20 | # 21 | # Gradle start up script for POSIX generated by Gradle. 22 | # 23 | # Important for running: 24 | # 25 | # (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is 26 | # noncompliant, but you have some other compliant shell such as ksh or 27 | # bash, then to run this script, type that shell name before the whole 28 | # command line, like: 29 | # 30 | # ksh Gradle 31 | # 32 | # Busybox and similar reduced shells will NOT work, because this script 33 | # requires all of these POSIX shell features: 34 | # * functions; 35 | # * expansions «$var», «${var}», «${var:-default}», «${var+SET}», 36 | # «${var#prefix}», «${var%suffix}», and «$( cmd )»; 37 | # * compound commands having a testable exit status, especially «case»; 38 | # * various built-in commands including «command», «set», and «ulimit». 39 | # 40 | # Important for patching: 41 | # 42 | # (2) This script targets any POSIX shell, so it avoids extensions provided 43 | # by Bash, Ksh, etc; in particular arrays are avoided. 44 | # 45 | # The "traditional" practice of packing multiple parameters into a 46 | # space-separated string is a well documented source of bugs and security 47 | # problems, so this is (mostly) avoided, by progressively accumulating 48 | # options in "$@", and eventually passing that to Java. 49 | # 50 | # Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, 51 | # and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; 52 | # see the in-line comments for details. 53 | # 54 | # There are tweaks for specific operating systems such as AIX, CygWin, 55 | # Darwin, MinGW, and NonStop. 56 | # 57 | # (3) This script is generated from the Groovy template 58 | # https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt 59 | # within the Gradle project. 60 | # 61 | # You can find Gradle at https://github.com/gradle/gradle/. 62 | # 63 | ############################################################################## 64 | 65 | # Attempt to set APP_HOME 66 | 67 | # Resolve links: $0 may be a link 68 | app_path=$0 69 | 70 | # Need this for daisy-chained symlinks. 71 | while 72 | APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path 73 | [ -h "$app_path" ] 74 | do 75 | ls=$( ls -ld "$app_path" ) 76 | link=${ls#*' -> '} 77 | case $link in #( 78 | /*) app_path=$link ;; #( 79 | *) app_path=$APP_HOME$link ;; 80 | esac 81 | done 82 | 83 | APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit 84 | 85 | APP_NAME="Gradle" 86 | APP_BASE_NAME=${0##*/} 87 | 88 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 89 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' 90 | 91 | # Use the maximum available, or set MAX_FD != -1 to use that value. 92 | MAX_FD=maximum 93 | 94 | warn () { 95 | echo "$*" 96 | } >&2 97 | 98 | die () { 99 | echo 100 | echo "$*" 101 | echo 102 | exit 1 103 | } >&2 104 | 105 | # OS specific support (must be 'true' or 'false'). 106 | cygwin=false 107 | msys=false 108 | darwin=false 109 | nonstop=false 110 | case "$( uname )" in #( 111 | CYGWIN* ) cygwin=true ;; #( 112 | Darwin* ) darwin=true ;; #( 113 | MSYS* | MINGW* ) msys=true ;; #( 114 | NONSTOP* ) nonstop=true ;; 115 | esac 116 | 117 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 118 | 119 | 120 | # Determine the Java command to use to start the JVM. 121 | if [ -n "$JAVA_HOME" ] ; then 122 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 123 | # IBM's JDK on AIX uses strange locations for the executables 124 | JAVACMD=$JAVA_HOME/jre/sh/java 125 | else 126 | JAVACMD=$JAVA_HOME/bin/java 127 | fi 128 | if [ ! -x "$JAVACMD" ] ; then 129 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 130 | 131 | Please set the JAVA_HOME variable in your environment to match the 132 | location of your Java installation." 133 | fi 134 | else 135 | JAVACMD=java 136 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 137 | 138 | Please set the JAVA_HOME variable in your environment to match the 139 | location of your Java installation." 140 | fi 141 | 142 | # Increase the maximum file descriptors if we can. 143 | if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then 144 | case $MAX_FD in #( 145 | max*) 146 | MAX_FD=$( ulimit -H -n ) || 147 | warn "Could not query maximum file descriptor limit" 148 | esac 149 | case $MAX_FD in #( 150 | '' | soft) :;; #( 151 | *) 152 | ulimit -n "$MAX_FD" || 153 | warn "Could not set maximum file descriptor limit to $MAX_FD" 154 | esac 155 | fi 156 | 157 | # Collect all arguments for the java command, stacking in reverse order: 158 | # * args from the command line 159 | # * the main class name 160 | # * -classpath 161 | # * -D...appname settings 162 | # * --module-path (only if needed) 163 | # * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. 164 | 165 | # For Cygwin or MSYS, switch paths to Windows format before running java 166 | if "$cygwin" || "$msys" ; then 167 | APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) 168 | CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) 169 | 170 | JAVACMD=$( cygpath --unix "$JAVACMD" ) 171 | 172 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 173 | for arg do 174 | if 175 | case $arg in #( 176 | -*) false ;; # don't mess with options #( 177 | /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath 178 | [ -e "$t" ] ;; #( 179 | *) false ;; 180 | esac 181 | then 182 | arg=$( cygpath --path --ignore --mixed "$arg" ) 183 | fi 184 | # Roll the args list around exactly as many times as the number of 185 | # args, so each arg winds up back in the position where it started, but 186 | # possibly modified. 187 | # 188 | # NB: a `for` loop captures its iteration list before it begins, so 189 | # changing the positional parameters here affects neither the number of 190 | # iterations, nor the values presented in `arg`. 191 | shift # remove old arg 192 | set -- "$@" "$arg" # push replacement arg 193 | done 194 | fi 195 | 196 | # Collect all arguments for the java command; 197 | # * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of 198 | # shell script including quotes and variable substitutions, so put them in 199 | # double quotes to make sure that they get re-expanded; and 200 | # * put everything else in single quotes, so that it's not re-expanded. 201 | 202 | set -- \ 203 | "-Dorg.gradle.appname=$APP_BASE_NAME" \ 204 | -classpath "$CLASSPATH" \ 205 | org.gradle.wrapper.GradleWrapperMain \ 206 | "$@" 207 | 208 | # Use "xargs" to parse quoted args. 209 | # 210 | # With -n1 it outputs one arg per line, with the quotes and backslashes removed. 211 | # 212 | # In Bash we could simply go: 213 | # 214 | # readarray ARGS < <( xargs -n1 <<<"$var" ) && 215 | # set -- "${ARGS[@]}" "$@" 216 | # 217 | # but POSIX shell has neither arrays nor command substitution, so instead we 218 | # post-process each arg (as a line of input to sed) to backslash-escape any 219 | # character that might be a shell metacharacter, then use eval to reverse 220 | # that process (while maintaining the separation between arguments), and wrap 221 | # the whole thing up as a single "set" statement. 222 | # 223 | # This will of course break if any of these variables contains a newline or 224 | # an unmatched quote. 225 | # 226 | 227 | eval "set -- $( 228 | printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | 229 | xargs -n1 | 230 | sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | 231 | tr '\n' ' ' 232 | )" '"$@"' 233 | 234 | exec "$JAVACMD" "$@" 235 | -------------------------------------------------------------------------------- /example/android/gradlew.bat: -------------------------------------------------------------------------------- 1 | @rem 2 | @rem Copyright 2015 the original author or authors. 3 | @rem 4 | @rem Licensed under the Apache License, Version 2.0 (the "License"); 5 | @rem you may not use this file except in compliance with the License. 6 | @rem You may obtain a copy of the License at 7 | @rem 8 | @rem https://www.apache.org/licenses/LICENSE-2.0 9 | @rem 10 | @rem Unless required by applicable law or agreed to in writing, software 11 | @rem distributed under the License is distributed on an "AS IS" BASIS, 12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | @rem See the License for the specific language governing permissions and 14 | @rem limitations under the License. 15 | @rem 16 | 17 | @if "%DEBUG%" == "" @echo off 18 | @rem ########################################################################## 19 | @rem 20 | @rem Gradle startup script for Windows 21 | @rem 22 | @rem ########################################################################## 23 | 24 | @rem Set local scope for the variables with windows NT shell 25 | if "%OS%"=="Windows_NT" setlocal 26 | 27 | set DIRNAME=%~dp0 28 | if "%DIRNAME%" == "" set DIRNAME=. 29 | set APP_BASE_NAME=%~n0 30 | set APP_HOME=%DIRNAME% 31 | 32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter. 33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi 34 | 35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" 37 | 38 | @rem Find java.exe 39 | if defined JAVA_HOME goto findJavaFromJavaHome 40 | 41 | set JAVA_EXE=java.exe 42 | %JAVA_EXE% -version >NUL 2>&1 43 | if "%ERRORLEVEL%" == "0" goto execute 44 | 45 | echo. 46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 47 | echo. 48 | echo Please set the JAVA_HOME variable in your environment to match the 49 | echo location of your Java installation. 50 | 51 | goto fail 52 | 53 | :findJavaFromJavaHome 54 | set JAVA_HOME=%JAVA_HOME:"=% 55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 56 | 57 | if exist "%JAVA_EXE%" goto execute 58 | 59 | echo. 60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 61 | echo. 62 | echo Please set the JAVA_HOME variable in your environment to match the 63 | echo location of your Java installation. 64 | 65 | goto fail 66 | 67 | :execute 68 | @rem Setup the command line 69 | 70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 71 | 72 | 73 | @rem Execute Gradle 74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* 75 | 76 | :end 77 | @rem End local scope for the variables with windows NT shell 78 | if "%ERRORLEVEL%"=="0" goto mainEnd 79 | 80 | :fail 81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 82 | rem the _cmd.exe /c_ return code! 83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 84 | exit /b 1 85 | 86 | :mainEnd 87 | if "%OS%"=="Windows_NT" endlocal 88 | 89 | :omega -------------------------------------------------------------------------------- /example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'example' 2 | apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings) 3 | include ':app' 4 | includeBuild('../node_modules/react-native-gradle-plugin') 5 | 6 | if (settings.hasProperty("newArchEnabled") && settings.newArchEnabled == "true") { 7 | include(":ReactAndroid") 8 | project(":ReactAndroid").projectDir = file('../node_modules/react-native/ReactAndroid') 9 | include(":ReactAndroid:hermes-engine") 10 | project(":ReactAndroid:hermes-engine").projectDir = file('../node_modules/react-native/ReactAndroid/hermes-engine') 11 | } 12 | -------------------------------------------------------------------------------- /example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "displayName": "example" 4 | } -------------------------------------------------------------------------------- /example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:metro-react-native-babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /example/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @format 3 | */ 4 | 5 | import {AppRegistry} from 'react-native'; 6 | import App from './App'; 7 | import {name as appName} from './app.json'; 8 | 9 | AppRegistry.registerComponent(appName, () => App); 10 | -------------------------------------------------------------------------------- /example/ios/.xcode.env: -------------------------------------------------------------------------------- 1 | # This `.xcode.env` file is versioned and is used to source the environment 2 | # used when running script phases inside Xcode. 3 | # To customize your local environment, you can create an `.xcode.env.local` 4 | # file that is not versioned. 5 | 6 | # NODE_BINARY variable contains the PATH to the node executable. 7 | # 8 | # Customize the NODE_BINARY variable here. 9 | # For example, to use nvm with brew, add the following line 10 | # . "$(brew --prefix nvm)/nvm.sh" --no-use 11 | export NODE_BINARY=$(command -v node) 12 | -------------------------------------------------------------------------------- /example/ios/Podfile: -------------------------------------------------------------------------------- 1 | require_relative '../node_modules/react-native/scripts/react_native_pods' 2 | require_relative '../node_modules/@react-native-community/cli-platform-ios/native_modules' 3 | 4 | platform :ios, '12.4' 5 | install! 'cocoapods', :deterministic_uuids => false 6 | 7 | target 'example' do 8 | # PDFTron 9 | use_frameworks! 10 | pod 'PDFNet', podspec: 'https://pdftron.com/downloads/ios/react-native/latest.podspec' 11 | pod 'RNPdftron', :path => '../node_modules/react-native-pdftron' 12 | config = use_native_modules! 13 | 14 | # Flags change depending on the env values. 15 | flags = get_default_flags() 16 | 17 | use_react_native!( 18 | :path => config[:reactNativePath], 19 | # to enable hermes on iOS, change `false` to `true` and then install pods 20 | :hermes_enabled => flags[:hermes_enabled], 21 | :fabric_enabled => flags[:fabric_enabled], 22 | # An absolute path to your application root. 23 | :app_path => "#{Pod::Config.instance.installation_root}/.." 24 | ) 25 | 26 | target 'exampleTests' do 27 | inherit! :complete 28 | # Pods for testing 29 | end 30 | 31 | # Enables Flipper. 32 | # 33 | # Note that if you have use_frameworks! enabled, Flipper will not work and 34 | # you should disable the next line. 35 | # use_flipper!() 36 | 37 | post_install do |installer| 38 | react_native_post_install(installer) 39 | __apply_Xcode_12_5_M1_post_install_workaround(installer) 40 | end 41 | end 42 | -------------------------------------------------------------------------------- /example/ios/example.xcodeproj/xcshareddata/xcschemes/example.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 53 | 55 | 61 | 62 | 63 | 64 | 70 | 72 | 78 | 79 | 80 | 81 | 83 | 84 | 87 | 88 | 89 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | @interface AppDelegate : UIResponder 5 | 6 | @property (nonatomic, strong) UIWindow *window; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /example/ios/example/AppDelegate.mm: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | 3 | #import 4 | #import 5 | #import 6 | 7 | #import 8 | 9 | #if RCT_NEW_ARCH_ENABLED 10 | #import 11 | #import 12 | #import 13 | #import 14 | #import 15 | #import 16 | 17 | #import 18 | 19 | static NSString *const kRNConcurrentRoot = @"concurrentRoot"; 20 | 21 | @interface AppDelegate () { 22 | RCTTurboModuleManager *_turboModuleManager; 23 | RCTSurfacePresenterBridgeAdapter *_bridgeAdapter; 24 | std::shared_ptr _reactNativeConfig; 25 | facebook::react::ContextContainer::Shared _contextContainer; 26 | } 27 | @end 28 | #endif 29 | 30 | @implementation AppDelegate 31 | 32 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 33 | { 34 | RCTAppSetupPrepareApp(application); 35 | 36 | RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions]; 37 | 38 | #if RCT_NEW_ARCH_ENABLED 39 | _contextContainer = std::make_shared(); 40 | _reactNativeConfig = std::make_shared(); 41 | _contextContainer->insert("ReactNativeConfig", _reactNativeConfig); 42 | _bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer]; 43 | bridge.surfacePresenter = _bridgeAdapter.surfacePresenter; 44 | #endif 45 | 46 | NSDictionary *initProps = [self prepareInitialProps]; 47 | UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"example", initProps); 48 | 49 | if (@available(iOS 13.0, *)) { 50 | rootView.backgroundColor = [UIColor systemBackgroundColor]; 51 | } else { 52 | rootView.backgroundColor = [UIColor whiteColor]; 53 | } 54 | 55 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 56 | UIViewController *rootViewController = [UIViewController new]; 57 | rootViewController.view = rootView; 58 | self.window.rootViewController = rootViewController; 59 | [self.window makeKeyAndVisible]; 60 | return YES; 61 | } 62 | 63 | /// This method controls whether the `concurrentRoot`feature of React18 is turned on or off. 64 | /// 65 | /// @see: https://reactjs.org/blog/2022/03/29/react-v18.html 66 | /// @note: This requires to be rendering on Fabric (i.e. on the New Architecture). 67 | /// @return: `true` if the `concurrentRoot` feture is enabled. Otherwise, it returns `false`. 68 | - (BOOL)concurrentRootEnabled 69 | { 70 | // Switch this bool to turn on and off the concurrent root 71 | return true; 72 | } 73 | 74 | - (NSDictionary *)prepareInitialProps 75 | { 76 | NSMutableDictionary *initProps = [NSMutableDictionary new]; 77 | 78 | #ifdef RCT_NEW_ARCH_ENABLED 79 | initProps[kRNConcurrentRoot] = @([self concurrentRootEnabled]); 80 | #endif 81 | 82 | return initProps; 83 | } 84 | 85 | - (NSURL *)sourceURLForBridge:(RCTBridge *)bridge 86 | { 87 | #if DEBUG 88 | return [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index"]; 89 | #else 90 | return [[NSBundle mainBundle] URLForResource:@"main" withExtension:@"jsbundle"]; 91 | #endif 92 | } 93 | 94 | #if RCT_NEW_ARCH_ENABLED 95 | 96 | #pragma mark - RCTCxxBridgeDelegate 97 | 98 | - (std::unique_ptr)jsExecutorFactoryForBridge:(RCTBridge *)bridge 99 | { 100 | _turboModuleManager = [[RCTTurboModuleManager alloc] initWithBridge:bridge 101 | delegate:self 102 | jsInvoker:bridge.jsCallInvoker]; 103 | return RCTAppSetupDefaultJsExecutorFactory(bridge, _turboModuleManager); 104 | } 105 | 106 | #pragma mark RCTTurboModuleManagerDelegate 107 | 108 | - (Class)getModuleClassFromName:(const char *)name 109 | { 110 | return RCTCoreModulesClassProvider(name); 111 | } 112 | 113 | - (std::shared_ptr)getTurboModule:(const std::string &)name 114 | jsInvoker:(std::shared_ptr)jsInvoker 115 | { 116 | return nullptr; 117 | } 118 | 119 | - (std::shared_ptr)getTurboModule:(const std::string &)name 120 | initParams: 121 | (const facebook::react::ObjCTurboModule::InitParams &)params 122 | { 123 | return nullptr; 124 | } 125 | 126 | - (id)getModuleInstanceFromClass:(Class)moduleClass 127 | { 128 | return RCTAppSetupDefaultModuleFromClass(moduleClass); 129 | } 130 | 131 | #endif 132 | 133 | @end 134 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "scale" : "2x", 6 | "size" : "20x20" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "scale" : "3x", 11 | "size" : "20x20" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "scale" : "2x", 16 | "size" : "29x29" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "scale" : "3x", 21 | "size" : "29x29" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "scale" : "2x", 26 | "size" : "40x40" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "scale" : "3x", 31 | "size" : "40x40" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "scale" : "2x", 36 | "size" : "60x60" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "scale" : "3x", 41 | "size" : "60x60" 42 | }, 43 | { 44 | "idiom" : "ios-marketing", 45 | "scale" : "1x", 46 | "size" : "1024x1024" 47 | } 48 | ], 49 | "info" : { 50 | "author" : "xcode", 51 | "version" : 1 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "author" : "xcode", 4 | "version" : 1 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/ic_close_black_24px.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "filename" : "ic_close_black_24px.png", 5 | "idiom" : "universal", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "filename" : "ic_close_black_24px@2x.png", 10 | "idiom" : "universal", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "filename" : "ic_close_black_24px@3x.png", 15 | "idiom" : "universal", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "author" : "xcode", 21 | "version" : 1 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/ic_close_black_24px.imageset/ic_close_black_24px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/ios/example/Images.xcassets/ic_close_black_24px.imageset/ic_close_black_24px.png -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/ic_close_black_24px.imageset/ic_close_black_24px@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/ios/example/Images.xcassets/ic_close_black_24px.imageset/ic_close_black_24px@2x.png -------------------------------------------------------------------------------- /example/ios/example/Images.xcassets/ic_close_black_24px.imageset/ic_close_black_24px@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/ios/example/Images.xcassets/ic_close_black_24px.imageset/ic_close_black_24px@3x.png -------------------------------------------------------------------------------- /example/ios/example/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | example 9 | CFBundleExecutable 10 | $(EXECUTABLE_NAME) 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSRequiresIPhoneOS 26 | 27 | NSAppTransportSecurity 28 | 29 | NSAllowsArbitraryLoads 30 | 31 | NSExceptionDomains 32 | 33 | localhost 34 | 35 | NSExceptionAllowsInsecureHTTPLoads 36 | 37 | 38 | 39 | 40 | NSLocationWhenInUseUsageDescription 41 | 42 | UILaunchStoryboardName 43 | LaunchScreen 44 | UIRequiredDeviceCapabilities 45 | 46 | armv7 47 | 48 | UISupportedInterfaceOrientations 49 | 50 | UIInterfaceOrientationPortrait 51 | UIInterfaceOrientationLandscapeLeft 52 | UIInterfaceOrientationLandscapeRight 53 | 54 | UIViewControllerBasedStatusBarAppearance 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /example/ios/example/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 24 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /example/ios/example/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "AppDelegate.h" 4 | 5 | int main(int argc, char * argv[]) { 6 | @autoreleasepool { 7 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /example/ios/exampleTests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /example/ios/exampleTests/exampleTests.m: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | #import 5 | #import 6 | 7 | #define TIMEOUT_SECONDS 600 8 | #define TEXT_TO_LOOK_FOR @"Welcome to React" 9 | 10 | @interface exampleTests : XCTestCase 11 | 12 | @end 13 | 14 | @implementation exampleTests 15 | 16 | - (BOOL)findSubviewInView:(UIView *)view matching:(BOOL(^)(UIView *view))test 17 | { 18 | if (test(view)) { 19 | return YES; 20 | } 21 | for (UIView *subview in [view subviews]) { 22 | if ([self findSubviewInView:subview matching:test]) { 23 | return YES; 24 | } 25 | } 26 | return NO; 27 | } 28 | 29 | - (void)testRendersWelcomeScreen 30 | { 31 | UIViewController *vc = [[[RCTSharedApplication() delegate] window] rootViewController]; 32 | NSDate *date = [NSDate dateWithTimeIntervalSinceNow:TIMEOUT_SECONDS]; 33 | BOOL foundElement = NO; 34 | 35 | __block NSString *redboxError = nil; 36 | #ifdef DEBUG 37 | RCTSetLogFunction(^(RCTLogLevel level, RCTLogSource source, NSString *fileName, NSNumber *lineNumber, NSString *message) { 38 | if (level >= RCTLogLevelError) { 39 | redboxError = message; 40 | } 41 | }); 42 | #endif 43 | 44 | while ([date timeIntervalSinceNow] > 0 && !foundElement && !redboxError) { 45 | [[NSRunLoop mainRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 46 | [[NSRunLoop mainRunLoop] runMode:NSRunLoopCommonModes beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]]; 47 | 48 | foundElement = [self findSubviewInView:vc.view matching:^BOOL(UIView *view) { 49 | if ([view.accessibilityLabel isEqualToString:TEXT_TO_LOOK_FOR]) { 50 | return YES; 51 | } 52 | return NO; 53 | }]; 54 | } 55 | 56 | #ifdef DEBUG 57 | RCTSetLogFunction(RCTDefaultLogFunction); 58 | #endif 59 | 60 | XCTAssertNil(redboxError, @"RedBox error: %@", redboxError); 61 | XCTAssertTrue(foundElement, @"Couldn't find element with text '%@' in %d seconds", TEXT_TO_LOOK_FOR, TIMEOUT_SECONDS); 62 | } 63 | 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /example/ios/getting_started.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/ios/getting_started.pdf -------------------------------------------------------------------------------- /example/ios/ic_close_black_24px.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/ios/ic_close_black_24px.png -------------------------------------------------------------------------------- /example/ios/ic_close_black_24px@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/ios/ic_close_black_24px@2x.png -------------------------------------------------------------------------------- /example/ios/ic_close_black_24px@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ApryseSDK/pdftron-react-native/0a2c1fd6d90d71a05110580b8799e0207a923953/example/ios/ic_close_black_24px@3x.png -------------------------------------------------------------------------------- /example/metro.config.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Metro configuration for React Native 3 | * https://github.com/facebook/react-native 4 | * 5 | * @format 6 | */ 7 | 8 | module.exports = { 9 | transformer: { 10 | getTransformOptions: async () => ({ 11 | transform: { 12 | experimentalImportSupport: false, 13 | inlineRequires: true, 14 | }, 15 | }), 16 | }, 17 | }; 18 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "example", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "preandroid": "cd node_modules/react-native-pdftron && npm start && cd ../../", 7 | "android": "react-native run-android", 8 | "preios": "cd node_modules/react-native-pdftron && npm start && cd ../../", 9 | "ios": "react-native run-ios", 10 | "prestart": "cd node_modules/react-native-pdftron && npm start && cd ../../", 11 | "start": "react-native start", 12 | "test": "jest", 13 | "lint": "eslint ." 14 | }, 15 | "dependencies": { 16 | "deprecated-react-native-prop-types": "^2.3.0", 17 | "react": "^18.0.0", 18 | "react-native": "^0.69.1", 19 | "react-native-pdftron": "github:ApryseSDK/pdftron-react-native" 20 | }, 21 | "devDependencies": { 22 | "@babel/core": "^7.12.9", 23 | "@babel/runtime": "^7.12.5", 24 | "@react-native-community/eslint-config": "^2.0.0", 25 | "@types/react": "^18.0.14", 26 | "@types/react-native": "^0.69.1", 27 | "@types/prop-types": "^15.7.12", 28 | "babel-jest": "^26.6.3", 29 | "eslint": "^7.32.0", 30 | "jest": "^26.6.3", 31 | "metro-react-native-babel-preset": "^0.70.3", 32 | "react-test-renderer": "18.0.0" 33 | }, 34 | "jest": { 35 | "preset": "react-native" 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | import { NativeModules } from 'react-native'; 2 | import { PDFViewCtrl } from './src/PDFViewCtrl/PDFViewCtrl'; 3 | import { DocumentView } from './src/DocumentView/DocumentView'; 4 | import { Config } from './src/Config/Config'; 5 | import * as AnnotOptions from './src/AnnotOptions/AnnotOptions'; 6 | 7 | interface RNPdftron { 8 | initialize(licenseKey: string) : void; 9 | enableJavaScript(enabled: boolean) : void; 10 | getVersion() : Promise; 11 | getPlatformVersion() : Promise; 12 | getSystemFontList() : Promise; 13 | clearRubberStampCache() : Promise; 14 | encryptDocument(filePath: string, password: string, currentPassword: string) : Promise; 15 | pdfFromOffice(docxPath: string, options: {applyPageBreaksToSheet?: boolean, displayChangeTracking?: boolean, excelDefaultCellBorderWidth?: number, 16 | excelMaxAllowedCellCount?: number, locale?: string}) : Promise; 17 | pdfFromOfficeTemplate(docxPath: string, json: object) : Promise; 18 | exportAsImage(pageNumber: number, dpi: number, exportFormat: Config.ExportFormat, filePath: string, transparent: boolean) : Promise; 19 | clearSavedViewerState() : Promise; 20 | } 21 | 22 | const RNPdftron : RNPdftron = NativeModules.RNPdftron; 23 | 24 | export { 25 | RNPdftron, 26 | PDFViewCtrl, 27 | DocumentView, 28 | Config, 29 | AnnotOptions, 30 | }; 31 | -------------------------------------------------------------------------------- /ios/DocumentViewController/RNTPTCollaborationDocumentController.h: -------------------------------------------------------------------------------- 1 | #import "RNTPTDocumentController.h" 2 | 3 | #import 4 | 5 | NS_ASSUME_NONNULL_BEGIN 6 | 7 | @interface RNTPTCollaborationDocumentController : PTCollaborationDocumentController 8 | 9 | @property (nonatomic, weak, nullable) id delegate; 10 | 11 | @end 12 | 13 | NS_ASSUME_NONNULL_END 14 | -------------------------------------------------------------------------------- /ios/DocumentViewController/RNTPTCollaborationDocumentViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | #import "RNTPTDocumentViewController.h" 4 | 5 | NS_ASSUME_NONNULL_BEGIN 6 | 7 | @interface RNTPTCollaborationDocumentViewController : PTCollaborationDocumentViewController 8 | 9 | @property (nonatomic, weak, nullable) id delegate; 10 | 11 | @end 12 | 13 | NS_ASSUME_NONNULL_END 14 | -------------------------------------------------------------------------------- /ios/DocumentViewController/RNTPTDocumentController.h: -------------------------------------------------------------------------------- 1 | #import "RNTPTDocumentViewController.h" 2 | 3 | #import 4 | 5 | NS_ASSUME_NONNULL_BEGIN 6 | 7 | @class RNTPTDocumentController; 8 | 9 | @protocol RNTPTDocumentControllerDelegate 10 | @required 11 | 12 | @end 13 | 14 | @interface RNTPTDocumentController : PTDocumentController 15 | 16 | @property (nonatomic, weak, nullable) id delegate; 17 | 18 | @end 19 | 20 | NS_ASSUME_NONNULL_END 21 | -------------------------------------------------------------------------------- /ios/DocumentViewController/RNTPTDocumentViewController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NS_ASSUME_NONNULL_BEGIN 4 | 5 | @protocol RNTPTDocumentBaseViewControllerDelegate 6 | @required 7 | 8 | - (void)rnt_documentViewControllerDocumentLoaded:(PTDocumentBaseViewController *)documentViewController; 9 | 10 | - (void)rnt_documentViewControllerDidScroll:(PTDocumentBaseViewController *)documentViewController; 11 | 12 | - (void)rnt_documentViewControllerDidZoom:(PTDocumentBaseViewController *)documentViewController; 13 | 14 | - (void)rnt_documentViewControllerDidFinishZoom:(PTDocumentBaseViewController *)documentViewController; 15 | 16 | - (void)rnt_documentViewControllerLayoutDidChange:(PTDocumentBaseViewController *)documentViewController; 17 | 18 | - (BOOL)rnt_documentViewControllerIsTopToolbarEnabled:(PTDocumentBaseViewController *)documentViewController; 19 | 20 | - (BOOL)rnt_documentViewControllerAreTopToolbarsEnabled:(PTDocumentBaseViewController *)documentViewController; 21 | 22 | - (BOOL)rnt_documentViewControllerIsNavigationBarEnabled:(PTDocumentBaseViewController *)documentViewController; 23 | 24 | - (BOOL)rnt_documentViewControllerAreKeyboardShortcutsEnabled:(PTDocumentBaseViewController *)documentViewController; 25 | 26 | - (BOOL)rnt_documentViewController:(PTDocumentBaseViewController *)documentViewController filterMenuItemsForAnnotationSelectionMenu:(UIMenuController *)menuController forAnnotation:(PTAnnot *)annot; 27 | 28 | - (BOOL)rnt_documentViewController:(PTDocumentBaseViewController *)documentViewController filterMenuItemsForLongPressMenu:(UIMenuController *)menuController; 29 | 30 | - (void)rnt_documentViewController:(PTDocumentBaseViewController *)documentViewController didSelectAnnotations:(NSArray *)annotations onPageNumber:(int)pageNumber; 31 | 32 | - (void)rnt_documentViewControllerTextSearchDidStart:(PTDocumentBaseViewController *)documentViewController; 33 | 34 | - (void)rnt_documentViewControllerTextSearchDidFindResult:(PTDocumentBaseViewController *)documentViewController selection:(PTSelection *)selection; 35 | 36 | - (void)rnt_documentViewControllerSavedSignaturesChanged:(PTDocumentBaseViewController *)documentViewController; 37 | 38 | - (void)rnt_documentViewControllerPageDidMove:(PTDocumentBaseViewController *)documentViewController pageMovedFromPageNumber:(int)oldPageNumber toPageNumber:(int)newPageNumber; 39 | 40 | - (void)rnt_documentViewControllerPageAdded:(PTDocumentBaseViewController *)documentViewController pageNumber:(int)pageNumber; 41 | 42 | - (void)rnt_documentViewControllerPageRemoved:(PTDocumentBaseViewController *)documentViewController pageNumber:(int)pageNumber; 43 | 44 | - (void)rnt_documentViewControllerDidRotatePages:(PTDocumentBaseViewController *)documentViewController forPageNumbers:(NSIndexSet *)pageNumbers; 45 | 46 | - (void)rnt_documentViewControllerToolbarButtonPressed:(PTDocumentBaseViewController *)documentViewController buttonString:(NSString *)buttonString; 47 | 48 | @end 49 | 50 | @class RNTPTDocumentViewController; 51 | 52 | @protocol RNTPTDocumentViewControllerDelegate 53 | @required 54 | 55 | - (BOOL)rnt_documentViewControllerShouldGoBackToPan:(PTDocumentViewController *)documentViewController; 56 | 57 | @end 58 | 59 | @interface RNTPTDocumentViewController : PTDocumentViewController 60 | 61 | @property (nonatomic, weak, nullable) id delegate; 62 | 63 | @end 64 | 65 | NS_ASSUME_NONNULL_END 66 | -------------------------------------------------------------------------------- /ios/RNPdftron.h: -------------------------------------------------------------------------------- 1 | 2 | #if __has_include() 3 | #import 4 | #else 5 | #import "RCTBridgeModule.h" 6 | #endif 7 | 8 | @class PTPDFDoc; 9 | @interface RNPdftron : NSObject 10 | 11 | +(NSString*)exportAsImageHelper:(PTPDFDoc*)doc pageNumber:(int)pageNumber dpi:(int)dpi exportFormat:(NSString*)imageFormat transparent:(BOOL)transparent; 12 | 13 | @end 14 | 15 | -------------------------------------------------------------------------------- /ios/RNTPTDocumentViewManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNTPTDocumentViewManager.h 3 | // RNPdftron 4 | // 5 | // Copyright © 2018 PDFTron. All rights reserved. 6 | // 7 | 8 | #import "RNTPTDocumentView.h" 9 | 10 | #import 11 | 12 | @interface RNTPTDocumentViewManager : RCTViewManager 13 | 14 | @property (nonatomic, strong) NSMutableDictionary *documentViews; 15 | 16 | - (void)setToolModeForDocumentViewTag:(NSNumber *)tag toolMode:(NSString *)toolMode; 17 | 18 | - (BOOL)commitToolForDocumentViewTag:(NSNumber *)tag; 19 | 20 | - (NSString *)getDocumentPathForDocumentViewTag:(NSNumber *)tag; 21 | 22 | - (NSString*) exportAsImageForDocumentViewTag:(NSNumber*)tag pageNumber:(int)pageNumber dpi:(int)dpi exportFormat:(NSString*)exportFormat transparent:(BOOL)transparent; 23 | 24 | - (int)getPageCountForDocumentViewTag:(NSNumber *)tag; 25 | 26 | - (void)importBookmarkJsonForDocumentViewTag:(NSNumber *)tag bookmarkJson:(NSString *)bookmarkJson; 27 | 28 | - (void)openBookmarkListForDocumentViewTag:(NSNumber *)tag; 29 | 30 | - (NSString *)exportAnnotationsForDocumentViewTag:(NSNumber *)tag options:(NSDictionary *)options; 31 | 32 | - (nullable NSArray *)importAnnotationsForDocumentViewTag:(NSNumber *)tag xfdf:(NSString *)xfdfString replace:(BOOL)replace; 33 | 34 | - (void)flattenAnnotationsForDocumentViewTag:(NSNumber *)tag formsOnly:(BOOL)formsOnly; 35 | 36 | - (void)deleteAnnotationsForDocumentViewTag:(NSNumber *)tag annotations:(NSArray *)annotations; 37 | 38 | - (void)saveDocumentForDocumentViewTag:(NSNumber *)tag completionHandler:(void (^)(NSString * _Nullable filePath))completionHandler; 39 | 40 | - (void)setFlagForFieldsForDocumentViewTag:(NSNumber *)tag forFields:(NSArray *)fields setFlag:(PTFieldFlag)flag toValue:(BOOL)value; 41 | 42 | - (void)setValuesForFieldsForDocumentViewTag:(NSNumber *)tag map:(NSDictionary *)map; 43 | 44 | - (NSDictionary *)getFieldForDocumentViewTag:(NSNumber *)tag fieldName:(NSString *)fieldName; 45 | 46 | - (void)setFlagsForAnnotationsForDocumentViewTag:(NSNumber*) tag annotationFlagList:(NSArray *)annotationFlagList; 47 | 48 | - (void)selectAnnotationForDocumentViewTag:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber; 49 | 50 | - (void)setPropertiesForAnnotationForDocumentViewTag:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber propertyMap:(NSDictionary *)propertyMap; 51 | 52 | - (NSDictionary *)getPropertiesForAnnotationForDocumentViewTag:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber; 53 | 54 | - (void)setDrawAnnotationsForDocumentViewTag:(NSNumber *)tag drawAnnotations:(BOOL)drawAnnotations; 55 | 56 | - (void)setVisibilityForAnnotationForDocumentViewTag:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber visibility:(BOOL)visibility; 57 | 58 | - (void)setHighlightFieldsForDocumentViewTag:(NSNumber *)tag highlightFields:(BOOL)highlightFields; 59 | 60 | - (NSDictionary *)getAnnotationAtForDocumentViewTag:(NSNumber *)tag x:(NSInteger)x y:(NSInteger)y distanceThreshold:(double)distanceThreshold minimumLineWeight:(double)minimumLineWeight; 61 | 62 | - (NSArray *)getAnnotationListAtForDocumentViewTag:(NSNumber *)tag x1:(NSInteger)x1 y1:(NSInteger)y1 x2:(NSInteger)x2 y2:(NSInteger)y2; 63 | 64 | - (NSArray *)getAnnotationListOnPageForDocumentViewTag:(NSNumber *)tag pageNumber:(NSInteger)pageNumber; 65 | 66 | - (NSString *)getCustomDataForAnnotationForDocumentViewTag:(NSNumber *) tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber key:(NSString *)key; 67 | 68 | - (void)setAnnotationToolbarItemEnabled:(NSNumber *)tag itemId:(NSString *)itemId enable:(BOOL)enable; 69 | 70 | - (NSDictionary *)getPageCropBoxForDocumentViewTag:(NSNumber *)tag pageNumber:(NSInteger)pageNumber; 71 | 72 | - (NSMutableArray *)getAllFieldsForDocumentViewTag:(NSNumber *)tag pageNumber:(NSInteger)pageNumber; 73 | 74 | - (BOOL)setCurrentPageForDocumentViewTag:(NSNumber *)tag pageNumber:(NSInteger)pageNumber; 75 | 76 | - (NSArray *)getVisiblePagesForDocumentViewTag:(NSNumber *)tag; 77 | 78 | - (BOOL)gotoPreviousPageForDocumentViewTag:(NSNumber *)tag; 79 | 80 | - (BOOL)gotoNextPageForDocumentViewTag:(NSNumber *)tag; 81 | 82 | - (BOOL)gotoFirstPageForDocumentViewTag:(NSNumber *)tag; 83 | 84 | - (BOOL)gotoLastPageForDocumentViewTag:(NSNumber *)tag; 85 | 86 | -(void)showGoToPageViewForDocumentViewTag:(NSNumber *)tag; 87 | 88 | - (void)closeAllTabsForDocumentViewTag:(NSNumber *)tag; 89 | 90 | - (void)openTabSwitcherForDocumentViewTag:(NSNumber *)tag; 91 | 92 | - (double)getZoomForDocumentViewTag:(NSNumber *)tag; 93 | 94 | - (int)getPageRotationForDocumentViewTag:(NSNumber *)tag; 95 | 96 | - (void)rotateClockwiseForDocumentViewTag:(NSNumber *)tag; 97 | 98 | - (void)rotateCounterClockwiseForDocumentViewTag:(NSNumber *)tag; 99 | 100 | - (void)undoForDocumentViewTag:(NSNumber *)tag; 101 | 102 | - (void)redoForDocumentViewTag:(NSNumber *)tag; 103 | 104 | - (bool)canUndoForDocumentViewTag:(NSNumber *)tag; 105 | 106 | - (bool)canRedoForDocumentViewTag:(NSNumber *)tag; 107 | 108 | - (void)setZoomLimitsForDocumentViewTag:(nonnull NSNumber *)tag zoomLimitMode:(NSString *)zoomLimitMode minimum:(double)minimum maximum:(double)maximum; 109 | 110 | - (void)zoomWithCenterForDocumentViewTag:(nonnull NSNumber *)tag zoom:(double)zoom x:(int)x y:(int)y; 111 | 112 | - (void)zoomToRectForDocumentViewTag:(nonnull NSNumber *)tag pageNumber:(int)pageNumber rect:(NSDictionary *)rect; 113 | 114 | - (void)smartZoomForDocumentViewTag:(nonnull NSNumber *)tag x:(int)x y:(int)y animated:(BOOL)animated; 115 | 116 | - (NSDictionary *)getScrollPosForDocumentViewTag:(NSNumber *)tag; 117 | 118 | - (NSDictionary *)getCanvasSizeForDocumentViewTag:(NSNumber *)tag; 119 | 120 | - (NSArray *)convertScreenPointsToPagePointsForDocumentViewTag:(nonnull NSNumber *)tag points:(NSArray *)points; 121 | 122 | - (NSArray *)convertPagePointsToScreenPointsForDocumentViewTag:(nonnull NSNumber *)tag points:(NSArray *)points; 123 | 124 | - (int)getPageNumberFromScreenPointForDocumentViewTag:(nonnull NSNumber *)tag x:(double)x y:(double)y; 125 | 126 | - (void)setProgressiveRenderingForDocumentViewTag:(NSNumber *)tag progressiveRendering:(BOOL)progressiveRendering initialDelay:(NSInteger)initialDelay interval:(NSInteger)interval; 127 | 128 | - (void)setImageSmoothingforDocumentViewTag:(NSNumber *)tag imageSmoothing:(BOOL)imageSmoothing; 129 | 130 | - (void)setOverprintforDocumentViewTag:(NSNumber *)tag overprint:(NSString *)overprint; 131 | 132 | - (void)setPageBorderVisibilityForDocumentViewTag:(NSNumber *)tag pageBorderVisibility:(BOOL)pageBorderVisibility; 133 | 134 | - (void)setPageTransparencyGridForDocumentViewTag:(NSNumber *)tag pageTransparencyGrid:(BOOL)pageTransparencyGrid; 135 | 136 | - (void)setDefaultPageColorForDocumentViewTag:(NSNumber *)tag defaultPageColor:(NSDictionary *)defaultPageColor; 137 | 138 | - (void)setBackgroundColorForDocumentViewTag:(NSNumber *)tag backgroundColor:(NSDictionary *)backgroundColor; 139 | 140 | - (void)setColorPostProcessModeForDocumentViewTag:(NSNumber *)tag colorPostProcessMode:(NSString *)colorPostProcessMode; 141 | 142 | - (void)setColorPostProcessColorsForDocumentViewTag:(NSNumber *)tag whiteColor:(NSDictionary *)whiteColor blackColor:(NSDictionary *)blackColor; 143 | 144 | - (void)findTextForDocumentViewTag:(NSNumber *)tag searchString:(NSString *)searchString matchCase:(BOOL)matchCase matchWholeWord:(BOOL)matchWholeWord searchUp:(BOOL)searchUp regExp:(BOOL)regExp; 145 | 146 | - (void)cancelFindTextForDocumentViewTag:(NSNumber *)tag; 147 | 148 | - (void)openSearchForDocumentViewTag:(NSNumber *)tag; 149 | 150 | - (void)startSearchModeForDocumentViewTag:(NSNumber *)tag searchString:(NSString *)searchString matchCase:(BOOL)matchCase matchWholeWord:(BOOL)matchWholeWord; 151 | 152 | - (void)exitSearchModeForDocumentViewTag:(NSNumber *)tag; 153 | 154 | - (NSDictionary *)getSelectionForDocumentViewTag:(NSNumber *)tag pageNumber:(NSInteger)pageNumber; 155 | 156 | - (BOOL)hasSelectionForDocumentViewTag:(NSNumber *)tag; 157 | 158 | - (void)clearSelectionForDocumentViewTag:(NSNumber *)tag; 159 | 160 | - (NSDictionary *)getSelectionPageRangeForDocumentViewTag:(NSNumber *)tag; 161 | 162 | - (bool)hasSelectionOnPageForDocumentViewTag:(NSNumber *)tag pageNumber:(NSInteger)pageNumber; 163 | 164 | - (BOOL)selectInRectForDocumentViewTag:(NSNumber *)tag rect:(NSDictionary *)rect; 165 | 166 | - (BOOL)isThereTextInRectForDocumentViewTag:(NSNumber *)tag rect:(NSDictionary *)rect; 167 | 168 | - (void)selectAllForDocumentViewTag:(NSNumber *)tag; 169 | 170 | - (void)importAnnotationCommandForDocumentViewTag:(NSNumber *)tag xfdfCommand:(NSString *)xfdfCommand initialLoad:(BOOL)initialLoad; 171 | 172 | - (void)setCurrentToolbarForDocumentViewTag:(NSNumber *)tag toolbarTitle:(NSString*)toolbarTitle; 173 | 174 | - (void)openOutlineListForDocumentViewTag:(NSNumber *)tag; 175 | 176 | - (void)openLayersListForDocumentViewTag:(NSNumber *)tag; 177 | 178 | - (void)openNavigationListsForDocumentViewTag:(NSNumber *) tag; 179 | 180 | - (void)openAnnotationListForDocumentViewTag:(NSNumber *)tag; 181 | 182 | - (BOOL)isReflowModeForDocumentViewTag:(NSNumber *)tag; 183 | 184 | - (void)toggleReflow:(NSNumber *)tag; 185 | 186 | - (void)showViewSettingsForDocumentViewTag:(nonnull NSNumber *)tag rect:(NSDictionary *)rect; 187 | 188 | - (void)showAddPagesViewForDocumentViewTag:(nonnull NSNumber *)tag rect:(NSDictionary *)rect; 189 | 190 | - (void)shareCopyForDocumentViewTag:(nonnull NSNumber *)tag rect:(NSDictionary *)rect withFlattening:(BOOL)flattening; 191 | 192 | - (void)openThumbnailsViewForDocumentViewTag:(NSNumber *)tag; 193 | 194 | - (NSArray *)getSavedSignaturesForDocumentViewTag:(NSNumber *)tag; 195 | 196 | - (NSString *)getSavedSignatureFolderForDocumentViewTag:(NSNumber *)tag; 197 | 198 | #pragma mark - Hygen Generated Methods 199 | - (void)setStampImageDataForDocumentViewTag:(NSNumber *)tag annotationId:(NSString *)annotationId pageNumber:(NSInteger)pageNumber stampImageDataUrl:(NSString *)stampImageDataUrl; 200 | - (void)setFormFieldHighlightColorForDocumentViewTag:(NSNumber *)tag fieldHighlightColor:(NSDictionary *)fieldHighlightColor; 201 | @end 202 | -------------------------------------------------------------------------------- /ios/RNTPTDocumentViewModule.h: -------------------------------------------------------------------------------- 1 | 2 | #if __has_include() 3 | #import 4 | #else 5 | #import "RCTBridgeModule.h" 6 | #endif 7 | 8 | @interface RNTPTDocumentViewModule : NSObject 9 | 10 | @end 11 | 12 | -------------------------------------------------------------------------------- /ios/RNTPTNavigationController.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | NS_ASSUME_NONNULL_BEGIN 4 | 5 | @class RNTPTNavigationController; 6 | 7 | @protocol RNTPTNavigationControllerDelegate 8 | @required 9 | 10 | - (BOOL)navigationController:(RNTPTNavigationController *)navigationController shouldSetNavigationBarHidden:(BOOL)navigationBarHidden animated:(BOOL)animated; 11 | 12 | - (BOOL)navigationController:(RNTPTNavigationController *)navigationController shouldSetToolbarHidden:(BOOL)toolbarHidden animated:(BOOL)animated; 13 | 14 | @end 15 | 16 | @interface RNTPTNavigationController : UINavigationController 17 | 18 | @property (nonatomic, weak, nullable) id delegate; 19 | 20 | @end 21 | 22 | NS_ASSUME_NONNULL_END 23 | -------------------------------------------------------------------------------- /ios/RNTPTNavigationController.m: -------------------------------------------------------------------------------- 1 | #import "RNTPTNavigationController.h" 2 | 3 | NS_ASSUME_NONNULL_BEGIN 4 | 5 | @interface RNTPTNavigationController () 6 | 7 | @end 8 | 9 | NS_ASSUME_NONNULL_END 10 | 11 | @implementation RNTPTNavigationController 12 | 13 | @dynamic delegate; 14 | 15 | - (void)setNavigationBarHidden:(BOOL)hidden animated:(BOOL)animated 16 | { 17 | BOOL allowed = YES; 18 | 19 | if ([self.delegate respondsToSelector:@selector(navigationController: 20 | shouldSetNavigationBarHidden: 21 | animated:)]) { 22 | allowed = [self.delegate navigationController:self 23 | shouldSetNavigationBarHidden:hidden 24 | animated:animated]; 25 | } 26 | 27 | if (allowed) { 28 | [super setNavigationBarHidden:hidden animated:animated]; 29 | } 30 | } 31 | 32 | - (void)setToolbarHidden:(BOOL)hidden animated:(BOOL)animated 33 | { 34 | BOOL allowed = YES; 35 | 36 | if ([self.delegate respondsToSelector:@selector(navigationController: 37 | shouldSetToolbarHidden: 38 | animated:)]) { 39 | allowed = [self.delegate navigationController:self 40 | shouldSetToolbarHidden:hidden 41 | animated:animated]; 42 | } 43 | 44 | if (allowed) { 45 | [super setToolbarHidden:hidden animated:animated]; 46 | } 47 | } 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /ios/RNTPTPDFViewCtrl.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNTPTPDFViewCtrl.h 3 | // RNPdftron 4 | // 5 | // Copyright © 2018 PDFTron. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface RNTPTPDFViewCtrl : PTPDFViewCtrl 11 | 12 | @end 13 | -------------------------------------------------------------------------------- /ios/RNTPTPDFViewCtrl.m: -------------------------------------------------------------------------------- 1 | // 2 | // RNTPTPDFViewCtrl.m 3 | // RNPdftron 4 | // 5 | // Copyright © 2018 PDFTron. All rights reserved. 6 | // 7 | 8 | #import "RNTPTPDFViewCtrl.h" 9 | 10 | @implementation RNTPTPDFViewCtrl 11 | 12 | /* 13 | // Only override drawRect: if you perform custom drawing. 14 | // An empty implementation adversely affects performance during animation. 15 | - (void)drawRect:(CGRect)rect { 16 | // Drawing code 17 | } 18 | */ 19 | 20 | @end 21 | -------------------------------------------------------------------------------- /ios/RNTPTPDFViewCtrlManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // RNTPTPDFViewCtrlManager.h 3 | // RNPdftron 4 | // 5 | // Copyright © 2018 PDFTron. All rights reserved. 6 | // 7 | 8 | #import 9 | #import 10 | 11 | @interface RNTPTPDFViewCtrlManager : RCTViewManager { 12 | PTToolManager * _toolManager; 13 | } 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /ios/RNTPTPDFViewCtrlManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // RNTPTPDFViewCtrlManager.m 3 | // RNPdftron 4 | // 5 | // Copyright © 2018 PDFTron. All rights reserved. 6 | // 7 | 8 | #import "RNTPTPDFViewCtrlManager.h" 9 | #import "RNTPTPDFViewCtrl.h" 10 | 11 | @implementation RNTPTPDFViewCtrlManager 12 | 13 | RCT_EXPORT_MODULE() 14 | 15 | - (UIView *)view 16 | { 17 | // Create a new PDFViewCtrl 18 | RNTPTPDFViewCtrl* pdfViewCtrl = [[RNTPTPDFViewCtrl alloc] init]; 19 | 20 | _toolManager = [[PTToolManager alloc] initWithPDFViewCtrl:pdfViewCtrl]; 21 | [pdfViewCtrl setToolDelegate:_toolManager]; 22 | [_toolManager changeTool:[PTPanTool class]]; 23 | 24 | return pdfViewCtrl; 25 | } 26 | 27 | RCT_CUSTOM_VIEW_PROPERTY(document, NSString, RNTPTPDFViewCtrl) 28 | { 29 | if (json && [RCTConvert NSString:json]) { 30 | // Get the path to document in the app bundle. 31 | NSString* pdfPath = [[NSBundle mainBundle] pathForResource:json ofType:@"pdf"]; 32 | // Instantiate a new PDFDoc with the path to the file. 33 | PTPDFDoc* docToOpen = [[PTPDFDoc alloc] initWithFilepath:pdfPath]; 34 | // Set the document to display 35 | [view SetDoc:docToOpen]; 36 | } 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /lib/index.js: -------------------------------------------------------------------------------- 1 | import { NativeModules } from 'react-native'; 2 | import { PDFViewCtrl } from './src/PDFViewCtrl/PDFViewCtrl'; 3 | import { DocumentView } from './src/DocumentView/DocumentView'; 4 | import { Config } from './src/Config/Config'; 5 | import * as AnnotOptions from './src/AnnotOptions/AnnotOptions'; 6 | const RNPdftron = NativeModules.RNPdftron; 7 | export { RNPdftron, PDFViewCtrl, DocumentView, Config, AnnotOptions, }; 8 | -------------------------------------------------------------------------------- /lib/src/AnnotOptions/AnnotOptions.js: -------------------------------------------------------------------------------- 1 | export {}; 2 | -------------------------------------------------------------------------------- /lib/src/PDFViewCtrl/PDFViewCtrl.js: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | import PropTypes from 'prop-types'; 3 | import { requireNativeComponent, Platform } from 'react-native'; 4 | import { ViewPropTypes } from 'deprecated-react-native-prop-types'; 5 | const propTypes = { 6 | document: PropTypes.string.isRequired, 7 | ...ViewPropTypes, 8 | }; 9 | export class PDFViewCtrl extends PureComponent { 10 | static propTypes = propTypes; 11 | render() { 12 | return (); 15 | } 16 | } 17 | const name = Platform.OS === 'ios' ? 'RNTPTPDFViewCtrl' : 'RCTPDFViewCtrl'; 18 | const RCTPDFViewCtrl = requireNativeComponent(name); 19 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-pdftron", 3 | "version": "3.0.2-beta.142", 4 | "lockfileVersion": 1, 5 | "requires": true, 6 | "dependencies": { 7 | "@react-native/normalize-color": { 8 | "version": "2.1.0", 9 | "resolved": "https://registry.npmjs.org/@react-native/normalize-color/-/normalize-color-2.1.0.tgz", 10 | "integrity": "sha512-Z1jQI2NpdFJCVgpY+8Dq/Bt3d+YUi1928Q+/CZm/oh66fzM0RUl54vvuXlPJKybH4pdCZey1eDTPaLHkMPNgWA==" 11 | }, 12 | "@types/prop-types": { 13 | "version": "15.7.5", 14 | "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", 15 | "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==", 16 | "dev": true 17 | }, 18 | "@types/react": { 19 | "version": "18.0.25", 20 | "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.25.tgz", 21 | "integrity": "sha512-xD6c0KDT4m7n9uD4ZHi02lzskaiqcBxf4zi+tXZY98a04wvc0hi/TcCPC2FOESZi51Nd7tlUeOJY8RofL799/g==", 22 | "dev": true, 23 | "requires": { 24 | "@types/prop-types": "*", 25 | "@types/scheduler": "*", 26 | "csstype": "^3.0.2" 27 | } 28 | }, 29 | "@types/react-native": { 30 | "version": "0.70.6", 31 | "resolved": "https://registry.npmjs.org/@types/react-native/-/react-native-0.70.6.tgz", 32 | "integrity": "sha512-ynQ2jj0km9d7dbnyKqVdQ6Nti7VQ8SLTA/KKkkS5+FnvGyvij2AOo1/xnkBR/jnSNXuzrvGVzw2n0VWfppmfKw==", 33 | "dev": true, 34 | "requires": { 35 | "@types/react": "*" 36 | } 37 | }, 38 | "@types/scheduler": { 39 | "version": "0.16.2", 40 | "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", 41 | "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==", 42 | "dev": true 43 | }, 44 | "csstype": { 45 | "version": "3.1.1", 46 | "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", 47 | "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==", 48 | "dev": true 49 | }, 50 | "deprecated-react-native-prop-types": { 51 | "version": "2.3.0", 52 | "resolved": "https://registry.npmjs.org/deprecated-react-native-prop-types/-/deprecated-react-native-prop-types-2.3.0.tgz", 53 | "integrity": "sha512-pWD0voFtNYxrVqvBMYf5gq3NA2GCpfodS1yNynTPc93AYA/KEMGeWDqqeUB6R2Z9ZofVhks2aeJXiuQqKNpesA==", 54 | "requires": { 55 | "@react-native/normalize-color": "*", 56 | "invariant": "*", 57 | "prop-types": "*" 58 | } 59 | }, 60 | "invariant": { 61 | "version": "2.2.4", 62 | "resolved": "https://registry.npmjs.org/invariant/-/invariant-2.2.4.tgz", 63 | "integrity": "sha512-phJfQVBuaJM5raOpJjSfkiD6BpbCE4Ns//LaXl6wGYtUBY83nWS6Rf9tXm2e8VaK60JEjYldbPif/A2B1C2gNA==", 64 | "requires": { 65 | "loose-envify": "^1.0.0" 66 | } 67 | }, 68 | "js-tokens": { 69 | "version": "4.0.0", 70 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", 71 | "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==" 72 | }, 73 | "loose-envify": { 74 | "version": "1.4.0", 75 | "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", 76 | "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", 77 | "requires": { 78 | "js-tokens": "^3.0.0 || ^4.0.0" 79 | } 80 | }, 81 | "object-assign": { 82 | "version": "4.1.1", 83 | "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", 84 | "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==" 85 | }, 86 | "prop-types": { 87 | "version": "15.8.1", 88 | "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.8.1.tgz", 89 | "integrity": "sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==", 90 | "requires": { 91 | "loose-envify": "^1.4.0", 92 | "object-assign": "^4.1.1", 93 | "react-is": "^16.13.1" 94 | } 95 | }, 96 | "react": { 97 | "version": "18.2.0", 98 | "resolved": "https://registry.npmjs.org/react/-/react-18.2.0.tgz", 99 | "integrity": "sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==", 100 | "dev": true, 101 | "requires": { 102 | "loose-envify": "^1.1.0" 103 | } 104 | }, 105 | "react-is": { 106 | "version": "16.13.1", 107 | "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", 108 | "integrity": "sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==" 109 | }, 110 | "typescript": { 111 | "version": "4.8.4", 112 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.4.tgz", 113 | "integrity": "sha512-QCh+85mCy+h0IGff8r5XWzOVSbBO+KfeYrMQh7NJ58QujwcE22u+NUSmUxqF+un70P9GXKxa2HCNiTTMJknyjQ==", 114 | "dev": true 115 | } 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-native-pdftron", 3 | "title": "React Native Pdftron", 4 | "version": "3.0.4-17", 5 | "description": "React Native Pdftron", 6 | "main": "./lib/index.js", 7 | "typings": "index.ts", 8 | "scripts": { 9 | "copy-to-repo": "cd scripts && python3 fileCopy.py toRepo && cd ..", 10 | "copy-to-node-modules": "cd scripts && python3 fileCopy.py toModule && cd ..", 11 | "start": "tsc", 12 | "postinstall": "python3 scripts/newPodspecMessage.py", 13 | "prestart": "python3 scripts/newPodspecMessage.py", 14 | "prepublishOnly": "bash scripts/prepare.sh", 15 | "postpublish": "bash scripts/postpublish.sh" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "git+https://github.com/ApryseSDK/pdftron-react-native.git", 20 | "baseUrl": "https://github.com/ApryseSDK/pdftron-react-native" 21 | }, 22 | "license": "SEE LICENSE IN LICENSE", 23 | "homepage": "https://docs.apryse.com/", 24 | "keywords": [ 25 | "react-native", 26 | "PDFTron", 27 | "pdf", 28 | "office" 29 | ], 30 | "readmeFilename": "README.md", 31 | "dependencies": { 32 | "deprecated-react-native-prop-types": "*" 33 | }, 34 | "peerDependencies": { 35 | "react": "*", 36 | "react-native": "*", 37 | "prop-types": "*" 38 | }, 39 | "devDependencies": { 40 | "react": "*", 41 | "@types/react": "*", 42 | "@types/react-native": "*", 43 | "@types/prop-types": "*", 44 | "typescript": "*" 45 | } 46 | } -------------------------------------------------------------------------------- /polaris.yml: -------------------------------------------------------------------------------- 1 | version: "1" 2 | project: 3 | name: ${scm.git.repo} 4 | branch: ${scm.git.branch} 5 | revision: 6 | name: ${scm.git.commit} 7 | date: ${scm.git.commit.date} 8 | capture: 9 | fileSystem: 10 | java: 11 | files: 12 | - directory: ./android 13 | javascript: 14 | files: 15 | - directory: ./lib/src 16 | - excludeRegex: node_modules|__test__ 17 | typescript: 18 | files: 19 | - directory: ./src 20 | - excludeRegex: node_modules|__test__ 21 | build: 22 | buildCommands: 23 | - shell: [bash, -e, scripts/ios/run_polaris.sh] 24 | coverity: 25 | skipFiles: 26 | - "example/ios/Pods" 27 | analyze: 28 | mode: central 29 | install: 30 | coverity: 31 | version: default 32 | serverUrl: https://pdftron.polaris.synopsys.com/ 33 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | # scripts folder 2 | 3 | This folder is only for convenient file copying for pdftron react native, which does not in any way affect the implementation of this module. 4 | 5 | To run the scripts, you could go to [package.json](./../package.json) in the root to see the list of available scripts. 6 | 7 | For example, if script name is `copy-to-repo`, then navigate to the root of this repository, and run: 8 | 9 | ``` 10 | npm run copy-to-repo 11 | ``` 12 | 13 | ## Scripts 14 | 15 | ### copy-to-repo 16 | This script copies pdftron-react-native (node modules in example -> root level of this repository). It is mostly useful when you have finished the implementation and are one step away from committing. 17 | 18 | ### copy-to-node-modules 19 | This script copies pdftron-react-native (root level of this repository -> node modules in example). Generally, this has been done by `npm install` or `yarn install`, but it could still be useful if you are switching branches. 20 | 21 | -------------------------------------------------------------------------------- /scripts/fileCopy.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import shutil 4 | 5 | # NOTE: this script is only used to copy files under android, ios and src folders. 6 | 7 | REPO_DIR = os.path.dirname(os.path.dirname(__file__)) 8 | MODULE_DIR = os.path.join(REPO_DIR, 'example', 'node_modules', 'react-native-pdftron') 9 | 10 | COPY_FOLDER_LIST = ['android', 'ios', 'src'] 11 | 12 | toRepo = sys.argv[1] == 'toRepo' 13 | 14 | # The source and destination for copying process 15 | srcRoot = MODULE_DIR if toRepo else REPO_DIR 16 | dstRoot = REPO_DIR if toRepo else MODULE_DIR 17 | 18 | print(srcRoot) 19 | print(dstRoot) 20 | 21 | # delete original folders if exist and copy over 22 | for folder in COPY_FOLDER_LIST: 23 | src = os.path.join(srcRoot, folder) 24 | dst = os.path.join(dstRoot, folder) 25 | if (os.path.exists(dst)): 26 | shutil.rmtree(dst) 27 | shutil.copytree(src, dst) -------------------------------------------------------------------------------- /scripts/ios/run_polaris.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | readonly project_dir="example/" 4 | 5 | cd "${project_dir}" 6 | 7 | # Install the Flutter package dependencies, which contain Dart and native iOS code. 8 | 9 | echo "Installing node packages..." 10 | 11 | yarn install 12 | 13 | # Install the CocoaPods package dependencies. 14 | 15 | cd 'ios/' 16 | 17 | echo "Installing CocoaPods packages..." 18 | 19 | pod install 20 | 21 | # Build the iOS workspace. 22 | 23 | echo "Building iOS workspace..." 24 | 25 | xcodebuild \ 26 | -workspace 'example.xcworkspace' \ 27 | -scheme 'example' \ 28 | -configuration 'Debug' \ 29 | -destination 'generic/platform=iOS Simulator' \ 30 | clean build 31 | -------------------------------------------------------------------------------- /scripts/newPodspecMessage.py: -------------------------------------------------------------------------------- 1 | class bcolors: 2 | OKCYAN = '\033[96m' 3 | WARNING = '\033[93m' 4 | ENDC = '\033[0m' 5 | BOLD = '\033[1m' 6 | UNDERLINE = '\033[4m' 7 | 8 | print(bcolors.WARNING + bcolors.BOLD + "\n[January 2022]\nThere is a new podspec for the PDFTron iOS React Native wrapper:") 9 | print(bcolors.OKCYAN + bcolors.UNDERLINE + "https://pdftron.com/downloads/ios/react-native/latest.podspec" + bcolors.ENDC) 10 | print(bcolors.WARNING + "Please update your app's Podfile accordingly.\n" + bcolors.ENDC) -------------------------------------------------------------------------------- /scripts/postpublish.sh: -------------------------------------------------------------------------------- 1 | json -I -f package.json -e "this.name=\"react-native-pdftron\"" -------------------------------------------------------------------------------- /scripts/prepare.sh: -------------------------------------------------------------------------------- 1 | json -I -f package.json -e "this.name=\"@pdftron/react-native-pdf\"" -------------------------------------------------------------------------------- /scripts/update_version.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs'); 2 | 3 | function jsonReader(filePath, cb) { 4 | fs.readFile(filePath, 'utf-8', (err, fileData) => { 5 | if(err) { 6 | return cb && cb(err); 7 | } 8 | try { 9 | const object = JSON.parse(fileData); 10 | return cb && cb(null, object); 11 | } catch (err) { 12 | return cb && cb(err); 13 | } 14 | }); 15 | } 16 | 17 | jsonReader('./package.json', (err, data) => { 18 | if(err){ 19 | console.log(err); 20 | } else { 21 | let version = data.version.split('-'); 22 | version[1] =(parseInt(version[1])+1); 23 | data.version = version.join('-'); 24 | fs.writeFile('./package.json', JSON.stringify(data, null, 2), err => { 25 | if(err) { 26 | console.log(err); 27 | } 28 | }) 29 | } 30 | }) -------------------------------------------------------------------------------- /src/AnnotOptions/AnnotOptions.ts: -------------------------------------------------------------------------------- 1 | import {Config} from '../Config/Config'; 2 | 3 | export interface Annotation { 4 | id: string; 5 | pageNumber?: number; 6 | type?: string; 7 | pageRect?: Rect; 8 | screenRect?: Rect; 9 | } 10 | 11 | export interface Rect { 12 | height?: number; 13 | width?: number; 14 | x1: number; 15 | y1: number; 16 | x2: number; 17 | y2: number; 18 | } 19 | 20 | export type CropBox = Required; 21 | 22 | export interface Color { 23 | red: number; 24 | green: number; 25 | blue: number; 26 | } 27 | 28 | export interface ColorWithAlpha { 29 | red: number; 30 | green: number; 31 | blue: number; 32 | alpha: number; 33 | } 34 | 35 | export type RotationDegree = 0 | 90 | 180 | 270; 36 | 37 | export interface Field { 38 | fieldName: string; 39 | fieldType: string; 40 | fieldValue?: string | boolean | number | undefined; 41 | fieldHasAppearance?: boolean | undefined; 42 | } 43 | 44 | export interface Point { 45 | x: number; 46 | y: number; 47 | pageNumber?: number; 48 | } 49 | 50 | export type Quad = [Point, Point, Point, Point]; 51 | 52 | export interface TextSelectionResult { 53 | html: string; 54 | unicode: string; 55 | pageNumber: number; 56 | quads: Array; 57 | } 58 | 59 | export interface AnnotationFlag { 60 | id: string; 61 | pageNumber: number; 62 | flag: Config.AnnotationFlags; 63 | flagValue: boolean; 64 | } 65 | 66 | export interface AnnotationProperties { 67 | rect?: Rect; 68 | contents?: string; 69 | subject?: string; 70 | title?: string; 71 | contentRect?: Rect; 72 | customData?: object; 73 | strokeColor?: Color; 74 | } 75 | 76 | export interface LinkPressData { 77 | url: string; 78 | } 79 | 80 | export interface StickyNoteData { 81 | id: string; 82 | pageNumber: number; 83 | type: string; 84 | pageRect?: Rect; 85 | screenRect?: Rect; 86 | } -------------------------------------------------------------------------------- /src/PDFViewCtrl/PDFViewCtrl.tsx: -------------------------------------------------------------------------------- 1 | import React, { PureComponent } from 'react'; 2 | import PropTypes, { InferProps } from 'prop-types'; 3 | import { 4 | requireNativeComponent, 5 | Platform 6 | } from 'react-native'; 7 | import { ViewPropTypes } from 'deprecated-react-native-prop-types'; 8 | 9 | const propTypes = { 10 | document: PropTypes.string.isRequired, 11 | ...ViewPropTypes, 12 | } 13 | 14 | // Generates the prop types for TypeScript users, from PropTypes. 15 | type PDFViewCtrlProps = InferProps; 16 | 17 | export class PDFViewCtrl extends PureComponent { 18 | 19 | static propTypes = propTypes; 20 | 21 | render() { 22 | return ( 23 | 28 | ) 29 | } 30 | } 31 | 32 | const name = Platform.OS === 'ios' ? 'RNTPTPDFViewCtrl' : 'RCTPDFViewCtrl'; 33 | 34 | const RCTPDFViewCtrl = requireNativeComponent(name); 35 | -------------------------------------------------------------------------------- /src/index.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'deprecated-react-native-prop-types'; 2 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "moduleResolution": "Node", 4 | "target": "ESNext", 5 | "jsx": "react-native", 6 | "allowSyntheticDefaultImports": true, 7 | "esModuleInterop": true, 8 | "skipLibCheck": true, 9 | "declaration": false, 10 | "outDir": "./lib", 11 | "strict": true, 12 | "noEmitOnError": true, 13 | }, 14 | "include": ["index.ts", "src/**/*"], 15 | "exclude": ["node_modules", "**/*.spec.ts"] 16 | } --------------------------------------------------------------------------------