From a06bfebb876c8a7092dfcfb21b0c9c7993440aa4 Mon Sep 17 00:00:00 2001 From: akwanpdf <83605632+akwanpdf@users.noreply.github.com> Date: Thu, 23 Sep 2021 12:19:41 -0700 Subject: [PATCH] TypeScript support (#378) * Add TS Support: * Created declaration files * Finished declarations for Config.js * Completed the TS types for the DocumentView component * Updates to the typings of DocumentView.js * Use literals in config, add options file * Add DocumentView methods * Add DocumentView methods * Updated typings for Config.js * Add DocumentView methods * Completed the typings for RNPdftron * Refactor options * Updated: * Typings of the DocumentView props * API docs of onDocumentLoaded and onDocumentError * Use literals in method params * PDFViewCtrl TS support * Fixed typings for PDFViewCtrl * Changes to index.d.ts and document_view.d.ts * Added export for PDFViewCtrl in index.d.ts * Fixed config.options.d.ts exports in index.d.ts * Added exports for the remainig interfaces within document_view.d.ts * Fixed error in document_view.d.ts * Refactor exports and fix a type * specify object interface for onBehaviorActivated * Fixed onDocumentLoaded and onDocumentError typing * move types to own folder * Edit filepaths * Edit mode prop types * Edit onToolChanged types * Updated package.json files * Added missing import in AnnotOptions.d.ts * edit reflowOrientation type * edit defaultEraserType type * Use promises for method return types * make initialLoad optional * Updated interfaces * Rect to include width and height optional properties * Annotation to include pageRect and screenRect optional properties * make CropBox from Rect * Updated definition of CropBox * Add types from latest master updates * Use Record utility * Remove redundant null * Add save copy option buttons * Redefined CustomToolbarKey in ConfigOptions.d.ts * Added pageRect and screenRect to stickyNoteData * fix typo * Use parameter destructuring * migrate js files to ts, tsx * move d.ts files move d.ts files * Revert "move d.ts files" This reverts commit 1390bb33c271aedad8177601c4cfbc0b1543e84d. * generate new d.ts, .js files * add tsconfig to get correct output structure * Added a build script and updated the exports * Fixed build script * Restructed repo * fix typo * Updated PropTypes in DocumentView.tsx * Rename ConfigOptions to Config * Created custom PropTypes * Refactor event function params * Script for Build Process * Updating Build Process Script * document funcProp * Created functions to make propTypes easier to read * funcProp to func * arrayOfProp to arrayOf * oneOfProp to oneOf * use Validator, add JSDocs for functions * Edit comments, rename param val to obj * edit comments * Refactor and add JSDoc * Add JSDoc for propTypes for dev use * Use arrayOf for custom annotationToolbars items * Use template literal for validator Error string * make oneOf, arrayOf accept multiple objects * make oneOf, arrayOf accept multiple values * simplify oneOf, arrayOf * refactor, edit comments * Simplify arrayOf * Add pull_request to build event triggers * Revert "Add pull_request to build event triggers" This reverts commit 210bc33332b16b46ad6a03f08409bcb6bfe0deb4. * Add JSDoc examples * Edit JSDocs * Return null at end of validator function * also specify onChange event type * remove onChange from propTypes & clean comments * Refactor methods to use one Promise * enable allowSyntheticDefaultImports * minor edit to ts-ignore description * use strict mode * Make type-related dependencies any-ver devDependencies * Updated Field interfaces due to changes to master * Replaced an object type with its primitive version * Create npmignore file excl. lib folder * Add extra ts-ignore to onChange * Updated README and API docs in prep for TS release * Edit TypeScript docs * update Installation and Usage with TypeScript * move TS section of readme * Update TS support version in README, edit CONTRIBUTING * Remove extraneous args from PDFViewCtrl requireNativeComponent * Remove unused object * Updated PDFViewCtrl to match DocumentView * Made document a required prop in PDFViewCtrl * (test) Add a prestart script (#372) * Add prestart script to generate JS files * Change branch where we want builds to be * Added/edited minor details/wording * Add preandroid and preios scripts to generate lib * Removed rect from the Annotation interface * Removed PointWithPage interface * Edit build process comments * add periods to end of comments * clarify example branches * remove extra rect from StickyNoteData interface * avoid emitting JS files if there is type error * Added some comments to Config and PDFViewCtrl * Rename Pdftron interface to RNPdftron * Show 2 variants for constructor in Usage example * Explicitly mention PDFTron React Native dependency in README * Avoid "our", "we" * replace "Migrating to TypeScript" with small sentence in "All Users" * Updated API section on TypeScript * Add return type info for getSavedSignatureJpgFolder * (iOS) Remove old podspec nightly mentions (#379) * Remove podspec nightly mentions, no longer necessary * bump ver * iOS enable user bookmarks list editing by default (#380) * Set userBookmarksListEditingEnabled to true by default * bump version * change wording Co-authored-by: JamesTron * change wording Co-authored-by: JamesTron * change wording of TS version recommendation Co-authored-by: JamesTron * change wording of PR step Co-authored-by: JamesTron * link to wiki * Updated version to 2.0.3-beta.184 (#381) Updated Android version to snapshot 9.1.1-beta02 Updated version to 2.0.3-beta.184 * (iOS) defaultEraserType (#382) * (iOS) defaultEraserType prop * Remove duplicate docs and constants, update original docs * bump ver * Update to Android 9.1.1beta3 (#383) * (Support) (iOS) Quick Navigation Button (#384) * (iOS) showQuickNavigationButton * Updated documentation * Fixed mistake in documentation * Bump version number * Updated default value of prop to true * Updated Android version to 9.1.1-beta05 * Remove package-lock.json and edit build process to install deps first * Edit build process to apply changes from dev to master - Also update to major version Co-authored-by: Dominic Cupidon Co-authored-by: Jamie Dassoulas <20866295+JamieDass@users.noreply.github.com> Co-authored-by: JamesTron Co-authored-by: eamon-mallon <77021678+eamon-mallon@users.noreply.github.com> Co-authored-by: sgong-pdftron Co-authored-by: Dominic Cupidon <83605527+dcupidon@users.noreply.github.com> Co-authored-by: brandenfung2 --- .github/workflows/jsBuilder.yml | 45 ++ .gitignore | 3 + .npmignore | 49 ++ API.md | 48 +- CONTRIBUTING.md | 9 +- README.md | 39 +- android/build.gradle | 8 +- example/package.json | 3 + index.js | 16 - index.ts | 26 + ios/RNTPTDocumentView.h | 8 + ios/RNTPTDocumentView.m | 42 +- ios/RNTPTDocumentViewManager.m | 15 + package.json | 13 +- src/AnnotOptions/AnnotOptions.ts | 78 +++ src/Config/{Config.js => Config.ts} | 65 ++- src/Config/package.json | 6 - .../{DocumentView.js => DocumentView.tsx} | 511 ++++++++++-------- src/DocumentView/package.json | 6 - src/PDFViewCtrl/PDFViewCtrl.js | 41 -- src/PDFViewCtrl/PDFViewCtrl.tsx | 33 ++ src/PDFViewCtrl/package.json | 6 - tsconfig.json | 16 + 23 files changed, 748 insertions(+), 338 deletions(-) create mode 100644 .github/workflows/jsBuilder.yml create mode 100644 .npmignore delete mode 100644 index.js create mode 100644 index.ts create mode 100644 src/AnnotOptions/AnnotOptions.ts rename src/Config/{Config.js => Config.ts} (73%) delete mode 100644 src/Config/package.json rename src/DocumentView/{DocumentView.js => DocumentView.tsx} (58%) delete mode 100644 src/DocumentView/package.json delete mode 100644 src/PDFViewCtrl/PDFViewCtrl.js create mode 100644 src/PDFViewCtrl/PDFViewCtrl.tsx delete mode 100644 src/PDFViewCtrl/package.json create mode 100644 tsconfig.json diff --git a/.github/workflows/jsBuilder.yml b/.github/workflows/jsBuilder.yml new file mode 100644 index 000000000..8e9c5f97a --- /dev/null +++ b/.github/workflows/jsBuilder.yml @@ -0,0 +1,45 @@ +name: Transpile TS + +on: + push: + branches: [dev] # <-- Change this to the primary branch (for example, "dev" if you want all changes to `dev` to be watched). + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v2 + with: + persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token. + fetch-depth: 0 # otherwise, you will failed to push refs to dest repo. + + - name: Install dependencies + run: | + npm i + + - name: Node setup + uses: actions/setup-node@v2 + with: + node-version: '16' + cache: 'npm' + + - name: Build JavaScript files + run: | # Change last line to your build script command #. + npm run start + + - name: Force add JS files to override .gitignore + run: git add --force ./lib # <-- Change this to your build path. + + - name: Commit files + run: | # Change last line to your preferred commit message (I like `chore: build js files`). + git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git commit -m "Updating JS files" -a + + - name: Push changes + uses: ad-m/github-push-action@v0.6.0 + with: + force: true + github_token: ${{ secrets.GITHUB_TOKEN }} + branch: master # <-- Change this to the branch where you want builds to be (for example, "master" if you want changes to the primary branch to be applied to `master`). \ No newline at end of file diff --git a/.gitignore b/.gitignore index e53e706c4..a2a179893 100644 --- a/.gitignore +++ b/.gitignore @@ -47,3 +47,6 @@ buck-out/ example/android/app/src/main/assets/index.android.bundle example/android/app/src/main/assets/index.android.bundle.meta + +# Build +/lib \ No newline at end of file diff --git a/.npmignore b/.npmignore new file mode 100644 index 000000000..ba0fcd823 --- /dev/null +++ b/.npmignore @@ -0,0 +1,49 @@ + +# OSX +# +.DS_Store + +# node.js +# +node_modules/ +npm-debug.log +yarn-error.log + + +# Xcode +# +build/ +Pods/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + + +# Android/IntelliJ +# +build/ +.idea +.gradle +local.properties +*.iml + +# BUCK +buck-out/ +\.buckd/ +*.keystore + +example/android/app/src/main/assets/index.android.bundle +example/android/app/src/main/assets/index.android.bundle.meta \ No newline at end of file diff --git a/API.md b/API.md index cb6267f32..6a29b261c 100644 --- a/API.md +++ b/API.md @@ -1,5 +1,9 @@ # PDFTron React Native API +## TypeScript + +PDFTron React Native supports TypeScript. Since not all customers use the language, the typings used in this document will be described using normal JavaScript types. For TypeScript users, type information is automatically provided while coding, and exact type aliases and constants used in our custom typings can be found in [AnnotOptions](src/AnnotOptions) and [Config](src/Config) source folders. + ## RNPdftron RNPdftron contains static methods for global library initialization, configuration, and utility methods. @@ -225,10 +229,15 @@ Defines whether the viewer is read-only. If true, the UI will not allow the user /> ``` #### defaultEraserType -one of [`Config.EraserType`](./src/Config/Config.js) constants, optional +one of the [`Config.EraserType`](./src/Config/Config.js) constants, optional -Sets the default eraser tool type. Value only applied after a clean install. Android only. -Example: +Sets the default eraser tool type. Value only applied after a clean install. + +Eraser Type | Description +--- | --- +`annotationEraser` | Erases everything as an object; if you touch ink, the entire object is erased. +`hybrideEraser` | Erases ink by pixel, but erases other annotation types as objects. +`inkEraser` | Erases ink by pixel only. Android only. ```js { @@ -302,6 +317,12 @@ function, optional This function is called when document opening encounters an error. +Parameters: + +Name | Type | Description +--- | --- | --- +error | string | Error message produced + ```js { @@ -1302,22 +1323,7 @@ Defines annotation types that cannot be edited after creation. #### excludedAnnotationListTypes array of [`Config.Tools`](./src/Config/Config.js) constants, optional, defaults to none -Defines types to be excluded from the annotation list. This feature will be soon be added to the official iOS release; to access it in the meantime, you can use the following podspec in the Podfile: -``` -pod 'PDFNet', podspec: 'https://nightly-pdftron.s3-us-west-2.amazonaws.com/stable/2021-08-04/9.0/cocoapods/xcframeworks/pdfnet/2021-08-04_stable_rev77892.podspec' -``` - -and uncomment the following line in `ios/RNTPTDocumentView.m`: -```objc -- (void)excludeAnnotationListTypes:(NSArray *)excludedAnnotationListTypes documentViewController:(PTDocumentBaseViewController *)documentViewController -{ - ... - if (annotTypes.count > 0) { - //documentViewController.navigationListsViewController.annotationViewController.excludedAnnotationTypes = annotTypes; - } -} -``` - +Defines types to be excluded from the annotation list. Example use: ```js @@ -1536,7 +1542,7 @@ Defines whether the page stack navigation buttons will appear in the viewer. ``` #### showQuickNavigationButton -bool, optional, defaults to true, Android only +bool, optional, defaults to true Defines whether the quick navigation buttons will appear in the viewer. @@ -3211,8 +3217,6 @@ this._viewer.openOutlineList(); #### openLayersList On Android it displays the layers dialog while on iOS it displays the layers tab of the existing list container. If this tab has been disabled or there are no layers in the document, the method does nothing. -**Note** For proper functionality the PDFNet podspec with: https://nightly-pdftron.s3-us-west-2.amazonaws.com/stable/2021-07-16/9.0/cocoapods/pdfnet/2021-07-16_stable_rev77863.podspec - Returns a Promise. ```js diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 20bebbe17..21adf0404 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -8,9 +8,10 @@ ## Pull requests 1. Fork the repository. -2. Create a branch from `master`. -3. Update the source code. +2. Create a branch from `dev`. +3. Update the source code (in `*.ts` files). 4. Commit and push the changes with descriptive messages. -5. Create a pull request to `master`. +5. Create a pull request to `dev`. -\* Please note that all pull requests should be tied to an issue, and all but the most trivial pull requests should be discussed beforehand. \ No newline at end of file +\* Please note that all pull requests should be tied to an issue, and all but the most trivial pull requests should be discussed beforehand. +\*\* Changes made to `dev` will automatically be applied to `master`. For more detailed information on developing post-TypeScript migration, see the [wiki](https://github.com/PDFTron/pdftron-react-native/wiki). \ No newline at end of file diff --git a/README.md b/README.md index 6681a98e2..93be98c1c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,8 @@ - [Preview](#preview) - [Installation](#installation) - [Usage](#usage) -- [Components](#components) +- [TypeScript](#typescript) +- [Contributing](#contributing) - [License](#license) ## API @@ -16,6 +17,7 @@ APIs are available on the [API page](API.md). - npm or yarn - PDFTron SDK >= 9.0.0 - react-native >= 0.60.0 +- TypeScript >= 3.4.1 (optional; see [TypeScript](#typescript)) ## Preview @@ -33,7 +35,7 @@ The release can be found here: https://github.com/PDFTron/pdftron-react-native/r 0. If using yarn, do: `yarn global add react-native-cli` -1. First, follow the official getting started guide on [setting up the React Native environment](https://reactnative.dev/docs/environment-setup), [setting up the iOS and Android environment](https://reactnative.dev/docs/environment-setup), and [creating a React Native project](https://reactnative.dev/docs/environment-setup), the following steps will assume your app is created through `react-native init MyApp`. +1. First, follow the official getting started guide on [setting up the React Native environment](https://reactnative.dev/docs/environment-setup), [setting up the iOS and Android environment](https://reactnative.dev/docs/environment-setup), and [creating a React Native project](https://reactnative.dev/docs/environment-setup). The following steps will assume your app is created through `react-native init MyApp`. This guide also applies if you are using the [TypeScript template](https://reactnative.dev/docs/environment-setup#optional-using-a-specific-version-or-template). 2. In `MyApp` folder, install `react-native-pdftron` by calling: ```shell @@ -150,7 +152,7 @@ The release can be found here: https://github.com/PDFTron/pdftron-react-native/r + public class MainApplication extends MultiDexApplication implements ReactApplication { ``` -6. Replace `App.js` with what is shown [here](#usage) +6. Replace `App.js` (or `App.tsx`) with what is shown [here](#usage). 7. Finally in the root project directory, run `react-native run-android`. ### iOS @@ -166,13 +168,13 @@ The release can be found here: https://github.com/PDFTron/pdftron-react-native/r ``` 2. In the `ios` folder, run `pod install`. -3. Replace `App.js` with what is shown [here](#usage). +3. Replace `App.js` (or `App.tsx`) with what is shown [here](#usage). 4. Finally in the root project directory, run `react-native run-ios`. 5. (Optional) If you need a close button icon, you will need to add the PNG resources to `MyApp` as well, i.e. `ic_close_black_24px`. ## Usage -Replace `App.js` with the code below. +Replace `App.js` (or `App.tsx` if you are [using TypeScript](#typescript)) with the code below. If you set your path variable to point to a local storage file, then the `PermissionsAndroid` component is required to ensure that storage permission is properly granted. @@ -202,6 +204,8 @@ import { DocumentView, RNPdftron } from 'react-native-pdftron'; type Props = {}; export default class App extends Component { + // If you are using TypeScript, use `constructor(props: Props) {` + // Otherwise, use: constructor(props) { super(props); @@ -321,6 +325,31 @@ const styles = StyleSheet.create({ document="content://..." ``` +## TypeScript + +PDFTron React Native introduced support for TypeScript in version 3.0.0. This update mainly benefits those who already use TypeScript in their applications. It also provides certain benefits to all customers, including those who use JavaScript without TypeScript. + +To get access to TypeScript support, simply update your PDFTron React Native dependency to version 3.0.0 or higher. + +### All Users + +For non-TypeScript users, updating your PDFTron React Native dependency to version 3.0.0 or higher will not automatically install TypeScript itself, and you can continue to use the library as before (without TypeScript support). If you currently do not use TypeScript itself in your project and would like to, see [Adding TypeScript to an Existing Project](https://reactnative.dev/docs/typescript#adding-typescript-to-an-existing-project). + +Regardless of whether you use TypeScript, the following benefits are available: +- Proper API typings which can be used in tools such as [IntelliSense](https://code.visualstudio.com/docs/editor/intellisense). This offers insight into the data being passed without referring to the [API documentation](API.md). +- Greater type safety and reliability due to the migration of source files from JavaScript to TypeScript. +- Updated Add an API guides for [Android](https://www.pdftron.com/documentation/android/get-started/react-native/add-an-api/) and [iOS](https://www.pdftron.com/documentation/ios/get-started/react-native/add-an-api) to offer step-by-step, TypeScript-supported examples on accessing properties, methods, and events. Contributors should be aware that PRs must now be made to the `dev` branch (see [Contributing](./CONTRIBUTING.md)). + +If you have questions, head to the FAQ's Integration section for [Android](https://www.pdftron.com/documentation/android/faq) and [iOS](https://www.pdftron.com/documentation/ios/faq/). + +### TypeScript Users + +If you are an existing TypeScript user, then the custom typings will be available to you simply by updating your PDFTron React Native dependency to version 3.0.0 or higher. + +Note: +- TypeScript version 3.4.1+ is recommended. Although compilation still works with lower versions, typings may degrade to `any`. +- Due to the introduction of proper typings to PDFTron's APIs, your compiler may now give warnings or errors about your usage of these APIs. In most cases these will not prevent your app from running but it is advised that you address them to take full advantage of TypeScript. It is particularly important to address them if you use TypeScript to emit files and have enabled `noEmitOnError` in your `tsconfig.json`. + ## Contributing See [Contributing](./CONTRIBUTING.md) diff --git a/android/build.gradle b/android/build.gradle index a709f1ff6..a229b7a3f 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -15,7 +15,7 @@ rootProject.allprojects { google() jcenter() maven { - url "https://pdftron-maven.s3.amazonaws.com/release" + url "https://pdftron-maven.s3.amazonaws.com/snapshot" } } } @@ -55,7 +55,7 @@ repositories { dependencies { implementation "com.facebook.react:react-native:+" - implementation "com.pdftron:pdftron:9.1.0" - implementation "com.pdftron:tools:9.1.0" - implementation "com.pdftron:collab:9.1.0" + implementation "com.pdftron:pdftron:9.1.1-beta05" + implementation "com.pdftron:tools:9.1.1-beta05" + implementation "com.pdftron:collab:9.1.1-beta05" } diff --git a/example/package.json b/example/package.json index 698f786b2..c547258db 100644 --- a/example/package.json +++ b/example/package.json @@ -3,8 +3,11 @@ "version": "0.0.1", "private": true, "scripts": { + "preandroid": "cd node_modules/react-native-pdftron && npm start && cd ../../", "android": "react-native run-android", + "preios": "cd node_modules/react-native-pdftron && npm start && cd ../../", "ios": "react-native run-ios", + "prestart": "cd node_modules/react-native-pdftron && npm start && cd ../../", "start": "react-native start", "test": "jest", "lint": "eslint ." diff --git a/index.js b/index.js deleted file mode 100644 index e5d3aa9aa..000000000 --- a/index.js +++ /dev/null @@ -1,16 +0,0 @@ -import React, { Component } from 'react'; -import PropTypes from 'prop-types'; -import { NativeModules } from 'react-native'; - -import PDFViewCtrl from './src/PDFViewCtrl'; -import DocumentView from './src/DocumentView'; -import Config from './src/Config'; - -const { RNPdftron } = NativeModules; - -export { - RNPdftron, - PDFViewCtrl, - DocumentView, - Config -}; diff --git a/index.ts b/index.ts new file mode 100644 index 000000000..b52ab1b48 --- /dev/null +++ b/index.ts @@ -0,0 +1,26 @@ +import { NativeModules } from 'react-native'; +import { PDFViewCtrl } from './src/PDFViewCtrl/PDFViewCtrl'; +import { DocumentView } from './src/DocumentView/DocumentView'; +import { Config } from './src/Config/Config'; +import * as AnnotOptions from './src/AnnotOptions/AnnotOptions'; + +interface RNPdftron { + initialize(licenseKey: string) : void; + enableJavaScript(enabled: boolean) : void; + getVersion() : Promise; + getPlatformVersion() : Promise; + getSystemFontList() : Promise; + clearRubberStampCache() : Promise; + encryptDocument(filePath: string, password: string, currentPassword: string) : Promise; + pdfFromOfficeTemplate(docxPath: string, json: object) : Promise; +} + +const RNPdftron : RNPdftron = NativeModules.RNPdftron; + +export { + RNPdftron, + PDFViewCtrl, + DocumentView, + Config, + AnnotOptions, +}; \ No newline at end of file diff --git a/ios/RNTPTDocumentView.h b/ios/RNTPTDocumentView.h index b4cc7c924..b711fb022 100644 --- a/ios/RNTPTDocumentView.h +++ b/ios/RNTPTDocumentView.h @@ -254,6 +254,10 @@ static NSString * const PTTextSelectionQuadPointYKey = @"y"; static NSString * const PTTextSelectionPageRangeBeginKey = @"begin"; static NSString * const PTTextSelectionPageRangeEndKey = @"end"; +// DefaultEraserType keys +static NSString * const PTInkEraserModeAllKey = @"annotationEraser"; +static NSString * const PTInkEraserModePointsKey = @"hybrideEraser"; + // Default annotation toolbar names. typedef NSString * PTDefaultAnnotationToolbarKey; static const PTDefaultAnnotationToolbarKey PTAnnotationToolbarView = @"PDFTron_View"; @@ -435,6 +439,8 @@ static NSString * const PTSignaturesManager_signatureDirectory = @"PTSignaturesM @property (nonatomic, assign) BOOL annotationsListEditingEnabled; +@property (nonatomic, assign) BOOL showQuickNavigationButton; + @property (nonatomic, assign) BOOL showNavigationListAsSidePanelOnLargeDevices; @property (nonatomic, assign) BOOL restrictDownloadUsage; @@ -445,6 +451,8 @@ static NSString * const PTSignaturesManager_signatureDirectory = @"PTSignaturesM @property (nonatomic, copy, nullable) NSArray *excludedAnnotationListTypes; +@property (nonatomic, copy, nullable) NSString *defaultEraserType; + #pragma mark - Methods - (void)setToolMode:(NSString *)toolMode; diff --git a/ios/RNTPTDocumentView.m b/ios/RNTPTDocumentView.m index 8e1a5f91c..f993e7c7e 100644 --- a/ios/RNTPTDocumentView.m +++ b/ios/RNTPTDocumentView.m @@ -90,6 +90,10 @@ - (void)RNTPTDocumentView_commonInit _tempFilePaths = [[NSMutableArray alloc] init]; _showSavedSignatures = YES; + + _userBookmarksListEditingEnabled = YES; + + _showQuickNavigationButton = YES; } -(instancetype)initWithFrame:(CGRect)frame @@ -605,7 +609,7 @@ - (void)excludeAnnotationListTypes:(NSArray *)excludedAnnotationListT } if (annotTypes.count > 0) { - //documentViewController.navigationListsViewController.annotationViewController.excludedAnnotationTypes = annotTypes; + documentViewController.navigationListsViewController.annotationViewController.excludedAnnotationTypes = annotTypes; } } @@ -614,6 +618,26 @@ - (void)setInkMultiStrokeEnabled:(BOOL)inkMultiStrokeEnabled _inkMultiStrokeEnabled = inkMultiStrokeEnabled; } +- (void)setDefaultEraserType:(NSString *)defaultEraserType +{ + _defaultEraserType = defaultEraserType; + + if (self.currentDocumentViewController) { + [self applyDefaultEraserType:defaultEraserType documentViewController:self.currentDocumentViewController]; + } +} + +- (void)applyDefaultEraserType:(NSString *)defaultEraserType documentViewController:(PTDocumentBaseViewController *)documentViewController +{ + PTToolManager *toolManager = documentViewController.toolManager; + + if ([defaultEraserType isEqualToString:PTInkEraserModeAllKey]) { + toolManager.eraserMode = PTInkEraserModeAll; + } else if ([defaultEraserType isEqualToString:PTInkEraserModePointsKey]) { + toolManager.eraserMode = PTInkEraserModePoints; + } +} + #pragma mark - Disabled tools - (void)setDisabledTools:(NSArray *)disabledTools @@ -1896,8 +1920,15 @@ - (void)applyViewerSettings:(PTDocumentBaseViewController *)documentViewControll // Set User Bookmark List Editing documentViewController.navigationListsViewController.bookmarkViewController.readonly = !self.userBookmarksListEditingEnabled; + // Image in reflow mode enabled. documentViewController.reflowViewController.reflowMode = self.imageInReflowEnabled; + + // Set Default Eraser Type + [self applyDefaultEraserType:self.defaultEraserType documentViewController:documentViewController]; + + // Show Quick Navigation Button + documentViewController.navigationHistoryEnabled = self.showQuickNavigationButton; // Enable/disable restoring state (last read page). [NSUserDefaults.standardUserDefaults setBool:self.saveStateEnabled @@ -5105,7 +5136,14 @@ -(void)openLayersList } } -#pragma mark - Navigation List +#pragma mark - Navigation + +-(void)setShowQuickNavigationButton:(BOOL)showQuickNavigationButton +{ + _showQuickNavigationButton = showQuickNavigationButton; + + [self applyViewerSettings]; +} -(void)openNavigationLists { diff --git a/ios/RNTPTDocumentViewManager.m b/ios/RNTPTDocumentViewManager.m index 7c685f112..8be95a1da 100644 --- a/ios/RNTPTDocumentViewManager.m +++ b/ios/RNTPTDocumentViewManager.m @@ -487,6 +487,13 @@ - (instancetype)init } } +RCT_CUSTOM_VIEW_PROPERTY(showQuickNavigationButton, BOOL, RNTPTDocumentView) +{ + if (json) { + view.showQuickNavigationButton = [RCTConvert BOOL:json]; + } +} + RCT_CUSTOM_VIEW_PROPERTY(showNavigationListAsSidePanelOnLargeDevices, BOOL, RNTPTDocumentView) { if (json) { @@ -530,6 +537,14 @@ - (instancetype)init } } +RCT_CUSTOM_VIEW_PROPERTY(defaultEraserType, NSString, RNTPTDocumentView) +{ + if (json) { + view.defaultEraserType = [RCTConvert NSString:json]; + } +} + + - (UIView *)view { RNTPTDocumentView *documentView = [[RNTPTDocumentView alloc] init]; diff --git a/package.json b/package.json index b9ca093b1..52db0d629 100644 --- a/package.json +++ b/package.json @@ -1,12 +1,14 @@ { "name": "react-native-pdftron", "title": "React Native Pdftron", - "version": "2.0.3-beta.181", + "version": "3.0.0", "description": "React Native Pdftron", - "main": "index.js", + "main": "./lib/index.js", + "typings": "index.ts", "scripts": { "copy-to-repo": "cd scripts && python3 fileCopy.py toRepo && cd ..", - "copy-to-node-modules": "cd scripts && python3 fileCopy.py toModule && cd .." + "copy-to-node-modules": "cd scripts && python3 fileCopy.py toModule && cd ..", + "start": "tsc" }, "repository": { "type": "git", @@ -26,6 +28,9 @@ "prop-types": "*" }, "devDependencies": { - "react": "*" + "react": "*", + "@types/react": "*", + "@types/react-native": "*", + "typescript": "*" } } diff --git a/src/AnnotOptions/AnnotOptions.ts b/src/AnnotOptions/AnnotOptions.ts new file mode 100644 index 000000000..12edca35f --- /dev/null +++ b/src/AnnotOptions/AnnotOptions.ts @@ -0,0 +1,78 @@ +import {Config} from '../Config/Config'; + +export interface Annotation { + id: string; + pageNumber?: number; + type?: string; + pageRect?: Rect; + screenRect?: Rect; +} + +export interface Rect { + height?: number; + width?: number; + x1: number; + y1: number; + x2: number; + y2: number; +} + +export type CropBox = Required; + +export interface Color { + red: number; + green: number; + blue: number; +} + +export type RotationDegree = 0 | 90 | 180 | 270; + +export interface Field { + fieldName: string; + fieldType: string; + fieldValue?: string | boolean | number | undefined; +} + +export interface Point { + x: number; + y: number; + pageNumber?: number; +} + +export type Quad = [Point, Point, Point, Point]; + +export interface TextSelectionResult { + html: string; + unicode: string; + pageNumber: number; + quads: Array; +} + +export interface AnnotationFlag { + id: string; + pageNumber: number; + flag: Config.AnnotationFlags; + flagValue: boolean; +} + +export interface AnnotationProperties { + rect?: Rect; + contents?: string; + subject?: string; + title?: string; + contentRect?: Rect; + customData?: object; + strokeColor?: Color; +} + +export interface LinkPressData { + url: string; +} + +export interface StickyNoteData { + id: string; + pageNumber: number; + type: string; + pageRect?: Rect; + screenRect?: Rect; +} \ No newline at end of file diff --git a/src/Config/Config.js b/src/Config/Config.ts similarity index 73% rename from src/Config/Config.js rename to src/Config/Config.ts index f9cbb0952..133222861 100644 --- a/src/Config/Config.js +++ b/src/Config/Config.ts @@ -1,4 +1,4 @@ -export default { +export const Config = { // Buttons define the various kinds of buttons for the viewer Buttons: { @@ -143,7 +143,7 @@ export default { calibrate: 'calibrate', }, - // EraserType defines the type of earse that will be used when eraser is selected + // EraserType defines the type of eraser that will be used when eraser is selected EraserType: { annotationEraser: 'annotationEraser', hybrideEraser: 'hybrideEraser', @@ -269,4 +269,63 @@ export default { JPEG: "JPEG", PNG: "PNG", }, -}; +} as const; + +/** + * A generic used to create the custom types defined in the module below. + * + * The variable `T` represents the type information being passed into the generic. + * This generic accepts type information about the `Config` object above. We pass this + * information in using `typeof Config.*`, * is any object nested in the `Config` object. + * + * `keyof T` creates a union of the object's keys e.g + * `keyof typeof Config.ReflowOrientation == 'Horizonal' | 'Vertical'` + * + * `T[]` is the indexed access type and takes the union produced by a `keyof T` and outputs + * a union of value types corresponding to those keys, e.g. + * `ValueOf == "horizontal" | "vertical"` + * + * The above union is made up of string literal types because the `as const` operator sets the + * properties of the `Config` object to have literal types. + * + * You can learn more about these special operators here: + * - {@link https://www.typescriptlang.org/docs/handbook/2/typeof-types.html Typeof} + * - {@link https://www.typescriptlang.org/docs/handbook/2/keyof-types.html Keyof} + * - {@link https://www.typescriptlang.org/docs/handbook/2/indexed-access-types.html Index Acess Types} + * - {@link https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-4.html#const-assertions Const Assertions} + */ +type ValueOf = T[keyof T]; + +/** + * A module containing custom types formed from the constants in the Config object. + * + * These types are used for props such as `disabledElements` and methods such as `exportAsImage` + */ +export module Config { + export type Buttons = ValueOf; + export type Tools = ValueOf; + export type FitMode = ValueOf; + export type LayoutMode = ValueOf; + export type FieldFlags = ValueOf; + export type AnnotationMenu = ValueOf; + export type EraserType = ValueOf; + export type LongPressMenu = ValueOf; + export type Actions = ValueOf; + export type AnnotationFlags = ValueOf; + export type DefaultToolbars = ValueOf; + export type ToolbarIcons = ValueOf; + export type ThumbnailFilterMode = ValueOf; + export type Conversion = ValueOf; + export type ViewModePickerItem = ValueOf; + export type ZoomLimitMode = ValueOf; + export type OverprintMode = ValueOf; + export type ColorPostProcessMode = ValueOf; + export type ReflowOrientation = ValueOf; + export type ExportFormat = ValueOf; + export type CustomToolbarKey = { + id : string; + name: string; + icon: ToolbarIcons; + items: (Tools | Buttons)[]; + } +} \ No newline at end of file diff --git a/src/Config/package.json b/src/Config/package.json deleted file mode 100644 index 7d1405838..000000000 --- a/src/Config/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "Config", - "version": "0.0.0", - "private": true, - "main": "./Config" -} \ No newline at end of file diff --git a/src/DocumentView/DocumentView.js b/src/DocumentView/DocumentView.tsx similarity index 58% rename from src/DocumentView/DocumentView.js rename to src/DocumentView/DocumentView.tsx index 950b834c7..e02299afa 100644 --- a/src/DocumentView/DocumentView.js +++ b/src/DocumentView/DocumentView.tsx @@ -1,122 +1,198 @@ import React, { PureComponent } from 'react'; -import PropTypes from 'prop-types'; +import PropTypes, { Requireable, Validator } from 'prop-types'; import { requireNativeComponent, ViewPropTypes, Platform, Alert, NativeModules, - findNodeHandle + findNodeHandle, } from 'react-native'; const { DocumentViewManager } = NativeModules; +import {Config} from "../Config/Config"; +import * as AnnotOptions from "../AnnotOptions/AnnotOptions"; + +/** + * Object containing PropTypes types for {@link DocumentView} class. + * Also used to generate prop types for TS users. + * + * To represent functions, please use {@link func}. + * To represent "one of Config.Buttons values" or "an array of + * Config.Buttons values", please use {@link oneOf} or {@link arrayOf}. + */ +const propTypes = { + document: PropTypes.string.isRequired, + password: PropTypes.string, + initialPageNumber: PropTypes.number, + pageNumber: PropTypes.number, + customHeaders: PropTypes.object, + leadingNavButtonIcon: PropTypes.string, + showLeadingNavButton: PropTypes.bool, + onLeadingNavButtonPressed: func<() => void>(), + onDocumentLoaded: func<(path: string) => void>(), + onDocumentError: func<(error: string) => void>(), + onPageChanged: func<(event: {previousPageNumber: number, pageNumber: number}) => void>(), + onScrollChanged: func<(event: {horizontal: number, vertical: number}) => void>(), + onZoomChanged: func<(event: {zoom: number}) => void>(), + onZoomFinished: func<(event: {zoom: number}) => void>(), + zoom: PropTypes.number, + disabledElements: arrayOf(Config.Buttons), + disabledTools: arrayOf(Config.Tools), + longPressMenuItems: arrayOf(Config.LongPressMenu), + overrideLongPressMenuBehavior: arrayOf(Config.LongPressMenu), + onLongPressMenuPress: func<(event: {longPressMenu: string, longPressText: string}) => void>(), + longPressMenuEnabled: PropTypes.bool, + annotationMenuItems: arrayOf(Config.AnnotationMenu), + overrideAnnotationMenuBehavior: arrayOf(Config.AnnotationMenu), + onAnnotationMenuPress: func<(event: {annotationMenu: string, annotations: Array}) => void>(), + hideAnnotationMenu: arrayOf(Config.Tools), + overrideBehavior: arrayOf(Config.Actions), + onBehaviorActivated: func<(event: {action: Config.Actions, data: AnnotOptions.LinkPressData | AnnotOptions.StickyNoteData}) => void>(), + topToolbarEnabled: PropTypes.bool, + bottomToolbarEnabled: PropTypes.bool, + hideToolbarsOnTap: PropTypes.bool, + documentSliderEnabled: PropTypes.bool, + pageIndicatorEnabled: PropTypes.bool, + keyboardShortcutsEnabled: PropTypes.bool, + onAnnotationsSelected: func<(event: {annotations: Array}) => void>(), + onAnnotationChanged: func<(event: {action: string, annotations: Array}) => void>(), + onFormFieldValueChanged: func<(event: {fields: Array}) => void>(), + readOnly: PropTypes.bool, + thumbnailViewEditingEnabled: PropTypes.bool, + fitMode: oneOf(Config.FitMode), + layoutMode: oneOf(Config.LayoutMode), + onLayoutChanged: func<() => void>(), + padStatusBar: PropTypes.bool, + continuousAnnotationEditing: PropTypes.bool, + selectAnnotationAfterCreation: PropTypes.bool, + annotationAuthor: PropTypes.string, + showSavedSignatures: PropTypes.bool, + isBase64String: PropTypes.bool, + collabEnabled: PropTypes.bool, + currentUser: PropTypes.string, + currentUserName: PropTypes.string, + onExportAnnotationCommand: func<(event: {action: string, xfdfCommand: string, annotations: Array}) => void>(), + autoSaveEnabled: PropTypes.bool, + pageChangeOnTap: PropTypes.bool, + followSystemDarkMode: PropTypes.bool, + useStylusAsPen: PropTypes.bool, + multiTabEnabled: PropTypes.bool, + tabTitle: PropTypes.string, + maxTabCount: PropTypes.number, + signSignatureFieldsWithStamps: PropTypes.bool, + annotationPermissionCheckEnabled: PropTypes.bool, + annotationToolbars: PropTypes.arrayOf(PropTypes.oneOfType([ + oneOf(Config.DefaultToolbars), + PropTypes.exact({ + id: PropTypes.string.isRequired, + name: PropTypes.string.isRequired, + icon: oneOf(Config.ToolbarIcons).isRequired, + items: arrayOf(Config.Tools, Config.Buttons).isRequired + }) + ])), + hideDefaultAnnotationToolbars: arrayOf(Config.DefaultToolbars), + topAppNavBarRightBar: arrayOf(Config.Buttons), + bottomToolbar: arrayOf(Config.Buttons), + hideAnnotationToolbarSwitcher: PropTypes.bool, + hideTopToolbars: PropTypes.bool, + hideTopAppNavBar: PropTypes.bool, + onBookmarkChanged: func<(event: {bookmarkJson: string}) => void>(), + hideThumbnailFilterModes: arrayOf(Config.ThumbnailFilterMode), + onToolChanged: func<(event: {previousTool: Config.Tools | "unknown tool", tool: Config.Tools | "unknown tool"}) => void>(), + horizontalScrollPos: PropTypes.number, + verticalScrollPos: PropTypes.number, + onTextSearchStart: func<() => void>(), + onTextSearchResult: func<(event: {found: boolean, textSelection: AnnotOptions.TextSelectionResult | null}) => void>(), + hideViewModeItems: arrayOf(Config.ViewModePickerItem), + pageStackEnabled: PropTypes.bool, + showQuickNavigationButton: PropTypes.bool, + photoPickerEnabled: PropTypes.bool, + autoResizeFreeTextEnabled: PropTypes.bool, + annotationsListEditingEnabled: PropTypes.bool, + showNavigationListAsSidePanelOnLargeDevices: PropTypes.bool, + restrictDownloadUsage: PropTypes.bool, + userBookmarksListEditingEnabled: PropTypes.bool, + imageInReflowEnabled: PropTypes.bool, + reflowOrientation: oneOf(Config.ReflowOrientation), + onUndoRedoStateChanged: func<() => void>(), + tabletLayoutEnabled: PropTypes.bool, + initialToolbar: PropTypes.string, + inkMultiStrokeEnabled: PropTypes.bool, + defaultEraserType: oneOf(Config.EraserType), + exportPath: PropTypes.string, + openUrlPath: PropTypes.string, + disableEditingByAnnotationType: arrayOf(Config.Tools), + hideScrollbars: PropTypes.bool, + saveStateEnabled: PropTypes.bool, + openSavedCopyInNewTab: PropTypes.bool, + excludedAnnotationListTypes: arrayOf(Config.Tools), + replyReviewStateEnabled: PropTypes.bool, + onPageMoved: func<(event: {previousPageNumber: number, pageNumber: number}) => void>(), + onTabChanged: func<(event: {currentTab: string}) => void>(), + ...ViewPropTypes, +}; + +// Generates the prop types for TypeScript users, from PropTypes. +type DocumentViewProps = PropTypes.InferProps; + +/** +* Creates a custom PropType for functions. +* +* If the resulting PropType is used to generate prop types for TS users, +* type checking for function parameters and return values will be provided. +* @returns {Requireable} A custom PropType constant. +* @example +* func<(path: string) => void>() +*/ +function func () : Requireable { + + let validator : Validator = function (props: { [key: string]: any }, propName: string, componentName: string, location: string, propFullName: string) : Error | null { + if (typeof props[propName] !== "function" && typeof props[propName] !== "undefined") { + return new Error (`Invalid prop \`${propName}\` of type \`${typeof props[propName]}\` supplied to \`${componentName}\`, expected a function.`); + } + return null; + } + + const t : Requireable = validator as Requireable; + t.isRequired = validator as Validator>; + return t; +} -export default class DocumentView extends PureComponent { - - static propTypes = { - document: PropTypes.string, - password: PropTypes.string, - initialPageNumber: PropTypes.number, - pageNumber: PropTypes.number, - customHeaders: PropTypes.object, - leadingNavButtonIcon: PropTypes.string, - showLeadingNavButton: PropTypes.bool, - onLeadingNavButtonPressed: PropTypes.func, - onDocumentLoaded: PropTypes.func, - onDocumentError: PropTypes.func, - onPageChanged: PropTypes.func, - onScrollChanged: PropTypes.func, - onZoomChanged: PropTypes.func, - onZoomFinished: PropTypes.func, - zoom: PropTypes.number, - disabledElements: PropTypes.array, - disabledTools: PropTypes.array, - longPressMenuItems: PropTypes.array, - overrideLongPressMenuBehavior: PropTypes.array, - onLongPressMenuPress: PropTypes.func, - longPressMenuEnabled: PropTypes.bool, - annotationMenuItems: PropTypes.array, - overrideAnnotationMenuBehavior: PropTypes.array, - onAnnotationMenuPress: PropTypes.func, - hideAnnotationMenu: PropTypes.array, - overrideBehavior: PropTypes.array, - onBehaviorActivated: PropTypes.func, - topToolbarEnabled: PropTypes.bool, - bottomToolbarEnabled: PropTypes.bool, - hideToolbarsOnTap: PropTypes.bool, - documentSliderEnabled: PropTypes.bool, - pageIndicatorEnabled: PropTypes.bool, - keyboardShortcutsEnabled: PropTypes.bool, - onAnnotationsSelected: PropTypes.func, - onAnnotationChanged: PropTypes.func, - onFormFieldValueChanged: PropTypes.func, - readOnly: PropTypes.bool, - thumbnailViewEditingEnabled: PropTypes.bool, - fitMode: PropTypes.string, - layoutMode: PropTypes.string, - onLayoutChanged: PropTypes.func, - padStatusBar: PropTypes.bool, - continuousAnnotationEditing: PropTypes.bool, - selectAnnotationAfterCreation: PropTypes.bool, - annotationAuthor: PropTypes.string, - showSavedSignatures: PropTypes.bool, - isBase64String: PropTypes.bool, - collabEnabled: PropTypes.bool, - currentUser: PropTypes.string, - currentUserName: PropTypes.string, - onExportAnnotationCommand: PropTypes.func, - autoSaveEnabled: PropTypes.bool, - pageChangeOnTap: PropTypes.bool, - followSystemDarkMode: PropTypes.bool, - useStylusAsPen: PropTypes.bool, - multiTabEnabled: PropTypes.bool, - tabTitle: PropTypes.string, - maxTabCount: PropTypes.number, - onTabChanged: PropTypes.func, - signSignatureFieldsWithStamps: PropTypes.bool, - annotationPermissionCheckEnabled: PropTypes.bool, - annotationToolbars: PropTypes.array, - hideDefaultAnnotationToolbars: PropTypes.array, - topAppNavBarRightBar: PropTypes.array, - bottomToolbar: PropTypes.array, - hideAnnotationToolbarSwitcher: PropTypes.bool, - hideTopToolbars: PropTypes.bool, - hideTopAppNavBar: PropTypes.bool, - onBookmarkChanged: PropTypes.func, - hideThumbnailFilterModes: PropTypes.array, - onToolChanged: PropTypes.func, - horizontalScrollPos: PropTypes.number, - verticalScrollPos: PropTypes.number, - onTextSearchStart: PropTypes.func, - onTextSearchResult: PropTypes.func, - hideViewModeItems: PropTypes.array, - pageStackEnabled: PropTypes.bool, - showQuickNavigationButton: PropTypes.bool, - photoPickerEnabled: PropTypes.bool, - autoResizeFreeTextEnabled: PropTypes.bool, - annotationsListEditingEnabled: PropTypes.bool, - showNavigationListAsSidePanelOnLargeDevices: PropTypes.bool, - restrictDownloadUsage: PropTypes.bool, - userBookmarksListEditingEnabled: PropTypes.bool, - imageInReflowEnabled: PropTypes.bool, - reflowOrientation: PropTypes.string, - onUndoRedoStateChanged: PropTypes.func, - tabletLayoutEnabled: PropTypes.bool, - initialToolbar: PropTypes.string, - inkMultiStrokeEnabled: PropTypes.bool, - defaultEraserType: PropTypes.string, - exportPath: PropTypes.string, - openUrlPath: PropTypes.string, - onPageMoved: PropTypes.func, - disableEditingByAnnotationType: PropTypes.array, - hideScrollbars: PropTypes.bool, - saveStateEnabled: PropTypes.bool, - openSavedCopyInNewTab: PropTypes.bool, - excludedAnnotationListTypes: PropTypes.array, - replyReviewStateEnabled: PropTypes.bool, - ...ViewPropTypes, - }; +/** + * Creates a custom PropType representing any value from given object(s). + * @param {object} obj An object containing values. + * @param {...object} rest Indefinite number of other objects containing values. + * @returns {Requireable} A custom PropType constant. + * @example + * oneOf(Config.Tools) + * oneOf(Config.Tools, Config.Buttons) +*/ +function oneOf(obj: object, ...rest: object[]) : Requireable { + if (rest.length > 0) { + return PropTypes.oneOf(Object.values(Object.assign({}, obj, ...rest))); + } + return PropTypes.oneOf(Object.values(obj)); +} + +/** + * Creates a custom PropType representing any array containing values from given object(s). + * @param {object} obj An object containing values. + * @param {...object} rest Indefinite number of other objects containing values. + * @returns {Requireable} A custom PropType constant. + * @example + * arrayOf(Config.Tools) + * arrayOf(Config.Tools, Config.Buttons) +*/ +function arrayOf(obj: object, ...rest: object[]) : Requireable { + return PropTypes.arrayOf(oneOf(obj, ...rest)) as Requireable; +} +export class DocumentView extends PureComponent { - onChange = (event) => { + _viewerRef: any; + + static propTypes = propTypes; + + onChange = (event: any) => { if (event.nativeEvent.onLeadingNavButtonPressed) { if (this.props.onLeadingNavButtonPressed) { this.props.onLeadingNavButtonPressed(); @@ -261,7 +337,9 @@ export default class DocumentView extends PureComponent { } } - getDocumentPath = () => { + // Methods + + getDocumentPath = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getDocumentPath(tag); @@ -269,7 +347,8 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setToolMode = (toolMode) => { + + setToolMode = (toolMode: Config.Tools): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setToolMode(tag, toolMode); @@ -277,7 +356,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - commitTool = () => { + commitTool = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.commitTool(tag); @@ -285,7 +364,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getPageCount = () => { + getPageCount = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getPageCount(tag); @@ -293,15 +372,15 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - importBookmarkJson = (bookmarkJson) => { + importBookmarkJson = (bookmarkJson: string): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.importBookmarkJson(tag, bookmarkJson); } return Promise.resolve(); } - - openBookmarkList = () => { + + openBookmarkList = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.openBookmarkList(tag); @@ -309,7 +388,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - importAnnotationCommand = (xfdfCommand, initialLoad) => { + importAnnotationCommand = (xfdfCommand: string, initialLoad?: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { if (initialLoad === undefined) { @@ -324,7 +403,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - importAnnotations = (xfdf) => { + importAnnotations = (xfdf: string): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.importAnnotations(tag, xfdf); @@ -332,7 +411,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - exportAnnotations = (options) => { + exportAnnotations = (options?: {annotList: Array}): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.exportAnnotations(tag, options); @@ -340,7 +419,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - flattenAnnotations = (formsOnly) => { + flattenAnnotations = (formsOnly: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.flattenAnnotations(tag, formsOnly); @@ -348,7 +427,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - deleteAnnotations = (annotations) => { + deleteAnnotations = (annotations: Array): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.deleteAnnotations(tag, annotations); @@ -356,7 +435,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - saveDocument = () => { + saveDocument = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.saveDocument(tag); @@ -364,7 +443,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setFlagForFields = (fields, flag, value) => { + setFlagForFields = (fields: Array, flag: Config.FieldFlags, value: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if(tag != null) { return DocumentViewManager.setFlagForFields(tag, fields, flag, value); @@ -372,7 +451,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getField = (fieldName) => { + getField = (fieldName: string): Promise => { const tag = findNodeHandle(this._viewerRef); if(tag != null) { return DocumentViewManager.getField(tag, fieldName); @@ -380,7 +459,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - openAnnotationList = () => { + openAnnotationList = (): Promise => { const tag = findNodeHandle(this._viewerRef); if(tag != null) { return DocumentViewManager.openAnnotationList(tag); @@ -392,11 +471,11 @@ export default class DocumentView extends PureComponent { * note: this function exists for supporting the old version. It simply calls setValuesForFields. * */ - setValueForFields = (fieldsMap) => { + setValueForFields = (fieldsMap: Record): Promise => { return this.setValuesForFields(fieldsMap); } - setValuesForFields = (fieldsMap) => { + setValuesForFields = (fieldsMap: Record): Promise => { const tag = findNodeHandle(this._viewerRef); if(tag != null) { return DocumentViewManager.setValuesForFields(tag, fieldsMap); @@ -404,7 +483,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - handleBackButton = () => { + handleBackButton = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.handleBackButton(tag); @@ -417,11 +496,11 @@ export default class DocumentView extends PureComponent { * note: this function exists for supporting the old version. It simply calls setFlagsForAnnotations. * */ - setFlagForAnnotations = (annotationFlagList) => { + setFlagForAnnotations = (annotationFlagList: Array): Promise => { return this.setFlagsForAnnotations(annotationFlagList); } - setFlagsForAnnotations = (annotationFlagList) => { + setFlagsForAnnotations = (annotationFlagList: Array): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setFlagsForAnnotations(tag, annotationFlagList); @@ -429,7 +508,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - selectAnnotation = (id, pageNumber) => { + selectAnnotation = (id: string, pageNumber: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.selectAnnotation(tag, id, pageNumber); @@ -441,11 +520,11 @@ export default class DocumentView extends PureComponent { * note: this function exists for supporting the old version. It simply calls setPropertiesForAnnotation. * */ - setPropertyForAnnotation = (id, pageNumber, propertyMap) => { - return setPropertiesForAnnotation(id, pageNumber, propertyMap); + setPropertyForAnnotation = (id: string, pageNumber: number, propertyMap: AnnotOptions.AnnotationProperties): Promise => { + return this._viewerRef.setPropertiesForAnnotation(id, pageNumber, propertyMap); } - setPropertiesForAnnotation = (id, pageNumber, propertyMap) => { + setPropertiesForAnnotation = (id: string, pageNumber: number, propertyMap: AnnotOptions.AnnotationProperties): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setPropertiesForAnnotation(tag, id, pageNumber, propertyMap); @@ -453,7 +532,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getPropertiesForAnnotation = (id, pageNumber) => { + getPropertiesForAnnotation = (id: string, pageNumber: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getPropertiesForAnnotation(tag, id, pageNumber); @@ -461,7 +540,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setDrawAnnotations = (drawAnnotations) => { + setDrawAnnotations = (drawAnnotations: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setDrawAnnotations(tag, drawAnnotations); @@ -469,7 +548,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setVisibilityForAnnotation = (id, pageNumber, visibility) => { + setVisibilityForAnnotation = (id: string, pageNumber: number, visibility: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { DocumentViewManager.setVisibilityForAnnotation(tag, id, pageNumber, visibility); @@ -477,7 +556,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setHighlightFields = (highlightFields) => { + setHighlightFields = (highlightFields: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { DocumentViewManager.setHighlightFields(tag, highlightFields); @@ -485,7 +564,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getAnnotationAtPoint = (x, y, distanceThreshold, minimumLineWeight) => { + getAnnotationAtPoint = (x: number, y: number, distanceThreshold: number, minimumLineWeight: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getAnnotationAt(tag, x, y, distanceThreshold, minimumLineWeight); @@ -493,7 +572,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getAnnotationListAt = (x1, y1, x2, y2) => { + getAnnotationListAt = (x1: number, y1: number, x2: number, y2: number): Promise> => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getAnnotationListAt(tag, x1, y1, x2, y2); @@ -501,7 +580,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getAnnotationsOnPage = (pageNumber) => { + getAnnotationsOnPage = (pageNumber: number): Promise> => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getAnnotationListOnPage(tag, pageNumber); @@ -509,7 +588,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getCustomDataForAnnotation = (annotationID, pageNumber, key) => { + getCustomDataForAnnotation = (annotationID: string, pageNumber: number, key: string): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getCustomDataForAnnotation(tag, annotationID, pageNumber, key); @@ -517,7 +596,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getPageCropBox = (pageNumber) => { + getPageCropBox = (pageNumber: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getPageCropBox(tag, pageNumber); @@ -525,7 +604,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setCurrentPage = (pageNumber) => { + setCurrentPage = (pageNumber: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setCurrentPage(tag, pageNumber); @@ -533,7 +612,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getVisiblePages = () => { + getVisiblePages = (): Promise> => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getVisiblePages(tag); @@ -541,7 +620,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - gotoPreviousPage = () => { + gotoPreviousPage = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.gotoPreviousPage(tag); @@ -549,7 +628,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - gotoNextPage = () => { + gotoNextPage = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.gotoNextPage(tag); @@ -557,7 +636,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - gotoFirstPage = () => { + gotoFirstPage = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.gotoFirstPage(tag); @@ -565,7 +644,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - gotoLastPage = () => { + gotoLastPage = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.gotoLastPage(tag); @@ -573,7 +652,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - showGoToPageView = () => { + showGoToPageView = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.showGoToPageView(tag); @@ -581,7 +660,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - closeAllTabs = () => { + closeAllTabs = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.closeAllTabs(tag); @@ -589,7 +668,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - openTabSwitcher = () => { + openTabSwitcher = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.openTabSwitcher(tag); @@ -597,7 +676,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getZoom = () => { + getZoom = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getZoom(tag); @@ -605,7 +684,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setZoomLimits = (zoomLimitMode, minimum, maximum) => { + setZoomLimits = (zoomLimitMode: Config.ZoomLimitMode, minimum: number, maximum: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setZoomLimits(tag, zoomLimitMode, minimum, maximum); @@ -613,7 +692,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - zoomWithCenter = (zoom, x, y) => { + zoomWithCenter = (zoom: number, x: number, y: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.zoomWithCenter(tag, zoom, x, y); @@ -621,7 +700,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - zoomToRect = (pageNumber, rect) => { + zoomToRect = (pageNumber: number, rect: AnnotOptions.Rect): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.zoomToRect(tag, pageNumber, rect); @@ -629,7 +708,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - smartZoom = (x, y, animated) => { + smartZoom = (x: number, y: number, animated: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.smartZoom(tag, x, y, animated); @@ -637,7 +716,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getScrollPos = () => { + getScrollPos = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getScrollPos(tag); @@ -645,7 +724,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getCanvasSize = () => { + getCanvasSize = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getCanvasSize(tag); @@ -653,7 +732,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getPageRotation = () => { + getPageRotation = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getPageRotation(tag); @@ -661,7 +740,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - rotateClockwise = () => { + rotateClockwise = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.rotateClockwise(tag); @@ -669,7 +748,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - rotateCounterClockwise = () => { + rotateCounterClockwise = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.rotateCounterClockwise(tag); @@ -678,7 +757,7 @@ export default class DocumentView extends PureComponent { } - convertScreenPointsToPagePoints = (points) => { + convertScreenPointsToPagePoints = (points: Array): Promise> => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.convertScreenPointsToPagePoints(tag, points); @@ -686,7 +765,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - convertPagePointsToScreenPoints = (points) => { + convertPagePointsToScreenPoints = (points: Array): Promise> => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.convertPagePointsToScreenPoints(tag, points); @@ -694,7 +773,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getPageNumberFromScreenPoint = (x, y) => { + getPageNumberFromScreenPoint = (x: number, y: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getPageNumberFromScreenPoint(tag, x, y); @@ -702,7 +781,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setProgressiveRendering = (progressiveRendering, initialDelay, interval) => { + setProgressiveRendering = (progressiveRendering: boolean, initialDelay: number, interval: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setProgressiveRendering(tag, progressiveRendering, initialDelay, interval); @@ -710,7 +789,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setImageSmoothing = (imageSmoothing) => { + setImageSmoothing = (imageSmoothing: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setImageSmoothing(tag, imageSmoothing); @@ -718,7 +797,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setOverprint = (overprint) => { + setOverprint = (overprint: Config.OverprintMode): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setOverprint(tag, overprint); @@ -726,7 +805,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setColorPostProcessMode = (colorPostProcessMode) => { + setColorPostProcessMode = (colorPostProcessMode: Config.ColorPostProcessMode): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { DocumentViewManager.setColorPostProcessMode(tag, colorPostProcessMode); @@ -734,7 +813,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setColorPostProcessColors = (whiteColor, blackColor) => { + setColorPostProcessColors = (whiteColor: AnnotOptions.Color, blackColor: AnnotOptions.Color): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setColorPostProcessColors(tag, whiteColor, blackColor); @@ -742,7 +821,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - startSearchMode = (searchString, matchCase, matchWholeWord) => { + startSearchMode = (searchString: string, matchCase: boolean, matchWholeWord: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.startSearchMode(tag, searchString, matchCase, matchWholeWord); @@ -750,7 +829,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - exitSearchMode = () => { + exitSearchMode = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.exitSearchMode(tag); @@ -758,7 +837,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - findText = (searchString, matchCase, matchWholeWord, searchUp, regExp) => { + findText = (searchString: string, matchCase: boolean, matchWholeWord: boolean, searchUp: boolean, regExp: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.findText(tag, searchString, matchCase, matchWholeWord, searchUp, regExp); @@ -766,7 +845,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - cancelFindText = () => { + cancelFindText = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.cancelFindText(tag); @@ -774,15 +853,15 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - openSearch = () => { + openSearch = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.openSearch(tag); } return Promise.resolve(); } - - getSelection = (pageNumber) => { + + getSelection = (pageNumber: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getSelection(tag, pageNumber); @@ -790,7 +869,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - hasSelection = () => { + hasSelection = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.hasSelection(tag); @@ -798,7 +877,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - clearSelection = () => { + clearSelection = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.clearSelection(tag); @@ -806,7 +885,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getSelectionPageRange = () => { + getSelectionPageRange = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getSelectionPageRange(tag); @@ -814,7 +893,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - hasSelectionOnPage = (pageNumber) => { + hasSelectionOnPage = (pageNumber: number): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.hasSelectionOnPage(tag, pageNumber); @@ -823,7 +902,7 @@ export default class DocumentView extends PureComponent { } - selectInRect = (rect) => { + selectInRect = (rect: AnnotOptions.Rect): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.selectInRect(tag, rect); @@ -831,7 +910,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - isThereTextInRect = (rect) => { + isThereTextInRect = (rect: AnnotOptions.Rect): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.isThereTextInRect(tag, rect); @@ -839,7 +918,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - selectAll = () => { + selectAll = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.selectAll(tag); @@ -847,7 +926,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setPageBorderVisibility = (pageBorderVisibility) => { + setPageBorderVisibility = (pageBorderVisibility: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setPageBorderVisibility(tag, pageBorderVisibility); @@ -855,7 +934,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setPageTransparencyGrid = (pageTransparencyGrid) => { + setPageTransparencyGrid = (pageTransparencyGrid: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setPageTransparencyGrid(tag, pageTransparencyGrid); @@ -863,7 +942,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setDefaultPageColor = (defaultPageColor) => { + setDefaultPageColor = (defaultPageColor: AnnotOptions.Color): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setDefaultPageColor(tag, defaultPageColor); @@ -871,7 +950,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setBackgroundColor = (backgroundColor) => { + setBackgroundColor = (backgroundColor: AnnotOptions.Color): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setBackgroundColor(tag, backgroundColor); @@ -879,7 +958,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - exportAsImage = (pageNumber, dpi, exportFormat) => { + exportAsImage = (pageNumber: number, dpi: number, exportFormat: Config.ExportFormat): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.exportAsImage(tag, pageNumber, dpi, exportFormat); @@ -887,7 +966,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - undo = () => { + undo = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.undo(tag); @@ -895,7 +974,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - redo = () => { + redo = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.redo(tag); @@ -903,7 +982,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - canUndo = () => { + canUndo = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.canUndo(tag); @@ -911,7 +990,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - canRedo = () => { + canRedo = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.canRedo(tag); @@ -919,7 +998,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - showCrop = () => { + showCrop = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.showCrop(tag); @@ -927,7 +1006,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - setCurrentToolbar = (toolbar) => { + setCurrentToolbar = (toolbar: string): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.setCurrentToolbar(tag, toolbar); @@ -935,7 +1014,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - showViewSettings = (rect) => { + showViewSettings = (rect: AnnotOptions.Rect): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.showViewSettings(tag, rect); @@ -943,15 +1022,15 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - showRotateDialog = () => { + showRotateDialog = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.showRotateDialog(tag); } return Promise.resolve(); } - - showAddPagesView = (rect) => { + + showAddPagesView = (rect: AnnotOptions.Rect): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.showAddPagesView(tag, rect); @@ -959,7 +1038,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - isReflowMode = () => { + isReflowMode = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.isReflowMode(tag); @@ -967,7 +1046,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - toggleReflow = () => { + toggleReflow = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.toggleReflow(tag); @@ -975,7 +1054,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - shareCopy = (rect, flattening) => { + shareCopy = (rect: AnnotOptions.Rect, flattening: boolean): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.shareCopy(tag, rect, flattening); @@ -983,7 +1062,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - openThumbnailsView = () => { + openThumbnailsView = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.openThumbnailsView(tag); @@ -991,7 +1070,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - openOutlineList = () => { + openOutlineList = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.openOutlineList(tag); @@ -999,7 +1078,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - openLayersList = () => { + openLayersList = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.openLayersList(tag); @@ -1007,7 +1086,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - openNavigationLists = () => { + openNavigationLists = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.openNavigationLists(tag); @@ -1015,7 +1094,7 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getSavedSignatures = () => { + getSavedSignatures = (): Promise> => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getSavedSignatures(tag); @@ -1023,15 +1102,15 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - getSavedSignatureFolder = () => { + getSavedSignatureFolder = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getSavedSignatureFolder(tag); } return Promise.resolve(); } - - getSavedSignatureJpgFolder = () => { + + getSavedSignatureJpgFolder = (): Promise => { const tag = findNodeHandle(this._viewerRef); if (tag != null) { return DocumentViewManager.getSavedSignatureJpgFolder(tag); @@ -1039,15 +1118,17 @@ export default class DocumentView extends PureComponent { return Promise.resolve(); } - _setNativeRef = (ref) => { + _setNativeRef = (ref: any) => { this._viewerRef = ref; }; render() { return ( + // @ts-ignore @@ -1057,12 +1138,4 @@ export default class DocumentView extends PureComponent { const name = Platform.OS === 'ios' ? 'RNTPTDocumentView' : 'RCTDocumentView'; -const RCTDocumentView = requireNativeComponent( - name, - DocumentView, - { - nativeOnly: { - onChange: true - } - } -); +const RCTDocumentView = requireNativeComponent(name); diff --git a/src/DocumentView/package.json b/src/DocumentView/package.json deleted file mode 100644 index cdded820d..000000000 --- a/src/DocumentView/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "DocumentView", - "version": "0.0.0", - "private": true, - "main": "./DocumentView" -} \ No newline at end of file diff --git a/src/PDFViewCtrl/PDFViewCtrl.js b/src/PDFViewCtrl/PDFViewCtrl.js deleted file mode 100644 index 1c899cf1f..000000000 --- a/src/PDFViewCtrl/PDFViewCtrl.js +++ /dev/null @@ -1,41 +0,0 @@ -import React, { PureComponent } from 'react'; -import PropTypes from 'prop-types'; -import { - requireNativeComponent, - ViewPropTypes, - Text, - View, - Dimensions, - Platform -} from 'react-native'; - -const { height, width } = Dimensions.get('window'); - -export default class PDFViewCtrl extends PureComponent { - - static propTypes = { - document: PropTypes.string, - ...ViewPropTypes, - }; - - render() { - return ( - - ) - } -} - -var iface = { - name: 'PDFViewCtrl', - propTypes: { - document: PropTypes.string, - ...ViewPropTypes, // include the default view properties - }, -}; - -const name = Platform.OS === 'ios' ? 'RNTPTPDFViewCtrl' : 'RCTPDFViewCtrl'; - -const RCTPDFViewCtrl = requireNativeComponent(name, PDFViewCtrl, iface); \ No newline at end of file diff --git a/src/PDFViewCtrl/PDFViewCtrl.tsx b/src/PDFViewCtrl/PDFViewCtrl.tsx new file mode 100644 index 000000000..fc3eff7b4 --- /dev/null +++ b/src/PDFViewCtrl/PDFViewCtrl.tsx @@ -0,0 +1,33 @@ +import React, { PureComponent } from 'react'; +import PropTypes, { InferProps } from 'prop-types'; +import { + requireNativeComponent, + ViewPropTypes, + Platform +} from 'react-native'; + +const propTypes = { + document: PropTypes.string.isRequired, + ...ViewPropTypes, +} + +// Generates the prop types for TypeScript users, from PropTypes. +type PDFViewCtrlProps = InferProps; + +export class PDFViewCtrl extends PureComponent { + + static propTypes = propTypes; + + render() { + return ( + + ) + } +} + +const name = Platform.OS === 'ios' ? 'RNTPTPDFViewCtrl' : 'RCTPDFViewCtrl'; + +const RCTPDFViewCtrl = requireNativeComponent(name); \ No newline at end of file diff --git a/src/PDFViewCtrl/package.json b/src/PDFViewCtrl/package.json deleted file mode 100644 index 6294c1e73..000000000 --- a/src/PDFViewCtrl/package.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "name": "PDFViewCtrl", - "version": "0.0.0", - "private": true, - "main": "./PDFViewCtrl" -} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 000000000..ee731576f --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "moduleResolution": "Node", + "target": "ESNext", + "jsx": "react-native", + "allowSyntheticDefaultImports": true, + "esModuleInterop": true, + "skipLibCheck": true, + "declaration": false, + "outDir": "./lib", + "strict": true, + "noEmitOnError": true, + }, + "include": ["index.ts", "src/**/*"], + "exclude": ["node_modules", "**/*.spec.ts"] +} \ No newline at end of file