react-native-pdf 6.6.2 → 6.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. package/README.md +17 -41
  2. package/android/build.gradle +71 -13
  3. package/android/src/main/java/org/wonday/pdf/{RCTPdfManager.java → PdfManager.java} +57 -21
  4. package/android/src/main/java/org/wonday/pdf/PdfView.java +25 -0
  5. package/android/src/main/java/org/wonday/pdf/{RCTPdfView.java → RNPDFPackage.java} +2 -3
  6. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerDelegate.java +86 -0
  7. package/android/src/paper/java/com/facebook/react/viewmanagers/RNPDFPdfViewManagerInterface.java +33 -0
  8. package/fabric/RNPDFPdfNativeComponent.js +46 -0
  9. package/index.d.ts +2 -0
  10. package/index.js +25 -27
  11. package/index.js.flow +2 -0
  12. package/ios/{RCTPdf/PdfManager.m → RNPDFPdf/PdfManager.mm} +1 -1
  13. package/ios/{RCTPdf/RCTPdfPageView.h → RNPDFPdf/RNPDFPdfPageView.h} +1 -1
  14. package/ios/{RCTPdf/RCTPdfPageView.m → RNPDFPdf/RNPDFPdfPageView.mm} +5 -5
  15. package/ios/{RCTPdf/RCTPdfPageViewManager.h → RNPDFPdf/RNPDFPdfPageViewManager.h} +1 -1
  16. package/ios/{RCTPdf/RCTPdfPageViewManager.m → RNPDFPdf/RNPDFPdfPageViewManager.mm} +4 -4
  17. package/ios/{RCTPdf/RCTPdfView.h → RNPDFPdf/RNPDFPdfView.h} +15 -5
  18. package/ios/{RCTPdf/RCTPdfView.m → RNPDFPdf/RNPDFPdfView.mm} +321 -54
  19. package/ios/{RCTPdf/RCTPdfViewManager.h → RNPDFPdf/RNPDFPdfViewManager.h} +1 -1
  20. package/ios/{RCTPdf/RCTPdfViewManager.m → RNPDFPdf/RNPDFPdfViewManager.mm} +7 -5
  21. package/ios/{RCTPdf.xcodeproj → RNPDFPdf.xcodeproj}/project.pbxproj +42 -42
  22. package/package.json +19 -3
  23. package/react-native-pdf.podspec +28 -3
  24. package/windows/RCTPdf/pch.h +2 -0
  25. package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
  26. /package/ios/{RCTPdf → RNPDFPdf}/PdfManager.h +0 -0
@@ -6,7 +6,7 @@
6
6
  * LICENSE file in the root directory of this source tree.
7
7
  */
8
8
 
9
- #import "RCTPdfView.h"
9
+ #import "RNPDFPdfView.h"
10
10
 
11
11
  #import <Foundation/Foundation.h>
12
12
  #import <QuartzCore/QuartzCore.h>
@@ -26,6 +26,21 @@
26
26
  #import <RCTBlobManager.h">
27
27
  #endif
28
28
 
29
+ #ifdef RCT_NEW_ARCH_ENABLED
30
+ #import <React/RCTConversions.h>
31
+ #import <React/RCTFabricComponentsPlugins.h>
32
+ #import <react/renderer/components/rnpdf/ComponentDescriptors.h>
33
+ #import <react/renderer/components/rnpdf/Props.h>
34
+ #import <react/renderer/components/rnpdf/RCTComponentViewHelpers.h>
35
+
36
+ // Some RN private method hacking below similar to how it is done in RNScreens:
37
+ // https://github.com/software-mansion/react-native-screens/blob/90e548739f35b5ded2524a9d6410033fc233f586/ios/RNSScreenStackHeaderConfig.mm#L30
38
+ @interface RCTBridge (Private)
39
+ + (RCTBridge *)currentBridge;
40
+ @end
41
+
42
+ #endif
43
+
29
44
  #ifndef __OPTIMIZE__
30
45
  // only output log when debug
31
46
  #define DLog( s, ... ) NSLog( @"<%p %@:(%d)> %@", self, [[NSString stringWithUTF8String:__FILE__] lastPathComponent], __LINE__, [NSString stringWithFormat:(s), ##__VA_ARGS__] )
@@ -39,7 +54,14 @@
39
54
  const float MAX_SCALE = 3.0f;
40
55
  const float MIN_SCALE = 1.0f;
41
56
 
42
- @implementation RCTPdfView
57
+ @interface RNPDFPdfView() <PDFDocumentDelegate, PDFViewDelegate
58
+ #ifdef RCT_NEW_ARCH_ENABLED
59
+ , RCTRNPDFPdfViewViewProtocol
60
+ #endif
61
+ >
62
+ @end
63
+
64
+ @implementation RNPDFPdfView
43
65
  {
44
66
  RCTBridge *_bridge;
45
67
  PDFDocument *_pdfDocument;
@@ -48,64 +70,217 @@ const float MIN_SCALE = 1.0f;
48
70
  float _fixScaleFactor;
49
71
  bool _initialed;
50
72
  NSArray<NSString *> *_changedProps;
73
+ UITapGestureRecognizer *_doubleTapRecognizer;
74
+ UITapGestureRecognizer *_singleTapRecognizer;
75
+ UIPinchGestureRecognizer *_pinchRecognizer;
76
+ UILongPressGestureRecognizer *_longPressRecognizer;
51
77
  }
52
78
 
53
- - (instancetype)initWithBridge:(RCTBridge *)bridge
79
+ #ifdef RCT_NEW_ARCH_ENABLED
80
+
81
+ using namespace facebook::react;
82
+
83
+ + (ComponentDescriptorProvider)componentDescriptorProvider
54
84
  {
55
- self = [super init];
56
- if (self) {
85
+ return concreteComponentDescriptorProvider<RNPDFPdfViewComponentDescriptor>();
86
+ }
57
87
 
58
- _bridge = bridge;
59
- _page = 1;
60
- _scale = 1;
61
- _minScale = MIN_SCALE;
62
- _maxScale = MAX_SCALE;
63
- _horizontal = NO;
64
- _enablePaging = NO;
65
- _enableRTL = NO;
66
- _enableAnnotationRendering = YES;
67
- _fitPolicy = 2;
68
- _spacing = 10;
69
- _singlePage = NO;
70
-
71
- // init and config PDFView
72
- _pdfView = [[PDFView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
73
- _pdfView.displayMode = kPDFDisplaySinglePageContinuous;
74
- _pdfView.autoScales = YES;
75
- _pdfView.displaysPageBreaks = YES;
76
- _pdfView.displayBox = kPDFDisplayBoxCropBox;
77
- _pdfView.backgroundColor = [UIColor clearColor];
88
+ - (instancetype)initWithFrame:(CGRect)frame
89
+ {
90
+ if (self = [super initWithFrame:frame]) {
91
+ static const auto defaultProps = std::make_shared<const RNPDFPdfViewProps>();
92
+ _props = defaultProps;
93
+ [self initCommonProps];
94
+ }
95
+ return self;
96
+ }
97
+
98
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
99
+ {
100
+ const auto &newProps = *std::static_pointer_cast<const RNPDFPdfViewProps>(props);
101
+ NSMutableArray<NSString *> *updatedPropNames = [NSMutableArray new];
102
+ if (_path != RCTNSStringFromStringNilIfEmpty(newProps.path)) {
103
+ _path = RCTNSStringFromStringNilIfEmpty(newProps.path);
104
+ [updatedPropNames addObject:@"path"];
105
+ }
106
+ if (_page != newProps.page) {
107
+ _page = newProps.page;
108
+ [updatedPropNames addObject:@"page"];
109
+ }
110
+ if (_scale != newProps.scale) {
111
+ _scale = newProps.scale;
112
+ [updatedPropNames addObject:@"scale"];
113
+ }
114
+ if (_minScale != newProps.minScale) {
115
+ _minScale = newProps.minScale;
116
+ [updatedPropNames addObject:@"minScale"];
117
+ }
118
+ if (_maxScale != newProps.maxScale) {
119
+ _maxScale = newProps.maxScale;
120
+ [updatedPropNames addObject:@"maxScale"];
121
+ }
122
+ if (_horizontal != newProps.horizontal) {
123
+ _horizontal = newProps.horizontal;
124
+ [updatedPropNames addObject:@"horizontal"];
125
+ }
126
+ if (_enablePaging != newProps.enablePaging) {
127
+ _enablePaging = newProps.enablePaging;
128
+ [updatedPropNames addObject:@"enablePaging"];
129
+ }
130
+ if (_enableRTL != newProps.enableRTL) {
131
+ _enableRTL = newProps.enableRTL;
132
+ [updatedPropNames addObject:@"enableRTL"];
133
+ }
134
+ if (_enableAnnotationRendering != newProps.enableAnnotationRendering) {
135
+ _enableAnnotationRendering = newProps.enableAnnotationRendering;
136
+ [updatedPropNames addObject:@"enableAnnotationRendering"];
137
+ }
138
+ if (_fitPolicy != newProps.fitPolicy) {
139
+ _fitPolicy = newProps.fitPolicy;
140
+ [updatedPropNames addObject:@"fitPolicy"];
141
+ }
142
+ if (_spacing != newProps.spacing) {
143
+ _spacing = newProps.spacing;
144
+ [updatedPropNames addObject:@"spacing"];
145
+ }
146
+ if (_password != RCTNSStringFromStringNilIfEmpty(newProps.password)) {
147
+ _password = RCTNSStringFromStringNilIfEmpty(newProps.password);
148
+ [updatedPropNames addObject:@"password"];
149
+ }
150
+ if (_singlePage != newProps.singlePage) {
151
+ _singlePage = newProps.singlePage;
152
+ [updatedPropNames addObject:@"singlePage"];
153
+ }
154
+ if (_showsHorizontalScrollIndicator != newProps.showsHorizontalScrollIndicator) {
155
+ _showsHorizontalScrollIndicator = newProps.showsHorizontalScrollIndicator;
156
+ [updatedPropNames addObject:@"showsHorizontalScrollIndicator"];
157
+ }
158
+ if (_showsVerticalScrollIndicator != newProps.showsVerticalScrollIndicator) {
159
+ _showsVerticalScrollIndicator = newProps.showsVerticalScrollIndicator;
160
+ [updatedPropNames addObject:@"showsVerticalScrollIndicator"];
161
+ }
162
+
163
+ [super updateProps:props oldProps:oldProps];
164
+ [self didSetProps:updatedPropNames];
165
+ }
166
+
167
+ // already added in case https://github.com/facebook/react-native/pull/35378 has been merged
168
+ - (BOOL)shouldBeRecycled
169
+ {
170
+ return NO;
171
+ }
78
172
 
79
- _fixScaleFactor = -1.0f;
80
- _initialed = NO;
81
- _changedProps = NULL;
173
+ - (void)prepareForRecycle
174
+ {
175
+ [super prepareForRecycle];
176
+
177
+ [_pdfView removeFromSuperview];
178
+ _pdfDocument = Nil;
179
+ _pdfView = Nil;
180
+ //Remove notifications
181
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewDocumentChangedNotification" object:nil];
182
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewPageChangedNotification" object:nil];
183
+ [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewScaleChangedNotification" object:nil];
184
+
185
+ // remove old recognizers before adding new ones
186
+ [self removeGestureRecognizer:_doubleTapRecognizer];
187
+ [self removeGestureRecognizer:_singleTapRecognizer];
188
+ [self removeGestureRecognizer:_pinchRecognizer];
189
+ [self removeGestureRecognizer:_longPressRecognizer];
190
+
191
+ [self initCommonProps];
192
+ }
193
+
194
+ - (void)updateLayoutMetrics:(const facebook::react::LayoutMetrics &)layoutMetrics oldLayoutMetrics:(const facebook::react::LayoutMetrics &)oldLayoutMetrics
195
+ {
196
+ // Fabric equivalent of `reactSetFrame` method
197
+ [super updateLayoutMetrics:layoutMetrics oldLayoutMetrics:oldLayoutMetrics];
198
+ _pdfView.frame = CGRectMake(0, 0, layoutMetrics.frame.size.width, layoutMetrics.frame.size.height);
82
199
 
83
- [self addSubview:_pdfView];
200
+ NSMutableArray *mProps = [_changedProps mutableCopy];
201
+ if (_initialed) {
202
+ [mProps removeObject:@"path"];
203
+ }
204
+ _initialed = YES;
84
205
 
206
+ [self didSetProps:mProps];
207
+ }
85
208
 
86
- // register notification
87
- NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
88
- [center addObserver:self selector:@selector(onDocumentChanged:) name:PDFViewDocumentChangedNotification object:_pdfView];
89
- [center addObserver:self selector:@selector(onPageChanged:) name:PDFViewPageChangedNotification object:_pdfView];
90
- [center addObserver:self selector:@selector(onScaleChanged:) name:PDFViewScaleChangedNotification object:_pdfView];
209
+ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args
210
+ {
211
+ RCTRNPDFPdfViewHandleCommand(self, commandName, args);
212
+ }
91
213
 
92
- [[_pdfView document] setDelegate: self];
93
- [_pdfView setDelegate: self];
214
+ - (void)setNativePage:(NSInteger)page
215
+ {
216
+ _page = page;
217
+ [self didSetProps:[NSArray arrayWithObject:@"page"]];
218
+ }
94
219
 
220
+ #endif
95
221
 
96
- [self bindTap];
222
+ - (instancetype)initWithBridge:(RCTBridge *)bridge
223
+ {
224
+ self = [super init];
225
+ if (self) {
226
+ _bridge = bridge;
227
+ [self initCommonProps];
97
228
  }
98
229
 
99
230
  return self;
100
231
  }
101
232
 
233
+ - (void)initCommonProps
234
+ {
235
+ _page = 1;
236
+ _scale = 1;
237
+ _minScale = MIN_SCALE;
238
+ _maxScale = MAX_SCALE;
239
+ _horizontal = NO;
240
+ _enablePaging = NO;
241
+ _enableRTL = NO;
242
+ _enableAnnotationRendering = YES;
243
+ _fitPolicy = 2;
244
+ _spacing = 10;
245
+ _singlePage = NO;
246
+ _showsHorizontalScrollIndicator = YES;
247
+ _showsVerticalScrollIndicator = YES;
248
+
249
+ // init and config PDFView
250
+ _pdfView = [[PDFView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
251
+ _pdfView.displayMode = kPDFDisplaySinglePageContinuous;
252
+ _pdfView.autoScales = YES;
253
+ _pdfView.displaysPageBreaks = YES;
254
+ _pdfView.displayBox = kPDFDisplayBoxCropBox;
255
+ _pdfView.backgroundColor = [UIColor clearColor];
256
+
257
+ _fixScaleFactor = -1.0f;
258
+ _initialed = NO;
259
+ _changedProps = NULL;
260
+
261
+ [self addSubview:_pdfView];
262
+
263
+
264
+ // register notification
265
+ NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
266
+ [center addObserver:self selector:@selector(onDocumentChanged:) name:PDFViewDocumentChangedNotification object:_pdfView];
267
+ [center addObserver:self selector:@selector(onPageChanged:) name:PDFViewPageChangedNotification object:_pdfView];
268
+ [center addObserver:self selector:@selector(onScaleChanged:) name:PDFViewScaleChangedNotification object:_pdfView];
269
+
270
+ [[_pdfView document] setDelegate: self];
271
+ [_pdfView setDelegate: self];
272
+
273
+
274
+ [self bindTap];
275
+ }
276
+
102
277
  - (void)PDFViewWillClickOnLink:(PDFView *)sender withURL:(NSURL *)url
103
278
  {
104
279
  NSString *_url = url.absoluteString;
105
- _onChange(@{ @"message":
280
+ [self notifyOnChangeWithMessage:
106
281
  [[NSString alloc] initWithString:
107
282
  [NSString stringWithFormat:
108
- @"linkPressed|%s", _url.UTF8String]] });
283
+ @"linkPressed|%s", _url.UTF8String]]];
109
284
  }
110
285
 
111
286
  - (void)didSetProps:(NSArray<NSString *> *)changedProps
@@ -125,7 +300,13 @@ const float MIN_SCALE = 1.0f;
125
300
  }
126
301
 
127
302
  if ([_path hasPrefix:@"blob:"]) {
128
- RCTBlobManager *blobManager = [_bridge moduleForName:@"BlobModule"];
303
+ RCTBlobManager *blobManager = [
304
+ #ifdef RCT_NEW_ARCH_ENABLED
305
+ [RCTBridge currentBridge]
306
+ #else
307
+ _bridge
308
+ #endif // RCT_NEW_ARCH_ENABLED
309
+ moduleForName:@"BlobModule"];
129
310
  NSURL *blobURL = [NSURL URLWithString:_path];
130
311
  NSData *blobData = [blobManager resolveURL:blobURL];
131
312
  if (blobData != nil) {
@@ -144,7 +325,7 @@ const float MIN_SCALE = 1.0f;
144
325
  //check need password or not
145
326
  if (_pdfDocument.isLocked && ![_pdfDocument unlockWithPassword:_password]) {
146
327
 
147
- _onChange(@{ @"message": @"error|Password required or incorrect password."});
328
+ [self notifyOnChangeWithMessage:@"error|Password required or incorrect password."];
148
329
 
149
330
  _pdfDocument = Nil;
150
331
  return;
@@ -153,7 +334,7 @@ const float MIN_SCALE = 1.0f;
153
334
  _pdfView.document = _pdfDocument;
154
335
  } else {
155
336
 
156
- _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"error|Load pdf failed. path=%s",_path.UTF8String]]});
337
+ [self notifyOnChangeWithMessage:[[NSString alloc] initWithString:[NSString stringWithFormat:@"error|Load pdf failed. path=%s",_path.UTF8String]]];
157
338
 
158
339
  _pdfDocument = Nil;
159
340
  return;
@@ -273,6 +454,42 @@ const float MIN_SCALE = 1.0f;
273
454
  }
274
455
  }
275
456
 
457
+ if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"showsHorizontalScrollIndicator"])) {
458
+ if (_showsHorizontalScrollIndicator) {
459
+ for (UIView *subview in _pdfView.subviews) {
460
+ if ([subview isKindOfClass:[UIScrollView class]]) {
461
+ UIScrollView *scrollView = (UIScrollView *)subview;
462
+ scrollView.showsHorizontalScrollIndicator = YES;
463
+ }
464
+ }
465
+ } else {
466
+ for (UIView *subview in _pdfView.subviews) {
467
+ if ([subview isKindOfClass:[UIScrollView class]]) {
468
+ UIScrollView *scrollView = (UIScrollView *)subview;
469
+ scrollView.showsHorizontalScrollIndicator = NO;
470
+ }
471
+ }
472
+ }
473
+ }
474
+
475
+ if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"showsVerticalScrollIndicator"])) {
476
+ if (_showsVerticalScrollIndicator) {
477
+ for (UIView *subview in _pdfView.subviews) {
478
+ if ([subview isKindOfClass:[UIScrollView class]]) {
479
+ UIScrollView *scrollView = (UIScrollView *)subview;
480
+ scrollView.showsVerticalScrollIndicator = YES;
481
+ }
482
+ }
483
+ } else {
484
+ for (UIView *subview in _pdfView.subviews) {
485
+ if ([subview isKindOfClass:[UIScrollView class]]) {
486
+ UIScrollView *scrollView = (UIScrollView *)subview;
487
+ scrollView.showsVerticalScrollIndicator = NO;
488
+ }
489
+ }
490
+ }
491
+ }
492
+
276
493
  if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"enablePaging"] || [changedProps containsObject:@"horizontal"] || [changedProps containsObject:@"page"])) {
277
494
 
278
495
  PDFPage *pdfPage = [_pdfDocument pageAtIndex:_page-1];
@@ -312,6 +529,19 @@ const float MIN_SCALE = 1.0f;
312
529
  [self didSetProps:mProps];
313
530
  }
314
531
 
532
+
533
+ - (void)notifyOnChangeWithMessage:(NSString *)message
534
+ {
535
+ #ifdef RCT_NEW_ARCH_ENABLED
536
+ if (_eventEmitter != nullptr) {
537
+ std::dynamic_pointer_cast<const RNPDFPdfViewEventEmitter>(_eventEmitter)
538
+ ->onChange(RNPDFPdfViewEventEmitter::OnChange{.message = RCTStringFromNSString(message)});
539
+ }
540
+ #else
541
+ _onChange(@{ @"message": message});
542
+ #endif
543
+ }
544
+
315
545
  - (void)dealloc{
316
546
 
317
547
  _pdfDocument = Nil;
@@ -322,6 +552,10 @@ const float MIN_SCALE = 1.0f;
322
552
  [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewPageChangedNotification" object:nil];
323
553
  [[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewScaleChangedNotification" object:nil];
324
554
 
555
+ _doubleTapRecognizer = nil;
556
+ _singleTapRecognizer = nil;
557
+ _pinchRecognizer = nil;
558
+ _longPressRecognizer = nil;
325
559
  }
326
560
 
327
561
  #pragma mark notification process
@@ -335,7 +569,8 @@ const float MIN_SCALE = 1.0f;
335
569
  CGSize pageSize = [_pdfView rowSizeForPage:page];
336
570
  NSString *jsonString = [self getTableContents];
337
571
 
338
- _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"loadComplete|%lu|%f|%f|%@", numberOfPages, pageSize.width, pageSize.height,jsonString]]});
572
+ [self notifyOnChangeWithMessage:
573
+ [[NSString alloc] initWithString:[NSString stringWithFormat:@"loadComplete|%lu|%f|%f|%@", numberOfPages, pageSize.width, pageSize.height,jsonString]]];
339
574
  }
340
575
 
341
576
  }
@@ -434,7 +669,7 @@ const float MIN_SCALE = 1.0f;
434
669
  unsigned long page = [_pdfDocument indexForPage:currentPage];
435
670
  unsigned long numberOfPages = _pdfDocument.pageCount;
436
671
 
437
- _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"pageChanged|%lu|%lu", page+1, numberOfPages]]});
672
+ [self notifyOnChangeWithMessage:[[NSString alloc] initWithString:[NSString stringWithFormat:@"pageChanged|%lu|%lu", page+1, numberOfPages]]];
438
673
  }
439
674
 
440
675
  }
@@ -445,7 +680,7 @@ const float MIN_SCALE = 1.0f;
445
680
  if (_initialed && _fixScaleFactor>0) {
446
681
  if (_scale != _pdfView.scaleFactor/_fixScaleFactor) {
447
682
  _scale = _pdfView.scaleFactor/_fixScaleFactor;
448
- _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"scaleChanged|%f", _scale]]});
683
+ [self notifyOnChangeWithMessage:[[NSString alloc] initWithString:[NSString stringWithFormat:@"scaleChanged|%f", _scale]]];
449
684
  }
450
685
  }
451
686
  }
@@ -475,17 +710,36 @@ const float MIN_SCALE = 1.0f;
475
710
 
476
711
  CGFloat newScale = scale * self->_fixScaleFactor;
477
712
  CGPoint tapPoint = [recognizer locationInView:self->_pdfView];
478
- tapPoint = [self->_pdfView convertPoint:tapPoint toPage:self->_pdfView.currentPage];
479
- CGRect zoomRect = CGRectZero;
480
- zoomRect.size.width = self->_pdfView.frame.size.width * newScale;
481
- zoomRect.size.height = self->_pdfView.frame.size.height * newScale;
482
- zoomRect.origin.x = tapPoint.x - zoomRect.size.width / 2;
483
- zoomRect.origin.y = tapPoint.y - zoomRect.size.height / 2;
713
+
714
+ PDFPage *tappedPdfPage = [_pdfView pageForPoint:tapPoint nearest:NO];
715
+ PDFPage *pageRef;
716
+ if (tappedPdfPage) {
717
+ pageRef = tappedPdfPage;
718
+ } else {
719
+ pageRef = self->_pdfView.currentPage;
720
+ }
721
+ tapPoint = [self->_pdfView convertPoint:tapPoint toPage:pageRef];
722
+
723
+ CGRect tempZoomRect = CGRectZero;
724
+ tempZoomRect.size.width = self->_pdfView.frame.size.width;
725
+ tempZoomRect.size.height = 1;
726
+ tempZoomRect.origin = tapPoint;
484
727
 
485
728
  dispatch_async(dispatch_get_main_queue(), ^{
486
729
  [UIView animateWithDuration:0.3 animations:^{
487
730
  [self->_pdfView setScaleFactor:newScale];
488
- [self->_pdfView goToRect:zoomRect onPage:self->_pdfView.currentPage];
731
+
732
+ [self->_pdfView goToRect:tempZoomRect onPage:pageRef];
733
+ CGPoint defZoomOrigin = [self->_pdfView convertPoint:tempZoomRect.origin fromPage:pageRef];
734
+ defZoomOrigin.x = defZoomOrigin.x - self->_pdfView.frame.size.width / 2;
735
+ defZoomOrigin.y = defZoomOrigin.y - self->_pdfView.frame.size.height / 2;
736
+ defZoomOrigin = [self->_pdfView convertPoint:defZoomOrigin toPage:pageRef];
737
+ CGRect defZoomRect = CGRectOffset(
738
+ tempZoomRect,
739
+ defZoomOrigin.x - tempZoomRect.origin.x,
740
+ defZoomOrigin.y - tempZoomRect.origin.y
741
+ );
742
+ [self->_pdfView goToRect:defZoomRect onPage:pageRef];
489
743
 
490
744
  [self setNeedsDisplay];
491
745
  [self onScaleChanged:Nil];
@@ -507,7 +761,8 @@ const float MIN_SCALE = 1.0f;
507
761
  PDFPage *pdfPage = [_pdfView pageForPoint:point nearest:NO];
508
762
  if (pdfPage) {
509
763
  unsigned long page = [_pdfDocument indexForPage:pdfPage];
510
- _onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"pageSingleTap|%lu|%f|%f", page+1, point.x, point.y]]});
764
+ [self notifyOnChangeWithMessage:
765
+ [[NSString alloc] initWithString:[NSString stringWithFormat:@"pageSingleTap|%lu|%f|%f", page+1, point.x, point.y]]];
511
766
  }
512
767
 
513
768
  //[self setNeedsDisplay];
@@ -550,6 +805,7 @@ const float MIN_SCALE = 1.0f;
550
805
  doubleTapRecognizer.delegate = self;
551
806
 
552
807
  [self addGestureRecognizer:doubleTapRecognizer];
808
+ _doubleTapRecognizer = doubleTapRecognizer;
553
809
 
554
810
  UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
555
811
  action:@selector(handleSingleTap:)];
@@ -559,11 +815,15 @@ const float MIN_SCALE = 1.0f;
559
815
  singleTapRecognizer.delegate = self;
560
816
 
561
817
  [self addGestureRecognizer:singleTapRecognizer];
818
+ _singleTapRecognizer = singleTapRecognizer;
819
+
562
820
  [singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer];
563
821
 
564
822
  UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self
565
823
  action:@selector(handlePinch:)];
566
824
  [self addGestureRecognizer:pinchRecognizer];
825
+ _pinchRecognizer = pinchRecognizer;
826
+
567
827
  pinchRecognizer.delegate = self;
568
828
 
569
829
  UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self
@@ -574,6 +834,7 @@ const float MIN_SCALE = 1.0f;
574
834
  longPressRecognizer.minimumPressDuration=0.3;
575
835
 
576
836
  [self addGestureRecognizer:longPressRecognizer];
837
+ _longPressRecognizer = longPressRecognizer;
577
838
 
578
839
  }
579
840
 
@@ -588,6 +849,12 @@ const float MIN_SCALE = 1.0f;
588
849
  return !_singlePage;
589
850
  }
590
851
 
852
+ @end
591
853
 
854
+ #ifdef RCT_NEW_ARCH_ENABLED
855
+ Class<RCTComponentViewProtocol> RNPDFPdfViewCls(void)
856
+ {
857
+ return RNPDFPdfView.class;
858
+ }
592
859
 
593
- @end
860
+ #endif
@@ -13,6 +13,6 @@
13
13
  #endif
14
14
 
15
15
 
16
- @interface RCTPdfViewManager : RCTViewManager
16
+ @interface RNPDFPdfViewManager : RCTViewManager
17
17
 
18
18
  @end
@@ -8,11 +8,11 @@
8
8
 
9
9
  #import <Foundation/Foundation.h>
10
10
 
11
- #import "RCTPdfViewManager.h"
12
- #import "RCTPdfView.h"
11
+ #import "RNPDFPdfViewManager.h"
12
+ #import "RNPDFPdfView.h"
13
13
 
14
14
 
15
- @implementation RCTPdfViewManager
15
+ @implementation RNPDFPdfViewManager
16
16
 
17
17
  RCT_EXPORT_MODULE()
18
18
 
@@ -20,7 +20,7 @@ RCT_EXPORT_MODULE()
20
20
  {
21
21
  if([[[UIDevice currentDevice] systemVersion] compare:@"11.0" options:NSNumericSearch] == NSOrderedDescending
22
22
  || [[[UIDevice currentDevice] systemVersion] compare:@"11.0" options:NSNumericSearch] == NSOrderedSame) {
23
- return [[RCTPdfView alloc] initWithBridge:self.bridge];
23
+ return [[RNPDFPdfView alloc] initWithBridge:self.bridge];
24
24
  } else {
25
25
  return NULL;
26
26
  }
@@ -33,6 +33,8 @@ RCT_EXPORT_VIEW_PROPERTY(scale, float);
33
33
  RCT_EXPORT_VIEW_PROPERTY(minScale, float);
34
34
  RCT_EXPORT_VIEW_PROPERTY(maxScale, float);
35
35
  RCT_EXPORT_VIEW_PROPERTY(horizontal, BOOL);
36
+ RCT_EXPORT_VIEW_PROPERTY(showsHorizontalScrollIndicator, BOOL);
37
+ RCT_EXPORT_VIEW_PROPERTY(showsVerticalScrollIndicator, BOOL);
36
38
  RCT_EXPORT_VIEW_PROPERTY(enablePaging, BOOL);
37
39
  RCT_EXPORT_VIEW_PROPERTY(enableRTL, BOOL);
38
40
  RCT_EXPORT_VIEW_PROPERTY(enableAnnotationRendering, BOOL);
@@ -61,4 +63,4 @@ RCT_EXPORT_METHOD(supportPDFKit:(RCTResponseSenderBlock)callback)
61
63
  - (void)dealloc{
62
64
  }
63
65
 
64
- @end
66
+ @end