diff --git a/PDFView.android.js b/PDFView.android.js index 54831b5..1e0d96d 100644 --- a/PDFView.android.js +++ b/PDFView.android.js @@ -1,5 +1,6 @@ 'use strict'; -import React,{ Component, PropTypes } from 'react'; +import React,{ Component } from 'react'; +import PropTypes from 'prop-types'; import { requireNativeComponent, View } from 'react-native'; class PDFView extends Component { diff --git a/PDFView.ios.js b/PDFView.ios.js index 12ec0f3..f8767f6 100644 --- a/PDFView.ios.js +++ b/PDFView.ios.js @@ -1,5 +1,6 @@ 'use strict'; -import React,{ Component, PropTypes } from 'react'; +import React,{ Component } from 'react'; +import PropTypes from 'prop-types'; import { requireNativeComponent, View } from 'react-native'; class PDFView extends Component { @@ -27,6 +28,8 @@ PDFView.propTypes = { path: PropTypes.string, pageNumber: PropTypes.number, zoom: PropTypes.number, + borderWidth: PropTypes.number, + backgroundColor: PropTypes.string, onLoadComplete: PropTypes.func }; diff --git a/README.md b/README.md index 53ee6d4..b8f31c0 100644 --- a/README.md +++ b/README.md @@ -136,5 +136,7 @@ var styles = StyleSheet.create({ | src | string | null | pdf absolute path(`Deprecated`) | ✔ | ✔ | | asset | string | null | the name of a PDF file in the asset folder | | ✔ | | pageNumber | number | 1 | page index | ✔ | ✔ | +| borderWidth | number | 5 | gray border width | ✔ | | +| backgroundColor | string | white | background color | ✔ | | | zoom | number | 1.0 | zoom scale | ✔ | ✔ | | onLoadComplete | function | null | page load complete,return page count | ✔ | ✔ | diff --git a/RNPDFView/PDFScrollView.m b/RNPDFView/PDFScrollView.m index ab95412..953dbf7 100644 --- a/RNPDFView/PDFScrollView.m +++ b/RNPDFView/PDFScrollView.m @@ -80,9 +80,8 @@ -(void)initialize { self.decelerationRate = UIScrollViewDecelerationRateFast; self.delegate = self; self.layer.borderColor = [UIColor lightGrayColor].CGColor; - self.layer.borderWidth = 5; - self.minimumZoomScale = .25; - self.maximumZoomScale = 5; + self.minimumZoomScale = 0.9; + self.maximumZoomScale = 2; } @@ -91,7 +90,7 @@ - (void)setPDFPage:(CGPDFPageRef)PDFPage; if( PDFPage != NULL ) CGPDFPageRetain(PDFPage); if( _PDFPage != NULL ) CGPDFPageRelease(_PDFPage); _PDFPage = PDFPage; - + // PDFPage is null if we're requested to draw a padded blank page by the parent UIPageViewController if( PDFPage == NULL ) { self.pageRect = self.bounds; @@ -117,35 +116,35 @@ - (void)dealloc // Use layoutSubviews to center the PDF page in the view. -- (void)layoutSubviews +- (void)layoutSubviews { [super layoutSubviews]; - + //NSLog(@"%s bounds: %@",__PRETTY_FUNCTION__,NSStringFromCGRect(self.bounds)); - + // Center the image as it becomes smaller than the size of the screen. - + CGSize boundsSize = self.bounds.size; - + CGRect frameToCenter = self.tiledPDFView.frame; - + // Center horizontally. - + if (frameToCenter.size.width < boundsSize.width) frameToCenter.origin.x = (boundsSize.width - frameToCenter.size.width) / 2; else frameToCenter.origin.x = 0; - + // Center vertically. - + if (frameToCenter.size.height < boundsSize.height) frameToCenter.origin.y = (boundsSize.height - frameToCenter.size.height) / 2; else frameToCenter.origin.y = 0; - + self.tiledPDFView.frame = frameToCenter; self.backgroundImageView.frame = frameToCenter; - + /* To handle the interaction between CATiledLayer and high resolution screens, set the tiling view's contentScaleFactor to 1.0. If this step were omitted, the content scale factor would be 2.0 on high resolution screens, which would cause the CATiledLayer to ask for tiles of the wrong scale. @@ -175,8 +174,8 @@ - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView * { NSLog(@"%s scrollView.zoomScale=%f",__PRETTY_FUNCTION__,self.zoomScale); // Remove back tiled view. - [self.oldTiledPDFView removeFromSuperview]; - + //[self.oldTiledPDFView removeFromSuperview]; + // Set the current TiledPDFView to be the old view. self.oldTiledPDFView = self.tiledPDFView; //[self addSubview:self.oldTiledPDFView]; @@ -188,14 +187,19 @@ - (void)scrollViewWillBeginZooming:(UIScrollView *)scrollView withView:(UIView * When the user stops zooming, create a new TiledPDFView based on the new zoom level and draw it on top of the old TiledPDFView. */ - (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(CGFloat)scale { - + NSLog(@"BEFORE %s scale=%f, _PDFScale=%f",__PRETTY_FUNCTION__,scale,_PDFScale); // Set the new scale factor for the TiledPDFView. - _PDFScale *= scale; + //_PDFScale *= scale; NSLog(@"AFTER %s scale=%f, _PDFScale=%f newFrame=%@",__PRETTY_FUNCTION__,scale,_PDFScale,NSStringFromCGRect(self.oldTiledPDFView.frame)); + if (self.zoomScale > 1) { + [self setZoomScale:1 animated:YES]; + } + self.tiledPDFView = self.oldTiledPDFView; + // Create a new tiled PDF View at the new scale - [self replaceTiledPDFViewWithFrame:self.oldTiledPDFView.frame]; + //[self replaceTiledPDFViewWithFrame:self.oldTiledPDFView.frame]; } -(void)replaceTiledPDFViewWithFrame:(CGRect)frame { diff --git a/RNPDFView/RNPDFView.h b/RNPDFView/RNPDFView.h index 86cdf88..b7d4d0f 100644 --- a/RNPDFView/RNPDFView.h +++ b/RNPDFView/RNPDFView.h @@ -17,7 +17,9 @@ @property(nonatomic, strong) NSString *path; @property(nonatomic, strong) NSNumber *pageNumber; @property(nonatomic, strong) NSNumber *zoom; +@property(nonatomic, strong) NSNumber *borderWidth; +@property(nonatomic, strong) UIColor *backgroundColor; @property(nonatomic, copy) RCTBubblingEventBlock onChange; -@end \ No newline at end of file +@end diff --git a/RNPDFView/RNPDFView.m b/RNPDFView/RNPDFView.m index 445f4e1..3590d74 100644 --- a/RNPDFView/RNPDFView.m +++ b/RNPDFView/RNPDFView.m @@ -111,6 +111,24 @@ - (void)setZoom:(NSNumber *)zoom } } +- (void)setBorderWidth:(NSNumber *)borderWidth +{ + if (![borderWidth isEqual:_borderWidth]) { + NSLog(@"setBorderWidth %@ -> %@", _borderWidth, borderWidth); + _borderWidth = [borderWidth copy]; + [self reloadPdf]; + } +} + +- (void)setBackgroundColor:(NSNumber *)backgroundColor +{ + if (![backgroundColor isEqual:_backgroundColor]) { + NSLog(@"setPageNumber %@ -> %@", _backgroundColor, backgroundColor); + _backgroundColor = [backgroundColor copy]; + [self reloadPdf]; + } +} + - (void)layoutSubviews { [super layoutSubviews]; @@ -122,6 +140,8 @@ - (void)layoutSubviews _pdfScrollView.frame = self.bounds; _pdfScrollView.zoomScale = (_zoom == NULL ? 1.0 : [_zoom doubleValue]); + _pdfScrollView.layer.borderWidth = (_borderWidth == NULL ? 5 : [_borderWidth intValue]); + _pdfScrollView.backgroundColor = (_backgroundColor == NULL ? [UIColor whiteColor] : _backgroundColor); _pdfScrollView.PDFScale = myScale; _pdfScrollView.tiledPDFView.bounds = self.bounds; _pdfScrollView.tiledPDFView.myScale = myScale; diff --git a/RNPDFView/RNPDFViewManager.m b/RNPDFView/RNPDFViewManager.m index 8f1714d..9c9857b 100644 --- a/RNPDFView/RNPDFViewManager.m +++ b/RNPDFView/RNPDFViewManager.m @@ -25,6 +25,8 @@ - (UIView *)view RCT_EXPORT_VIEW_PROPERTY(path, NSString); RCT_EXPORT_VIEW_PROPERTY(pageNumber, NSNumber); RCT_EXPORT_VIEW_PROPERTY(zoom, NSNumber); +RCT_EXPORT_VIEW_PROPERTY(borderWidth, NSNumber); +RCT_EXPORT_VIEW_PROPERTY(backgroundColor, UIColor); RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock); @end \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 5616d02..478034a 100755 --- a/android/build.gradle +++ b/android/build.gradle @@ -29,5 +29,5 @@ repositories { dependencies { compile 'com.facebook.react:react-native:0.20.+' - compile 'com.github.barteksc:android-pdf-viewer:2.3.0' + compile 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1' } diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f84c1f8 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,119 @@ +{ + "name": "react-native-pdf-view", + "version": "0.4.1", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "asap": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/asap/-/asap-2.0.6.tgz", + "integrity": "sha1-5QNHYR1+aQlDIIu9r+vLwvuGbUY=" + }, + "core-js": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-1.2.7.tgz", + "integrity": "sha1-ZSKUwUZR2yj6k70tX/KYOk8IxjY=" + }, + "encoding": { + "version": "0.1.12", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.12.tgz", + "integrity": "sha1-U4tm8+5izRq1HsMjgp0flIDHS+s=", + "requires": { + "iconv-lite": "0.4.19" + } + }, + "fbjs": { + "version": "0.8.16", + "resolved": "https://registry.npmjs.org/fbjs/-/fbjs-0.8.16.tgz", + "integrity": "sha1-XmdDL1UNxBtXK/VYR7ispk5TN9s=", + "requires": { + "core-js": "1.2.7", + "isomorphic-fetch": "2.2.1", + "loose-envify": "1.3.1", + "object-assign": "4.1.1", + "promise": "7.3.1", + "setimmediate": "1.0.5", + "ua-parser-js": "0.7.17" + } + }, + "iconv-lite": { + "version": "0.4.19", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.19.tgz", + "integrity": "sha512-oTZqweIP51xaGPI4uPa56/Pri/480R+mo7SeU+YETByQNhDG55ycFyNLIgta9vXhILrxXDmF7ZGhqZIcuN0gJQ==" + }, + "is-stream": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/is-stream/-/is-stream-1.1.0.tgz", + "integrity": "sha1-EtSj3U5o4Lec6428hBc66A2RykQ=" + }, + "isomorphic-fetch": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/isomorphic-fetch/-/isomorphic-fetch-2.2.1.tgz", + "integrity": "sha1-YRrhrPFPXoH3KVB0coGf6XM1WKk=", + "requires": { + "node-fetch": "1.7.3", + "whatwg-fetch": "2.0.3" + } + }, + "js-tokens": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-3.0.2.tgz", + "integrity": "sha1-mGbfOVECEw449/mWvOtlRDIJwls=" + }, + "loose-envify": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.3.1.tgz", + "integrity": "sha1-0aitM/qc4OcT1l/dCsi3SNR4yEg=", + "requires": { + "js-tokens": "3.0.2" + } + }, + "node-fetch": { + "version": "1.7.3", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz", + "integrity": "sha512-NhZ4CsKx7cYm2vSrBAr2PvFOe6sWDf0UYLRqA6svUYg7+/TSfVAu49jYC4BvQ4Sms9SZgdqGBgroqfDhJdTyKQ==", + "requires": { + "encoding": "0.1.12", + "is-stream": "1.1.0" + } + }, + "object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha1-IQmtx5ZYh8/AXLvUQsrIv7s2CGM=" + }, + "promise": { + "version": "7.3.1", + "resolved": "https://registry.npmjs.org/promise/-/promise-7.3.1.tgz", + "integrity": "sha512-nolQXZ/4L+bP/UGlkfaIujX9BKxGwmQ9OT4mOt5yvy8iK1h3wqTEJCijzGANTCCl9nWjY41juyAn2K3Q1hLLTg==", + "requires": { + "asap": "2.0.6" + } + }, + "prop-types": { + "version": "15.6.0", + "resolved": "https://registry.npmjs.org/prop-types/-/prop-types-15.6.0.tgz", + "integrity": "sha1-zq8IMCL8RrSjX2nhPvda7Q1jmFY=", + "requires": { + "fbjs": "0.8.16", + "loose-envify": "1.3.1", + "object-assign": "4.1.1" + } + }, + "setimmediate": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/setimmediate/-/setimmediate-1.0.5.tgz", + "integrity": "sha1-KQy7Iy4waULX1+qbg3Mqt4VvgoU=" + }, + "ua-parser-js": { + "version": "0.7.17", + "resolved": "https://registry.npmjs.org/ua-parser-js/-/ua-parser-js-0.7.17.tgz", + "integrity": "sha512-uRdSdu1oA1rncCQL7sCj8vSyZkgtL7faaw9Tc9rZ3mGgraQ7+Pdx7w5mnOSF3gw9ZNG6oc+KXfkon3bKuROm0g==" + }, + "whatwg-fetch": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/whatwg-fetch/-/whatwg-fetch-2.0.3.tgz", + "integrity": "sha1-nITsLc9oGH/wC8ZOEnS0QhduHIQ=" + } + } +} diff --git a/package.json b/package.json index 5fc6178..e6ef726 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-native-pdf-view", - "version": "0.4.0", + "version": "0.4.1", "description": "A pdf file view component for react native.", "main": "index.js", "typings": "./index.d.ts", @@ -27,5 +27,8 @@ "peerDependencies": { "@types/react": "*", "@types/react-native": "*" + }, + "dependencies": { + "prop-types": "^15.6.0" } }