Skip to content

Commit

Permalink
Better TypeScript support
Browse files Browse the repository at this point in the history
  • Loading branch information
rumax committed Oct 26, 2020
1 parent ba5e6aa commit c379d5b
Show file tree
Hide file tree
Showing 10 changed files with 38 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"no-underscore-dangle": 0,
"react/require-default-props": 0,
"lines-between-class-members": 0,
"react/destructuring-assignment": 0
"react/destructuring-assignment": 0,
"prettier/prettier": 0
}
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# NPM
react-native-view-pdf-*.tgz
react-native-view-pdf.tgz
package/

package-lock.json
yarn.lock

# jest
coverage
Expand Down
3 changes: 3 additions & 0 deletions demo/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
module.exports = {
root: true,
extends: '@react-native-community',
rules: {
'prettier/prettier': 0,
},
};
3 changes: 2 additions & 1 deletion demo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"android": "react-native run-android",
"ios": "react-native run-ios",
"start": "react-native start",
"preinstall": "rm -rf node_modules package-lock.json && cd .. && rm -rf react-native-view-pdf-*.tgz && npm i && npm pack && mv react-native-view-pdf-*.tgz react-native-view-pdf.tgz",
"test": "jest",
"lint": "eslint ."
},
Expand All @@ -14,7 +15,7 @@
"react-native": "0.63.3",
"react-native-dropdownalert": "^4.3.0",
"react-native-loading-spinner-overlay": "^1.1.0",
"react-native-view-pdf": "^0.11.0"
"react-native-view-pdf": "../react-native-view-pdf.tgz"
},
"devDependencies": {
"@babel/core": "^7.8.4",
Expand Down
5 changes: 2 additions & 3 deletions demo/src/App.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* @flow */
/* eslint-disable react/prop-types, no-console */
import React, { Fragment } from 'react';
import {
Alert,
Expand Down Expand Up @@ -28,14 +27,14 @@ type StateType = {

const HorisontalLine = () => (<View style={styles.horizontalLine} />);

type PdfContentType = {
type PdfContentType = {|
resource?: Resource,
onRef?: Function,
onLoad?: Function,
onError?: Function,
onPageChanged?: Function,
onScrolled?: Function,
};
|};

const PdfContent = (props: PdfContentType) => {
if (props.resource) {
Expand Down
3 changes: 2 additions & 1 deletion demo/src/Button.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
TouchableOpacity,
View,
} from 'react-native';
import type { ViewStyleProp } from 'StyleSheet';

import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet';

import styles from './styles';

Expand Down
4 changes: 2 additions & 2 deletions demo/src/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import type { UrlPropsType } from 'react-native-view-pdf';

import base64Data from './base64.json';

export type Resource = {
export type Resource = {|
resource: string,
resourceType: 'url' | 'base64' | 'file',
urlProps?: UrlPropsType,
};
|};

const resources: {[key: string]: Resource } = {
fileAssets: {
Expand Down
21 changes: 10 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "react-native-view-pdf",
"version": "0.11.0",
"description": "React native Pdf viewer implementation",
"main": "src/index.js",
"main": "lib/index.js",
"scripts": {
"prepublish": "./utils/deploy.sh",
"test": "jest",
Expand All @@ -22,34 +22,33 @@
"prop-types": ">=15.7.2"
},
"devDependencies": {
"react": "16.8.6",
"react-native": "0.60.5",
"@babel/core": "^7.5.5",
"@babel/preset-flow": "^7.0.0",
"@babel/runtime": "^7.5.5",
"@react-native-community/eslint-config": "^0.0.5",
"babel-eslint": "^10.0.1",
"babel-jest": "^24.9.0",
"eslint": "^6.2.0",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react-test-renderer": "16.8.6",
"codecov": "^3.0.0",
"eslint": "^6.2.0",
"eslint-config-airbnb": "^17.1.0",
"eslint-plugin-flowtype": "^3.2.1",
"eslint-plugin-import": "^2.14.0",
"eslint-plugin-jsx-a11y": "^6.1.2",
"eslint-plugin-react": "^7.11.1",
"flow-bin": "0.98.0",
"flow-copy-source": "^2.0.9",
"flow-remove-types": "^1.2.3",
"flow-typed": "^2.5.1"
"flow-typed": "^2.5.1",
"jest": "^24.9.0",
"metro-react-native-babel-preset": "^0.56.0",
"react": "16.8.6",
"react-native": "0.60.5",
"react-test-renderer": "16.8.6"
},
"files": [
"index.d.ts",
"src/index.js",
"src/RNPDFView.js",
"lib/index.js",
"lib/RNPDFView.js",
"lib",
"android/build.gradle",
"android/src/main/AndroidManifest.xml",
"android/src/main/java/com/rumax/reactnative/pdfviewer/*.java",
Expand Down
10 changes: 7 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
NativeModules,
} from 'react-native';

import type { ViewProps } from 'react-native/Libraries/Components/View/ViewPropTypes';

import RNPDFView from './RNPDFView';

export type UrlPropsType = {
Expand All @@ -29,7 +31,9 @@ export type UrlPropsType = {
body?: string,
};

type PropsType = {
type PropsType = {|
...ViewProps,

/**
* A Function. Invoked on load error with {nativeEvent: {error}}.
*/
Expand Down Expand Up @@ -102,7 +106,7 @@ type PropsType = {
* - false, default
*/
enableAnnotations?: boolean,
};
|};

class PDFView extends React.Component<PropsType, *> {
// eslint-disable-next-line react/sort-comp
Expand Down Expand Up @@ -147,7 +151,7 @@ class PDFView extends React.Component<PropsType, *> {
_getCommands = () => {
const _PDFView = UIManager.getViewManagerConfig
? UIManager.getViewManagerConfig('PDFView') // RN 0.58
: UIManager.PDFView; // RN 0.57
: (UIManager: any).PDFView; // RN 0.57
return _PDFView.Commands;
}

Expand Down
6 changes: 6 additions & 0 deletions utils/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ mkdir lib
# Remove flow types
./node_modules/.bin/flow-remove-types src/index.js --pretty --out-file lib/index.js
./node_modules/.bin/flow-remove-types src/RNPDFView.js --pretty --out-file lib/RNPDFView.js

# TypeScript
cp ./index.d.ts ./lib

# FlowType
./node_modules/.bin/flow-copy-source --ignore __tests__/* --verbose src lib

0 comments on commit c379d5b

Please sign in to comment.