Skip to content

Commit

Permalink
fix in iPad can not zoom problem(offset still has problem, but zoom w…
Browse files Browse the repository at this point in the history
…orks)
  • Loading branch information
Wonday committed Jun 3, 2018
1 parent a3d1f60 commit a0c59d5
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions PdfPageView.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ PdfPageView.propTypes = {
...ViewPropTypes,
fileNo: PropTypes.number,
page: PropTypes.number,
scale: PropTypes.number,
width: PropTypes.number,
height: PropTypes.number
};
Expand Down
1 change: 1 addition & 0 deletions PdfView.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ export default class PdfView extends Component {
key={item.id}
fileNo={this.state.fileNo}
page={item.key + 1}
scale={this.state.scale}
width={this._getPageWidth()}
height={this._getPageHeight()}
/>
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ A2. Your react-native version is too old, please upgrade it to 0.47.0+ see also

### ChangeLog

v3.0.14
1. fix in iPad can not zoom problem(offset still has problem, but zoom works)

v3.0.13
1. fix in iPad layout not center problem

Expand Down
2 changes: 2 additions & 0 deletions ios/RCTPdf/RCTPdfPageView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

@property(nonatomic) int fileNo;
@property(nonatomic) int page;
@property(nonatomic) CGFloat scale;



@end
9 changes: 7 additions & 2 deletions ios/RCTPdf/RCTPdfPageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ - (instancetype)init
{
self = [super init];
if (self) {

self.scale = 1.0f;
self.backgroundColor = UIColor.whiteColor;
CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
tiledLayer.levelsOfDetailBias = 0;

}

return self;
}


// The layer's class should be CATiledLayer.
+ (Class)layerClass
{
Expand All @@ -78,6 +80,8 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
- (void)reactSetFrame:(CGRect)frame
{
[super reactSetFrame:frame];
CATiledLayer *tiledLayer = (CATiledLayer *)[self layer];
tiledLayer.tileSize = frame.size;
}

-(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
Expand Down Expand Up @@ -107,6 +111,7 @@ -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context

CGAffineTransform pageTransform = CGPDFPageGetDrawingTransform(pdfPage, kCGPDFCropBox, pageBounds, 0, true);
CGContextConcatCTM(context, pageTransform);
CGContextScaleCTM(context, self.scale, self.scale);

CGContextDrawPDFPage(context, pdfPage);
CGContextRestoreGState(context);
Expand All @@ -117,4 +122,4 @@ -(void)drawLayer:(CALayer*)layer inContext:(CGContextRef)context
}
}

@end
@end
1 change: 1 addition & 0 deletions ios/RCTPdf/RCTPdfPageViewManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ - (UIView *)view

RCT_EXPORT_VIEW_PROPERTY(fileNo, int);
RCT_EXPORT_VIEW_PROPERTY(page, int);
RCT_EXPORT_VIEW_PROPERTY(scale, CGFloat);

+ (BOOL)requiresMainQueueSetup {
return YES;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-pdf",
"version": "3.0.13",
"version": "3.0.14",
"description": "A react native PDF view component",
"main": "index.js",
"typings": "./index.d.ts",
Expand Down

0 comments on commit a0c59d5

Please sign in to comment.