Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion PDFView.android.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
5 changes: 4 additions & 1 deletion PDFView.ios.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -27,6 +28,8 @@ PDFView.propTypes = {
path: PropTypes.string,
pageNumber: PropTypes.number,
zoom: PropTypes.number,
borderWidth: PropTypes.number,
backgroundColor: PropTypes.string,
onLoadComplete: PropTypes.func
};

Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 | ✔ | ✔ |
44 changes: 24 additions & 20 deletions RNPDFView/PDFScrollView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand All @@ -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;
Expand All @@ -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.
Expand Down Expand Up @@ -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];
Expand All @@ -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 {
Expand Down
4 changes: 3 additions & 1 deletion RNPDFView/RNPDFView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
@end
20 changes: 20 additions & 0 deletions RNPDFView/RNPDFView.m
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions RNPDFView/RNPDFViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
119 changes: 119 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand All @@ -27,5 +27,8 @@
"peerDependencies": {
"@types/react": "*",
"@types/react-native": "*"
},
"dependencies": {
"prop-types": "^15.6.0"
}
}