From c007fa5e214defdfc25a3424ae09e7dbcc86bb17 Mon Sep 17 00:00:00 2001 From: Wonday Date: Tue, 31 Jul 2018 14:03:59 +0800 Subject: [PATCH] use PDFKit to show pdf if support --- index.js | 38 ++- ios/RCTPdf.xcodeproj/project.pbxproj | 24 ++ ios/RCTPdf/RCTPdfView.h | 39 +++ ios/RCTPdf/RCTPdfView.m | 382 +++++++++++++++++++++++++++ ios/RCTPdf/RCTPdfViewManager.h | 18 ++ ios/RCTPdf/RCTPdfViewManager.m | 56 ++++ 6 files changed, 550 insertions(+), 7 deletions(-) create mode 100644 ios/RCTPdf/RCTPdfView.h create mode 100644 ios/RCTPdf/RCTPdfView.m create mode 100644 ios/RCTPdf/RCTPdfViewManager.h create mode 100644 ios/RCTPdf/RCTPdfViewManager.m diff --git a/index.js b/index.js index 7295fdd3..c1fa5984 100644 --- a/index.js +++ b/index.js @@ -94,6 +94,7 @@ export default class Pdf extends Component { path: '', isDownloaded: false, progress: 0, + isSupportPDFKit: false }; this.lastRNBFTask = null; @@ -119,6 +120,12 @@ export default class Pdf extends Component { } componentDidMount() { + if (Platform.OS === "ios") { + const PdfViewManagerNative = require('react-native').NativeModules.PdfViewManager; + PdfViewManagerNative.supportPDFKit((isSupportPDFKit)=>{ + this.setState({isSupportPDFKit:isSupportPDFKit}); + }); + } this._loadFromSource(this.props.source); } @@ -374,18 +381,30 @@ export default class Pdf extends Component { /> ); } else if (Platform.OS === "ios") { + if (this.state.isSupportPDFKit) { return ( - (this._root = component)} {...this.props} style={[{backgroundColor: '#EEE'}, this.props.style]} path={this.state.path} - onLoadComplete={this.props.onLoadComplete} - onPageChanged={this.props.onPageChanged} - onError={this._onError} - onPageSingleTap={this.props.onPageSingleTap} - onScaleChanged={this.props.onScaleChanged} + onChange={this._onChange} /> - ); + ); + } else { + return ( + + ); + } } else { return (null); } @@ -399,8 +418,13 @@ if (Platform.OS === "android") { var PdfCustom = requireNativeComponent('RCTPdf', Pdf, { nativeOnly: {path: true, onChange: true}, }) +} else if (Platform.OS === "ios") { + var PdfCustom = requireNativeComponent('RCTPdfView', Pdf, { + nativeOnly: {path: true, onChange: true}, + }) } + const styles = StyleSheet.create({ progressContainer: { flex: 1, diff --git a/ios/RCTPdf.xcodeproj/project.pbxproj b/ios/RCTPdf.xcodeproj/project.pbxproj index 9a27a55c..ea379093 100644 --- a/ios/RCTPdf.xcodeproj/project.pbxproj +++ b/ios/RCTPdf.xcodeproj/project.pbxproj @@ -7,6 +7,9 @@ objects = { /* Begin PBXBuildFile section */ + 5267DA06210F0EDE00D20C59 /* RCTPdfView.m in Sources */ = {isa = PBXBuildFile; fileRef = 5267DA03210F0EDD00D20C59 /* RCTPdfView.m */; }; + 5267DA07210F0EDE00D20C59 /* RCTPdfViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 5267DA05210F0EDE00D20C59 /* RCTPdfViewManager.m */; }; + 5267DA0A210F0F0800D20C59 /* PDFKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5267DA09210F0F0800D20C59 /* PDFKit.framework */; }; 526B80401EABD92200259970 /* RCTPdfPageViewManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 526B803F1EABD92200259970 /* RCTPdfPageViewManager.m */; }; 52A324EA1FD3C3FB000B0B18 /* PdfManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 52A324E91FD3C3FB000B0B18 /* PdfManager.m */; }; 52F79DB71EB2DA4F00CAD00C /* RCTPdfPageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 52F79DB41EB2DA4F00CAD00C /* RCTPdfPageView.m */; }; @@ -26,6 +29,11 @@ /* Begin PBXFileReference section */ 20D8E03F1C8E946C00039823 /* libRCTPdf.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRCTPdf.a; sourceTree = BUILT_PRODUCTS_DIR; }; + 5267DA02210F0EDD00D20C59 /* RCTPdfView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPdfView.h; sourceTree = ""; }; + 5267DA03210F0EDD00D20C59 /* RCTPdfView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPdfView.m; sourceTree = ""; }; + 5267DA04210F0EDD00D20C59 /* RCTPdfViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPdfViewManager.h; sourceTree = ""; }; + 5267DA05210F0EDE00D20C59 /* RCTPdfViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPdfViewManager.m; sourceTree = ""; }; + 5267DA09210F0F0800D20C59 /* PDFKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = PDFKit.framework; path = System/Library/Frameworks/PDFKit.framework; sourceTree = SDKROOT; }; 526B803E1EABD92200259970 /* RCTPdfPageViewManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = RCTPdfPageViewManager.h; sourceTree = ""; }; 526B803F1EABD92200259970 /* RCTPdfPageViewManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RCTPdfPageViewManager.m; sourceTree = ""; }; 52A324E81FD3C3FB000B0B18 /* PdfManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PdfManager.h; sourceTree = ""; }; @@ -39,6 +47,7 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( + 5267DA0A210F0F0800D20C59 /* PDFKit.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -50,6 +59,7 @@ children = ( 20D8E0411C8E946C00039823 /* RCTPdf */, 20D8E0401C8E946C00039823 /* Products */, + 5267DA08210F0F0800D20C59 /* Frameworks */, ); sourceTree = ""; }; @@ -64,6 +74,10 @@ 20D8E0411C8E946C00039823 /* RCTPdf */ = { isa = PBXGroup; children = ( + 5267DA02210F0EDD00D20C59 /* RCTPdfView.h */, + 5267DA03210F0EDD00D20C59 /* RCTPdfView.m */, + 5267DA04210F0EDD00D20C59 /* RCTPdfViewManager.h */, + 5267DA05210F0EDE00D20C59 /* RCTPdfViewManager.m */, 52A324E81FD3C3FB000B0B18 /* PdfManager.h */, 52A324E91FD3C3FB000B0B18 /* PdfManager.m */, 52F79DB31EB2DA4F00CAD00C /* RCTPdfPageView.h */, @@ -74,6 +88,14 @@ path = RCTPdf; sourceTree = ""; }; + 5267DA08210F0F0800D20C59 /* Frameworks */ = { + isa = PBXGroup; + children = ( + 5267DA09210F0F0800D20C59 /* PDFKit.framework */, + ); + name = Frameworks; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -132,6 +154,8 @@ buildActionMask = 2147483647; files = ( 52A324EA1FD3C3FB000B0B18 /* PdfManager.m in Sources */, + 5267DA07210F0EDE00D20C59 /* RCTPdfViewManager.m in Sources */, + 5267DA06210F0EDE00D20C59 /* RCTPdfView.m in Sources */, 526B80401EABD92200259970 /* RCTPdfPageViewManager.m in Sources */, 52F79DB71EB2DA4F00CAD00C /* RCTPdfPageView.m in Sources */, ); diff --git a/ios/RCTPdf/RCTPdfView.h b/ios/RCTPdf/RCTPdfView.h new file mode 100644 index 00000000..6eb7b292 --- /dev/null +++ b/ios/RCTPdf/RCTPdfView.h @@ -0,0 +1,39 @@ +/** + * Copyright (c) 2017-present, Wonday (@wonday.org) + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#ifndef RCTPdfView_h +#define RCTPdfView_h + +#if __has_include() +#import +#import +#else +#import "RCTEventDispatcher.h" +#import "UIView+React.h" +#endif + + +@class RCTEventDispatcher; + +@interface RCTPdfView : UIView + +@property(nonatomic, strong) NSString *path; +@property(nonatomic) int page; +@property(nonatomic) float scale; +@property(nonatomic) BOOL horizontal; +@property(nonatomic) int fitPolicy; +@property(nonatomic) int spacing; +@property(nonatomic, strong) NSString *password; + + +@property(nonatomic, copy) RCTBubblingEventBlock onChange; + + +@end + +#endif /* RCTPdfView_h */ diff --git a/ios/RCTPdf/RCTPdfView.m b/ios/RCTPdf/RCTPdfView.m new file mode 100644 index 00000000..af1d1514 --- /dev/null +++ b/ios/RCTPdf/RCTPdfView.m @@ -0,0 +1,382 @@ +/** + * Copyright (c) 2017-present, Wonday (@wonday.org) + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import "RCTPdfView.h" + +#import +#import +#import + +#if __has_include() +#import +#import +#import +#import +#else +#import "RCTBridgeModule.h" +#import "RCTEventDispatcher.h" +#import "UIView+React.h" +#import "RCTLog.h" +#endif + +#ifndef __OPTIMIZE__ +// only output log when debug +#define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) +#else +#define DLog( s, ... ) +#endif + +// output log both debug and release +#define RLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] ) + +@implementation RCTPdfView +{ + PDFDocument *_pdfDocument; + PDFView *_pdfView; + float _fixScaleFactor; + float _lastScale; + bool _initialed; + +} + +- (instancetype)init +{ + self = [super init]; + if (self) { + + // init and config PDFView + _pdfView = [[PDFView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)]; + _pdfView.displayMode = kPDFDisplaySinglePageContinuous; + _pdfView.autoScales = YES; + _pdfView.displaysPageBreaks = YES; + _pdfView.displayBox = kPDFDisplayBoxMediaBox; + _pdfView.backgroundColor = [UIColor colorWithRed:0.875 green:0.875 blue:0.875 alpha:1.0]; //#EEE + + _fixScaleFactor = -1.0f; + _lastScale = -1.0; + _initialed = NO; + + [self addSubview:_pdfView]; + + + // register notification + NSNotificationCenter *center = [NSNotificationCenter defaultCenter]; + [center addObserver:self selector:@selector(onDocumentChanged:) name:PDFViewDocumentChangedNotification object:_pdfView]; + [center addObserver:self selector:@selector(onPageChanged:) name:PDFViewPageChangedNotification object:_pdfView]; + [center addObserver:self selector:@selector(onScaleChanged:) name:PDFViewScaleChangedNotification object:_pdfView]; + + [self bindTap]; + } + + return self; +} + +- (void)didSetProps:(NSArray *)changedProps +{ + long int count = [changedProps count]; + for (int i = 0 ; i < count; i++) { + if ([[changedProps objectAtIndex:i] isEqualToString:@"path"]) { + + NSURL *fileURL = [NSURL fileURLWithPath:_path]; + + if (_pdfDocument != Nil) { + //Release old doc + _pdfDocument = Nil; + } + + _pdfDocument = [[PDFDocument alloc] initWithURL:fileURL]; + + if (_pdfDocument) { + + //check need password or not + if (_pdfDocument.isLocked && ![_pdfDocument unlockWithPassword:_password]) { + + _onChange(@{ @"message": @"error|Password required or incorrect password."}); + + _pdfDocument = Nil; + [_pdfView goToPage:[_pdfDocument pageAtIndex:_page-1]]; + + return; + } + + _pdfView.document = _pdfDocument; + } else { + + _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"error|Load pdf failed. path=%s",_path.UTF8String]]}); + + _pdfDocument = Nil; + return; + } + } + + if (_pdfDocument && ([[changedProps objectAtIndex:i] isEqualToString:@"path"] || [[changedProps objectAtIndex:i] isEqualToString:@"page"])) { + [_pdfView goToPage:[_pdfDocument pageAtIndex:_page-1]]; + } + + if (_pdfDocument && ([[changedProps objectAtIndex:i] isEqualToString:@"path"] || [[changedProps objectAtIndex:i] isEqualToString:@"spacing"])) { + if (_horizontal) { + _pdfView.pageBreakMargins = UIEdgeInsetsMake(0,_spacing,0,0); + } else { + _pdfView.pageBreakMargins = UIEdgeInsetsMake(0,0,_spacing,0); + } + } + + if (_pdfDocument && ([[changedProps objectAtIndex:i] isEqualToString:@"path"] || [[changedProps objectAtIndex:i] isEqualToString:@"fitPolicy"])) { + + if (_initialed) { + PDFPage *page = [_pdfDocument pageAtIndex:0]; + CGRect pageRect = [page boundsForBox:kPDFDisplayBoxMediaBox]; + + if (_fitPolicy == 0) { + _fixScaleFactor = _pdfView.frame.size.width/pageRect.size.width; + _pdfView.minScaleFactor = _fixScaleFactor/2; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } else if (_fitPolicy == 1) { + _fixScaleFactor = _pdfView.frame.size.height/pageRect.size.height; + _pdfView.minScaleFactor = _fixScaleFactor/2; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } else { + float pageAspect = pageRect.size.width/pageRect.size.height; + float reactViewAspect = self.frame.size.width/self.frame.size.height; + if (reactViewAspect>pageAspect) { + _fixScaleFactor = self.frame.size.height/pageRect.size.height; + _pdfView.minScaleFactor = _fixScaleFactor/2; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } else { + _fixScaleFactor = self.frame.size.width/pageRect.size.width; + _pdfView.minScaleFactor = _fixScaleFactor; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } + } + } + + } + + if (_pdfDocument && ([[changedProps objectAtIndex:i] isEqualToString:@"path"] || [[changedProps objectAtIndex:i] isEqualToString:@"scale"])) { + if (_fixScaleFactor > 0.0f) { + _pdfView.scaleFactor = _scale * _fixScaleFactor; + } + } + + if (_pdfDocument && ([[changedProps objectAtIndex:i] isEqualToString:@"path"] || [[changedProps objectAtIndex:i] isEqualToString:@"horizontal"])) { + if (_horizontal) { + _pdfView.displayDirection = kPDFDisplayDirectionHorizontal; + _pdfView.pageBreakMargins = UIEdgeInsetsMake(0,_spacing,0,0); + } else { + _pdfView.displayDirection = kPDFDisplayDirectionVertical; + _pdfView.pageBreakMargins = UIEdgeInsetsMake(0,0,_spacing,0); + } + } + } + + [_pdfView.layer setNeedsDisplay]; + [self setNeedsDisplay]; +} + + +- (void)reactSetFrame:(CGRect)frame +{ + [super reactSetFrame:frame]; + + + PDFPage *page = [_pdfDocument pageAtIndex:0]; + CGRect pageRect = [page boundsForBox:kPDFDisplayBoxMediaBox]; + + // some pdf with rotation, then adjust it + if (page.rotation == 90 || page.rotation == 270) { + pageRect = CGRectMake(0, 0, pageRect.size.height, pageRect.size.width); + } + + if (_fitPolicy == 0) { + _fixScaleFactor = frame.size.width/pageRect.size.width; + _pdfView.minScaleFactor = _fixScaleFactor/2; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } else if (_fitPolicy == 1) { + _fixScaleFactor = frame.size.height/pageRect.size.height; + _pdfView.minScaleFactor = _fixScaleFactor/2; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } else { + float pageAspect = pageRect.size.width/pageRect.size.height; + float reactViewAspect = frame.size.width/frame.size.height; + if (reactViewAspect>pageAspect) { + _fixScaleFactor = frame.size.height/pageRect.size.height; + _pdfView.minScaleFactor = _fixScaleFactor/2; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } else { + _fixScaleFactor = frame.size.width/pageRect.size.width; + _pdfView.minScaleFactor = _fixScaleFactor/2; + _pdfView.maxScaleFactor = _fixScaleFactor*3; + _pdfView.scaleFactor = _fixScaleFactor; + } + } + + _pdfView.frame = frame; + [_pdfView goToPage:[_pdfDocument pageAtIndex:_page-1]]; + + _initialed = YES; +} + +- (void)dealloc{ + + _pdfDocument = Nil; + _pdfView = Nil; + + //Remove notifications + [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewDocumentChangedNotification" object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewPageChangedNotification" object:nil]; + [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewScaleChangedNotification" object:nil]; + +} + +#pragma mark notification process +- (void)onDocumentChanged:(NSNotification *)noti +{ + + if (_pdfDocument) { + unsigned long numberOfPages = _pdfDocument.pageCount; + PDFPage *page = [_pdfDocument pageAtIndex:0]; + CGSize pageSize = [_pdfView rowSizeForPage:page]; + _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"loadComplete|%lu|%f|%f", numberOfPages, pageSize.width, pageSize.height]]}); + } + +} + +- (void)onPageChanged:(NSNotification *)noti +{ + + if (_pdfDocument) { + PDFPage *currentPage = _pdfView.currentPage; + unsigned long page = [_pdfDocument indexForPage:currentPage]; + unsigned long numberOfPages = _pdfDocument.pageCount; + + _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"pageChanged|%lu|%lu", page+1, numberOfPages]]}); + } + +} + +- (void)onScaleChanged:(NSNotification *)noti +{ + + if (_initialed) { + if (_lastScale != _pdfView.scaleFactor/_fixScaleFactor) { + _lastScale = _pdfView.scaleFactor/_fixScaleFactor; + _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"scaleChanged|%f", _lastScale]]}); + } + } +} + +#pragma mark gesture process + +/** + * Tap + * zoom reset or zoom in + * + * @param recognizer + */ +- (void)handleDoubleTap:(UITapGestureRecognizer *)recognizer +{ + + // one tap add scale 1.2 times + CGFloat scale = _pdfView.scaleFactor*1.2; + + if (scale>_pdfView.maxScaleFactor){ + scale = _fixScaleFactor; + } + + _pdfView.scaleFactor = scale; + + [self setNeedsDisplay]; + +} + +/** + * Single Tap + * stop zoom + * + * @param recognizer + */ +- (void)handleSingleTap:(UITapGestureRecognizer *)sender +{ + + if (_pdfView.scaleFactor>1*_fixScaleFactor) { + _pdfView.scaleFactor = 1.0*_fixScaleFactor; + [self setNeedsDisplay]; + } else { + CGPoint point = [sender locationInView:self]; + PDFPage *pdfPage = [_pdfView pageForPoint:point nearest:NO]; + if (pdfPage) { + unsigned long page = [_pdfDocument indexForPage:pdfPage]; + _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"pageSingleTap|%lu", page+1]]}); + } + } + +} + +/** + * Pinch + * + * + * @param recognizer + */ +-(void)handlePinch:(UIPinchGestureRecognizer *)sender{ + [self onScaleChanged:Nil]; +} + +/** + * Bind tap + * + * + */ +- (void)bindTap +{ + UITapGestureRecognizer *doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(handleDoubleTap:)]; + //trigger by one finger and double touch + doubleTapRecognizer.numberOfTapsRequired = 2; + doubleTapRecognizer.numberOfTouchesRequired = 1; + + [self addGestureRecognizer:doubleTapRecognizer]; + + UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self + action:@selector(handleSingleTap:)]; + //trigger by one finger and one touch + singleTapRecognizer.numberOfTapsRequired = 1; + singleTapRecognizer.numberOfTouchesRequired = 1; + + [self addGestureRecognizer:singleTapRecognizer]; + [singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer]; + + UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self + action:@selector(handlePinch:)]; + [self addGestureRecognizer:pinchRecognizer]; + pinchRecognizer.delegate = self; + + +} + +- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer + +{ + return YES; +} + +- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer +{ + return YES; +} + + + +@end diff --git a/ios/RCTPdf/RCTPdfViewManager.h b/ios/RCTPdf/RCTPdfViewManager.h new file mode 100644 index 00000000..ba9e0340 --- /dev/null +++ b/ios/RCTPdf/RCTPdfViewManager.h @@ -0,0 +1,18 @@ +/** + * Copyright (c) 2017-present, Wonday (@wonday.org) + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#if __has_include() +#import +#else +#import "RCTViewManager.h" +#endif + + +@interface RCTPdfViewManager : RCTViewManager + +@end diff --git a/ios/RCTPdf/RCTPdfViewManager.m b/ios/RCTPdf/RCTPdfViewManager.m new file mode 100644 index 00000000..28812f1b --- /dev/null +++ b/ios/RCTPdf/RCTPdfViewManager.m @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2017-present, Wonday (@wonday.org) + * All rights reserved. + * + * This source code is licensed under the MIT-style license found in the + * LICENSE file in the root directory of this source tree. + */ + +#import + +#import "RCTPdfViewManager.h" +#import "RCTPdfView.h" + + +@implementation RCTPdfViewManager + +RCT_EXPORT_MODULE() + +- (UIView *)view +{ + if (@available(iOS 11.0, *)) { + return [[RCTPdfView alloc] init]; + } else { + return NULL; + } + +} + +RCT_EXPORT_VIEW_PROPERTY(path, NSString); +RCT_EXPORT_VIEW_PROPERTY(page, int); +RCT_EXPORT_VIEW_PROPERTY(scale, float); +RCT_EXPORT_VIEW_PROPERTY(horizontal, BOOL); +RCT_EXPORT_VIEW_PROPERTY(fitPolicy, int); +RCT_EXPORT_VIEW_PROPERTY(spacing, int); +RCT_EXPORT_VIEW_PROPERTY(password, NSString); +RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock); + +RCT_EXPORT_METHOD(supportPDFKit:(RCTResponseSenderBlock)callback) +{ + if (@available(iOS 11.0, *)) { + callback(@[@YES]); + } else { + callback(@[@NO]); + } + +} + ++ (BOOL)requiresMainQueueSetup { + return YES; +} + + +- (void)dealloc{ +} + +@end