react-native-pdf 6.2.0 → 6.4.0
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.
- package/PdfView.js +41 -13
- package/PinchZoomView.js +1 -1
- package/README.md +120 -87
- package/android/.gradle/5.6.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/5.6.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/5.6.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +2 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/android/build.gradle +10 -1
- package/android/src/main/java/org/wonday/pdf/PdfView.java +67 -9
- package/android/src/main/java/org/wonday/pdf/RCTPdfManager.java +5 -0
- package/index.d.ts +11 -3
- package/index.js +30 -40
- package/index.js.flow +6 -3
- package/ios/RCTPdf/RCTPdfView.h +3 -1
- package/ios/RCTPdf/RCTPdfView.m +124 -97
- package/ios/RCTPdf/RCTPdfViewManager.m +2 -1
- package/ios/RCTPdf.xcodeproj/xcuserdata/wonday.xcuserdatad/xcschemes/xcschememanagement.plist +14 -0
- package/package.json +21 -6
- package/react-native-pdf.podspec +1 -1
- package/windows/RCTPdf/PropertySheet.props +16 -0
- package/windows/RCTPdf/RCTPdf.def +3 -0
- package/windows/RCTPdf/RCTPdf.vcxproj +180 -0
- package/windows/RCTPdf/RCTPdf.vcxproj.filters +38 -0
- package/windows/RCTPdf/RCTPdfControl.cpp +667 -0
- package/windows/RCTPdf/RCTPdfControl.h +119 -0
- package/windows/RCTPdf/RCTPdfControl.idl +10 -0
- package/windows/RCTPdf/RCTPdfControl.xaml +34 -0
- package/windows/RCTPdf/RCTPdfViewManager.cpp +69 -0
- package/windows/RCTPdf/RCTPdfViewManager.h +51 -0
- package/windows/RCTPdf/ReactPackageProvider.cpp +15 -0
- package/windows/RCTPdf/ReactPackageProvider.h +16 -0
- package/windows/RCTPdf/ReactPackageProvider.idl +9 -0
- package/windows/RCTPdf/packages.config +4 -0
- package/windows/RCTPdf/pch.cpp +1 -0
- package/windows/RCTPdf/pch.h +29 -0
- package/windows/README.md +21 -0
- package/.babelrc +0 -3
- package/example/.eslintrc.js +0 -4
- package/example/PDFExample.js +0 -176
- package/example/android/app/BUCK +0 -55
- package/example/android/app/build.gradle +0 -210
- package/example/android/app/build_defs.bzl +0 -19
- package/example/android/app/proguard-rules.pro +0 -10
- package/example/android/app/src/debug/AndroidManifest.xml +0 -8
- package/example/android/app/src/main/AndroidManifest.xml +0 -26
- package/example/android/app/src/main/assets/test.pdf +0 -0
- package/example/android/app/src/main/java/com/pdfexample/MainActivity.java +0 -15
- package/example/android/app/src/main/java/com/pdfexample/MainApplication.java +0 -49
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png +0 -0
- package/example/android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png +0 -0
- package/example/android/app/src/main/res/values/strings.xml +0 -3
- package/example/android/app/src/main/res/values/styles.xml +0 -9
- package/example/android/build.gradle +0 -38
- package/example/android/gradle/wrapper/gradle-wrapper.jar +0 -0
- package/example/android/gradle/wrapper/gradle-wrapper.properties +0 -5
- package/example/android/gradle.properties +0 -21
- package/example/android/gradlew +0 -188
- package/example/android/gradlew.bat +0 -100
- package/example/android/settings.gradle +0 -3
- package/example/app.json +0 -4
- package/example/babel.config.js +0 -3
- package/example/index.js +0 -9
- package/example/ios/PDFExample/AppDelegate.h +0 -15
- package/example/ios/PDFExample/AppDelegate.m +0 -42
- package/example/ios/PDFExample/Base.lproj/LaunchScreen.xib +0 -42
- package/example/ios/PDFExample/Images.xcassets/AppIcon.appiconset/Contents.json +0 -38
- package/example/ios/PDFExample/Images.xcassets/Contents.json +0 -6
- package/example/ios/PDFExample/Info.plist +0 -57
- package/example/ios/PDFExample/main.m +0 -16
- package/example/ios/PDFExample-tvOS/Info.plist +0 -53
- package/example/ios/PDFExample-tvOSTests/Info.plist +0 -24
- package/example/ios/PDFExample.xcodeproj/project.pbxproj +0 -923
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample-tvOS.xcscheme +0 -129
- package/example/ios/PDFExample.xcodeproj/xcshareddata/xcschemes/PDFExample.xcscheme +0 -129
- package/example/ios/PDFExample.xcworkspace/contents.xcworkspacedata +0 -10
- package/example/ios/PDFExampleTests/Info.plist +0 -24
- package/example/ios/PDFExampleTests/PDFExampleTests.m +0 -68
- package/example/ios/Podfile +0 -47
- package/example/ios/Podfile.lock +0 -205
- package/example/metro.config.js +0 -17
- package/example/package.json +0 -42
- package/example/test.pdf +0 -0
- package/issue_template.md +0 -13
package/ios/RCTPdf/RCTPdfView.m
CHANGED
|
@@ -17,11 +17,13 @@
|
|
|
17
17
|
#import <React/RCTEventDispatcher.h>
|
|
18
18
|
#import <React/UIView+React.h>
|
|
19
19
|
#import <React/RCTLog.h>
|
|
20
|
+
#import <React/RCTBlobManager.h>
|
|
20
21
|
#else
|
|
21
22
|
#import "RCTBridgeModule.h"
|
|
22
23
|
#import "RCTEventDispatcher.h"
|
|
23
24
|
#import "UIView+React.h"
|
|
24
25
|
#import "RCTLog.h"
|
|
26
|
+
#import <RCTBlobManager.h">
|
|
25
27
|
#endif
|
|
26
28
|
|
|
27
29
|
#ifndef __OPTIMIZE__
|
|
@@ -39,6 +41,7 @@ const float MIN_SCALE = 1.0f;
|
|
|
39
41
|
|
|
40
42
|
@implementation RCTPdfView
|
|
41
43
|
{
|
|
44
|
+
RCTBridge *_bridge;
|
|
42
45
|
PDFDocument *_pdfDocument;
|
|
43
46
|
PDFView *_pdfView;
|
|
44
47
|
PDFOutline *root;
|
|
@@ -47,11 +50,12 @@ const float MIN_SCALE = 1.0f;
|
|
|
47
50
|
NSArray<NSString *> *_changedProps;
|
|
48
51
|
}
|
|
49
52
|
|
|
50
|
-
- (instancetype)
|
|
53
|
+
- (instancetype)initWithBridge:(RCTBridge *)bridge
|
|
51
54
|
{
|
|
52
55
|
self = [super init];
|
|
53
56
|
if (self) {
|
|
54
|
-
|
|
57
|
+
|
|
58
|
+
_bridge = bridge;
|
|
55
59
|
_page = 1;
|
|
56
60
|
_scale = 1;
|
|
57
61
|
_minScale = MIN_SCALE;
|
|
@@ -62,7 +66,8 @@ const float MIN_SCALE = 1.0f;
|
|
|
62
66
|
_enableAnnotationRendering = YES;
|
|
63
67
|
_fitPolicy = 2;
|
|
64
68
|
_spacing = 10;
|
|
65
|
-
|
|
69
|
+
_singlePage = NO;
|
|
70
|
+
|
|
66
71
|
// init and config PDFView
|
|
67
72
|
_pdfView = [[PDFView alloc] initWithFrame:CGRectMake(0, 0, 500, 500)];
|
|
68
73
|
_pdfView.displayMode = kPDFDisplaySinglePageContinuous;
|
|
@@ -74,23 +79,23 @@ const float MIN_SCALE = 1.0f;
|
|
|
74
79
|
_fixScaleFactor = -1.0f;
|
|
75
80
|
_initialed = NO;
|
|
76
81
|
_changedProps = NULL;
|
|
77
|
-
|
|
82
|
+
|
|
78
83
|
[self addSubview:_pdfView];
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
|
|
85
|
+
|
|
81
86
|
// register notification
|
|
82
87
|
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
|
83
88
|
[center addObserver:self selector:@selector(onDocumentChanged:) name:PDFViewDocumentChangedNotification object:_pdfView];
|
|
84
89
|
[center addObserver:self selector:@selector(onPageChanged:) name:PDFViewPageChangedNotification object:_pdfView];
|
|
85
90
|
[center addObserver:self selector:@selector(onScaleChanged:) name:PDFViewScaleChangedNotification object:_pdfView];
|
|
86
|
-
|
|
91
|
+
|
|
87
92
|
[[_pdfView document] setDelegate: self];
|
|
88
93
|
[_pdfView setDelegate: self];
|
|
89
|
-
|
|
90
|
-
|
|
94
|
+
|
|
95
|
+
|
|
91
96
|
[self bindTap];
|
|
92
97
|
}
|
|
93
|
-
|
|
98
|
+
|
|
94
99
|
return self;
|
|
95
100
|
}
|
|
96
101
|
|
|
@@ -106,43 +111,52 @@ const float MIN_SCALE = 1.0f;
|
|
|
106
111
|
- (void)didSetProps:(NSArray<NSString *> *)changedProps
|
|
107
112
|
{
|
|
108
113
|
if (!_initialed) {
|
|
109
|
-
|
|
114
|
+
|
|
110
115
|
_changedProps = changedProps;
|
|
111
|
-
|
|
116
|
+
|
|
112
117
|
} else {
|
|
113
|
-
|
|
118
|
+
|
|
114
119
|
if ([changedProps containsObject:@"path"]) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
120
|
+
|
|
121
|
+
|
|
118
122
|
if (_pdfDocument != Nil) {
|
|
119
123
|
//Release old doc
|
|
120
124
|
_pdfDocument = Nil;
|
|
121
125
|
}
|
|
122
126
|
|
|
123
|
-
|
|
124
|
-
|
|
127
|
+
if ([_path hasPrefix:@"blob:"]) {
|
|
128
|
+
RCTBlobManager *blobManager = [_bridge moduleForName:@"BlobModule"];
|
|
129
|
+
NSURL *blobURL = [NSURL URLWithString:_path];
|
|
130
|
+
NSData *blobData = [blobManager resolveURL:blobURL];
|
|
131
|
+
if (blobData != nil) {
|
|
132
|
+
_pdfDocument = [[PDFDocument alloc] initWithData:blobData];
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
NSURL *fileURL = [NSURL fileURLWithPath:_path];
|
|
136
|
+
_pdfDocument = [[PDFDocument alloc] initWithURL:fileURL];
|
|
137
|
+
}
|
|
138
|
+
|
|
125
139
|
if (_pdfDocument) {
|
|
126
|
-
|
|
140
|
+
|
|
127
141
|
//check need password or not
|
|
128
142
|
if (_pdfDocument.isLocked && ![_pdfDocument unlockWithPassword:_password]) {
|
|
129
|
-
|
|
143
|
+
|
|
130
144
|
_onChange(@{ @"message": @"error|Password required or incorrect password."});
|
|
131
|
-
|
|
145
|
+
|
|
132
146
|
_pdfDocument = Nil;
|
|
133
147
|
return;
|
|
134
148
|
}
|
|
135
|
-
|
|
149
|
+
|
|
136
150
|
_pdfView.document = _pdfDocument;
|
|
137
151
|
} else {
|
|
138
|
-
|
|
152
|
+
|
|
139
153
|
_onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"error|Load pdf failed. path=%s",_path.UTF8String]]});
|
|
140
|
-
|
|
154
|
+
|
|
141
155
|
_pdfDocument = Nil;
|
|
142
156
|
return;
|
|
143
157
|
}
|
|
144
158
|
}
|
|
145
|
-
|
|
159
|
+
|
|
146
160
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"spacing"])) {
|
|
147
161
|
if (_horizontal) {
|
|
148
162
|
_pdfView.pageBreakMargins = UIEdgeInsetsMake(0,_spacing,0,0);
|
|
@@ -168,11 +182,11 @@ const float MIN_SCALE = 1.0f;
|
|
|
168
182
|
}
|
|
169
183
|
}
|
|
170
184
|
}
|
|
171
|
-
|
|
185
|
+
|
|
172
186
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"enableRTL"])) {
|
|
173
187
|
_pdfView.displaysRTL = _enableRTL;
|
|
174
188
|
}
|
|
175
|
-
|
|
189
|
+
|
|
176
190
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"enableAnnotationRendering"])) {
|
|
177
191
|
if (!_enableAnnotationRendering) {
|
|
178
192
|
for (unsigned long i=0; i<_pdfView.document.pageCount; i++) {
|
|
@@ -183,17 +197,17 @@ const float MIN_SCALE = 1.0f;
|
|
|
183
197
|
}
|
|
184
198
|
}
|
|
185
199
|
}
|
|
186
|
-
|
|
200
|
+
|
|
187
201
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"fitPolicy"] || [changedProps containsObject:@"minScale"] || [changedProps containsObject:@"maxScale"])) {
|
|
188
|
-
|
|
202
|
+
|
|
189
203
|
PDFPage *pdfPage = [_pdfDocument pageAtIndex:_pdfDocument.pageCount-1];
|
|
190
204
|
CGRect pdfPageRect = [pdfPage boundsForBox:kPDFDisplayBoxCropBox];
|
|
191
|
-
|
|
205
|
+
|
|
192
206
|
// some pdf with rotation, then adjust it
|
|
193
207
|
if (pdfPage.rotation == 90 || pdfPage.rotation == 270) {
|
|
194
208
|
pdfPageRect = CGRectMake(0, 0, pdfPageRect.size.height, pdfPageRect.size.width);
|
|
195
209
|
}
|
|
196
|
-
|
|
210
|
+
|
|
197
211
|
if (_fitPolicy == 0) {
|
|
198
212
|
_fixScaleFactor = self.frame.size.width/pdfPageRect.size.width;
|
|
199
213
|
_pdfView.scaleFactor = _scale * _fixScaleFactor;
|
|
@@ -219,15 +233,15 @@ const float MIN_SCALE = 1.0f;
|
|
|
219
233
|
_pdfView.maxScaleFactor = _fixScaleFactor*_maxScale;
|
|
220
234
|
}
|
|
221
235
|
}
|
|
222
|
-
|
|
236
|
+
|
|
223
237
|
}
|
|
224
|
-
|
|
238
|
+
|
|
225
239
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"scale"])) {
|
|
226
240
|
_pdfView.scaleFactor = _scale * _fixScaleFactor;
|
|
227
241
|
if (_pdfView.scaleFactor>_pdfView.maxScaleFactor) _pdfView.scaleFactor = _pdfView.maxScaleFactor;
|
|
228
242
|
if (_pdfView.scaleFactor<_pdfView.minScaleFactor) _pdfView.scaleFactor = _pdfView.minScaleFactor;
|
|
229
243
|
}
|
|
230
|
-
|
|
244
|
+
|
|
231
245
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"horizontal"])) {
|
|
232
246
|
if (_horizontal) {
|
|
233
247
|
_pdfView.displayDirection = kPDFDisplayDirectionHorizontal;
|
|
@@ -237,7 +251,7 @@ const float MIN_SCALE = 1.0f;
|
|
|
237
251
|
_pdfView.pageBreakMargins = UIEdgeInsetsMake(0,0,_spacing,0);
|
|
238
252
|
}
|
|
239
253
|
}
|
|
240
|
-
|
|
254
|
+
|
|
241
255
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"enablePaging"])) {
|
|
242
256
|
if (_enablePaging) {
|
|
243
257
|
[_pdfView usePageViewController:YES withViewOptions:@{UIPageViewControllerOptionSpineLocationKey:@(UIPageViewControllerSpineLocationMin),UIPageViewControllerOptionInterPageSpacingKey:@(_spacing)}];
|
|
@@ -245,26 +259,36 @@ const float MIN_SCALE = 1.0f;
|
|
|
245
259
|
[_pdfView usePageViewController:NO withViewOptions:Nil];
|
|
246
260
|
}
|
|
247
261
|
}
|
|
248
|
-
|
|
262
|
+
|
|
263
|
+
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"singlePage"])) {
|
|
264
|
+
if (_singlePage) {
|
|
265
|
+
_pdfView.displayMode = kPDFDisplaySinglePage;
|
|
266
|
+
_pdfView.userInteractionEnabled = NO;
|
|
267
|
+
} else {
|
|
268
|
+
_pdfView.displayMode = kPDFDisplaySinglePageContinuous;
|
|
269
|
+
_pdfView.userInteractionEnabled = YES;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
249
273
|
if (_pdfDocument && ([changedProps containsObject:@"path"] || [changedProps containsObject:@"enablePaging"] || [changedProps containsObject:@"horizontal"] || [changedProps containsObject:@"page"])) {
|
|
250
|
-
|
|
274
|
+
|
|
251
275
|
PDFPage *pdfPage = [_pdfDocument pageAtIndex:_page-1];
|
|
252
276
|
if (pdfPage) {
|
|
253
277
|
CGRect pdfPageRect = [pdfPage boundsForBox:kPDFDisplayBoxCropBox];
|
|
254
|
-
|
|
278
|
+
|
|
255
279
|
// some pdf with rotation, then adjust it
|
|
256
280
|
if (pdfPage.rotation == 90 || pdfPage.rotation == 270) {
|
|
257
281
|
pdfPageRect = CGRectMake(0, 0, pdfPageRect.size.height, pdfPageRect.size.width);
|
|
258
282
|
}
|
|
259
|
-
|
|
283
|
+
|
|
260
284
|
CGPoint pointLeftTop = CGPointMake(0, pdfPageRect.size.height);
|
|
261
285
|
PDFDestination *pdfDest = [[PDFDestination alloc] initWithPage:pdfPage atPoint:pointLeftTop];
|
|
262
286
|
[_pdfView goToDestination:pdfDest];
|
|
263
287
|
_pdfView.scaleFactor = _fixScaleFactor*_scale;
|
|
264
288
|
}
|
|
265
289
|
}
|
|
266
|
-
|
|
267
|
-
|
|
290
|
+
|
|
291
|
+
_pdfView.backgroundColor = [UIColor clearColor];
|
|
268
292
|
[_pdfView layoutDocumentView];
|
|
269
293
|
[self setNeedsDisplay];
|
|
270
294
|
}
|
|
@@ -275,129 +299,133 @@ const float MIN_SCALE = 1.0f;
|
|
|
275
299
|
{
|
|
276
300
|
[super reactSetFrame:frame];
|
|
277
301
|
_pdfView.frame = CGRectMake(0, 0, frame.size.width, frame.size.height);
|
|
278
|
-
|
|
302
|
+
|
|
303
|
+
NSMutableArray *mProps = [_changedProps mutableCopy];
|
|
304
|
+
if (_initialed) {
|
|
305
|
+
[mProps removeObject:@"path"];
|
|
306
|
+
}
|
|
279
307
|
_initialed = YES;
|
|
280
|
-
|
|
281
|
-
[self didSetProps:
|
|
308
|
+
|
|
309
|
+
[self didSetProps:mProps];
|
|
282
310
|
}
|
|
283
311
|
|
|
284
312
|
- (void)dealloc{
|
|
285
|
-
|
|
313
|
+
|
|
286
314
|
_pdfDocument = Nil;
|
|
287
315
|
_pdfView = Nil;
|
|
288
|
-
|
|
316
|
+
|
|
289
317
|
//Remove notifications
|
|
290
318
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewDocumentChangedNotification" object:nil];
|
|
291
319
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewPageChangedNotification" object:nil];
|
|
292
320
|
[[NSNotificationCenter defaultCenter] removeObserver:self name:@"PDFViewScaleChangedNotification" object:nil];
|
|
293
|
-
|
|
321
|
+
|
|
294
322
|
}
|
|
295
323
|
|
|
296
324
|
#pragma mark notification process
|
|
297
325
|
- (void)onDocumentChanged:(NSNotification *)noti
|
|
298
326
|
{
|
|
299
|
-
|
|
327
|
+
|
|
300
328
|
if (_pdfDocument) {
|
|
301
|
-
|
|
329
|
+
|
|
302
330
|
unsigned long numberOfPages = _pdfDocument.pageCount;
|
|
303
331
|
PDFPage *page = [_pdfDocument pageAtIndex:_pdfDocument.pageCount-1];
|
|
304
332
|
CGSize pageSize = [_pdfView rowSizeForPage:page];
|
|
305
333
|
NSString *jsonString = [self getTableContents];
|
|
306
|
-
|
|
334
|
+
|
|
307
335
|
_onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"loadComplete|%lu|%f|%f|%@", numberOfPages, pageSize.width, pageSize.height,jsonString]]});
|
|
308
336
|
}
|
|
309
|
-
|
|
337
|
+
|
|
310
338
|
}
|
|
311
339
|
|
|
312
340
|
-(NSString *) getTableContents
|
|
313
341
|
{
|
|
314
|
-
|
|
342
|
+
|
|
315
343
|
NSMutableArray<PDFOutline *> *arrTableOfContents = [[NSMutableArray alloc] init];
|
|
316
|
-
|
|
344
|
+
|
|
317
345
|
if (_pdfDocument.outlineRoot) {
|
|
318
|
-
|
|
346
|
+
|
|
319
347
|
PDFOutline *currentRoot = _pdfDocument.outlineRoot;
|
|
320
348
|
NSMutableArray<PDFOutline *> *stack = [[NSMutableArray alloc] init];
|
|
321
|
-
|
|
349
|
+
|
|
322
350
|
[stack addObject:currentRoot];
|
|
323
|
-
|
|
351
|
+
|
|
324
352
|
while (stack.count > 0) {
|
|
325
|
-
|
|
353
|
+
|
|
326
354
|
PDFOutline *currentOutline = stack.lastObject;
|
|
327
355
|
[stack removeLastObject];
|
|
328
|
-
|
|
356
|
+
|
|
329
357
|
if (currentOutline.label.length > 0){
|
|
330
358
|
[arrTableOfContents addObject:currentOutline];
|
|
331
359
|
}
|
|
332
|
-
|
|
360
|
+
|
|
333
361
|
for ( NSInteger i= currentOutline.numberOfChildren; i > 0; i-- )
|
|
334
362
|
{
|
|
335
363
|
[stack addObject:[currentOutline childAtIndex:i-1]];
|
|
336
364
|
}
|
|
337
365
|
}
|
|
338
366
|
}
|
|
339
|
-
|
|
367
|
+
|
|
340
368
|
NSMutableArray *arrParentsContents = [[NSMutableArray alloc] init];
|
|
341
|
-
|
|
369
|
+
|
|
342
370
|
for ( NSInteger i= 0; i < arrTableOfContents.count; i++ )
|
|
343
371
|
{
|
|
344
372
|
PDFOutline *currentOutline = [arrTableOfContents objectAtIndex:i];
|
|
345
|
-
|
|
373
|
+
|
|
346
374
|
NSInteger indentationLevel = -1;
|
|
347
|
-
|
|
375
|
+
|
|
348
376
|
PDFOutline *parentOutline = currentOutline.parent;
|
|
349
|
-
|
|
377
|
+
|
|
350
378
|
while (parentOutline != nil) {
|
|
351
379
|
indentationLevel += 1;
|
|
352
380
|
parentOutline = parentOutline.parent;
|
|
353
381
|
}
|
|
354
|
-
|
|
382
|
+
|
|
355
383
|
if (indentationLevel == 0) {
|
|
356
|
-
|
|
384
|
+
|
|
357
385
|
NSMutableDictionary *DXParentsContent = [[NSMutableDictionary alloc] init];
|
|
358
|
-
|
|
386
|
+
|
|
359
387
|
[DXParentsContent setObject:[[NSMutableArray alloc] init] forKey:@"children"];
|
|
360
388
|
[DXParentsContent setObject:@"" forKey:@"mNativePtr"];
|
|
361
389
|
[DXParentsContent setObject:[NSString stringWithFormat:@"%lu", [_pdfDocument indexForPage:currentOutline.destination.page]] forKey:@"pageIdx"];
|
|
362
390
|
[DXParentsContent setObject:currentOutline.label forKey:@"title"];
|
|
363
|
-
|
|
391
|
+
|
|
364
392
|
//currentOutlin
|
|
365
393
|
//mNativePtr
|
|
366
394
|
[arrParentsContents addObject:DXParentsContent];
|
|
367
395
|
}
|
|
368
396
|
else {
|
|
369
397
|
NSMutableDictionary *DXParentsContent = [arrParentsContents lastObject];
|
|
370
|
-
|
|
398
|
+
|
|
371
399
|
NSMutableArray *arrChildren = [DXParentsContent valueForKey:@"children"];
|
|
372
|
-
|
|
400
|
+
|
|
373
401
|
while (indentationLevel > 1) {
|
|
374
402
|
NSMutableDictionary *DXchild = [arrChildren lastObject];
|
|
375
403
|
arrChildren = [DXchild valueForKey:@"children"];
|
|
376
404
|
indentationLevel--;
|
|
377
405
|
}
|
|
378
|
-
|
|
406
|
+
|
|
379
407
|
NSMutableDictionary *DXChildContent = [[NSMutableDictionary alloc] init];
|
|
380
408
|
[DXChildContent setObject:[[NSMutableArray alloc] init] forKey:@"children"];
|
|
381
409
|
[DXChildContent setObject:@"" forKey:@"mNativePtr"];
|
|
382
410
|
[DXChildContent setObject:[NSString stringWithFormat:@"%lu", [_pdfDocument indexForPage:currentOutline.destination.page]] forKey:@"pageIdx"];
|
|
383
411
|
[DXChildContent setObject:currentOutline.label forKey:@"title"];
|
|
384
412
|
[arrChildren addObject:DXChildContent];
|
|
385
|
-
|
|
413
|
+
|
|
386
414
|
}
|
|
387
415
|
}
|
|
388
|
-
|
|
416
|
+
|
|
389
417
|
NSError *error;
|
|
390
418
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:arrParentsContents options:NSJSONWritingPrettyPrinted error:&error];
|
|
391
|
-
|
|
419
|
+
|
|
392
420
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
|
393
|
-
|
|
421
|
+
|
|
394
422
|
return jsonString;
|
|
395
|
-
|
|
423
|
+
|
|
396
424
|
}
|
|
397
425
|
|
|
398
426
|
- (void)onPageChanged:(NSNotification *)noti
|
|
399
427
|
{
|
|
400
|
-
|
|
428
|
+
|
|
401
429
|
if (_pdfDocument) {
|
|
402
430
|
PDFPage *currentPage = _pdfView.currentPage;
|
|
403
431
|
unsigned long page = [_pdfDocument indexForPage:currentPage];
|
|
@@ -405,12 +433,12 @@ const float MIN_SCALE = 1.0f;
|
|
|
405
433
|
|
|
406
434
|
_onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"pageChanged|%lu|%lu", page+1, numberOfPages]]});
|
|
407
435
|
}
|
|
408
|
-
|
|
436
|
+
|
|
409
437
|
}
|
|
410
438
|
|
|
411
439
|
- (void)onScaleChanged:(NSNotification *)noti
|
|
412
440
|
{
|
|
413
|
-
|
|
441
|
+
|
|
414
442
|
if (_initialed && _fixScaleFactor>0) {
|
|
415
443
|
if (_scale != _pdfView.scaleFactor/_fixScaleFactor) {
|
|
416
444
|
_scale = _pdfView.scaleFactor/_fixScaleFactor;
|
|
@@ -441,7 +469,7 @@ const float MIN_SCALE = 1.0f;
|
|
|
441
469
|
} else {
|
|
442
470
|
scale = min;
|
|
443
471
|
}
|
|
444
|
-
|
|
472
|
+
|
|
445
473
|
CGFloat newScale = scale * self->_fixScaleFactor;
|
|
446
474
|
CGPoint tapPoint = [recognizer locationInView:self->_pdfView];
|
|
447
475
|
tapPoint = [self->_pdfView convertPoint:tapPoint toPage:self->_pdfView.currentPage];
|
|
@@ -450,12 +478,12 @@ const float MIN_SCALE = 1.0f;
|
|
|
450
478
|
zoomRect.size.height = self->_pdfView.frame.size.height * newScale;
|
|
451
479
|
zoomRect.origin.x = tapPoint.x - zoomRect.size.width / 2;
|
|
452
480
|
zoomRect.origin.y = tapPoint.y - zoomRect.size.height / 2;
|
|
453
|
-
|
|
481
|
+
|
|
454
482
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
455
483
|
[UIView animateWithDuration:0.3 animations:^{
|
|
456
484
|
[self->_pdfView setScaleFactor:newScale];
|
|
457
485
|
[self->_pdfView goToRect:zoomRect onPage:self->_pdfView.currentPage];
|
|
458
|
-
|
|
486
|
+
|
|
459
487
|
[self setNeedsDisplay];
|
|
460
488
|
[self onScaleChanged:Nil];
|
|
461
489
|
}];
|
|
@@ -470,20 +498,19 @@ const float MIN_SCALE = 1.0f;
|
|
|
470
498
|
*/
|
|
471
499
|
- (void)handleSingleTap:(UITapGestureRecognizer *)sender
|
|
472
500
|
{
|
|
473
|
-
|
|
474
501
|
//_pdfView.scaleFactor = _pdfView.minScaleFactor;
|
|
475
|
-
|
|
502
|
+
|
|
476
503
|
CGPoint point = [sender locationInView:self];
|
|
477
504
|
PDFPage *pdfPage = [_pdfView pageForPoint:point nearest:NO];
|
|
478
505
|
if (pdfPage) {
|
|
479
506
|
unsigned long page = [_pdfDocument indexForPage:pdfPage];
|
|
480
507
|
_onChange(@{ @"message": [[NSString alloc] initWithString:[NSString stringWithFormat:@"pageSingleTap|%lu|%f|%f", page+1, point.x, point.y]]});
|
|
481
508
|
}
|
|
482
|
-
|
|
509
|
+
|
|
483
510
|
//[self setNeedsDisplay];
|
|
484
511
|
//[self onScaleChanged:Nil];
|
|
485
|
-
|
|
486
|
-
|
|
512
|
+
|
|
513
|
+
|
|
487
514
|
}
|
|
488
515
|
|
|
489
516
|
/**
|
|
@@ -502,7 +529,7 @@ const float MIN_SCALE = 1.0f;
|
|
|
502
529
|
*
|
|
503
530
|
*/
|
|
504
531
|
- (void)handleLongPress:(UILongPressGestureRecognizer *)sender{
|
|
505
|
-
|
|
532
|
+
|
|
506
533
|
}
|
|
507
534
|
|
|
508
535
|
/**
|
|
@@ -518,44 +545,44 @@ const float MIN_SCALE = 1.0f;
|
|
|
518
545
|
doubleTapRecognizer.numberOfTapsRequired = 2;
|
|
519
546
|
doubleTapRecognizer.numberOfTouchesRequired = 1;
|
|
520
547
|
doubleTapRecognizer.delegate = self;
|
|
521
|
-
|
|
548
|
+
|
|
522
549
|
[self addGestureRecognizer:doubleTapRecognizer];
|
|
523
|
-
|
|
550
|
+
|
|
524
551
|
UITapGestureRecognizer *singleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self
|
|
525
552
|
action:@selector(handleSingleTap:)];
|
|
526
553
|
//trigger by one finger and one touch
|
|
527
554
|
singleTapRecognizer.numberOfTapsRequired = 1;
|
|
528
555
|
singleTapRecognizer.numberOfTouchesRequired = 1;
|
|
529
556
|
singleTapRecognizer.delegate = self;
|
|
530
|
-
|
|
557
|
+
|
|
531
558
|
[self addGestureRecognizer:singleTapRecognizer];
|
|
532
559
|
[singleTapRecognizer requireGestureRecognizerToFail:doubleTapRecognizer];
|
|
533
|
-
|
|
560
|
+
|
|
534
561
|
UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self
|
|
535
562
|
action:@selector(handlePinch:)];
|
|
536
563
|
[self addGestureRecognizer:pinchRecognizer];
|
|
537
564
|
pinchRecognizer.delegate = self;
|
|
538
|
-
|
|
565
|
+
|
|
539
566
|
UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self
|
|
540
567
|
action:@selector(handleLongPress:)];
|
|
541
568
|
// Making sure the allowable movement isn not too narrow
|
|
542
569
|
longPressRecognizer.allowableMovement=100;
|
|
543
570
|
// Important: The duration must be long enough to allow taps but not longer than the period in which view opens the magnifying glass
|
|
544
571
|
longPressRecognizer.minimumPressDuration=0.3;
|
|
545
|
-
|
|
572
|
+
|
|
546
573
|
[self addGestureRecognizer:longPressRecognizer];
|
|
547
|
-
|
|
574
|
+
|
|
548
575
|
}
|
|
549
576
|
|
|
550
577
|
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
|
|
551
578
|
|
|
552
579
|
{
|
|
553
|
-
return
|
|
580
|
+
return !_singlePage;
|
|
554
581
|
}
|
|
555
582
|
|
|
556
583
|
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
|
|
557
584
|
{
|
|
558
|
-
return
|
|
585
|
+
return !_singlePage;
|
|
559
586
|
}
|
|
560
587
|
|
|
561
588
|
|
|
@@ -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]
|
|
23
|
+
return [[RCTPdfView alloc] initWithBridge:self.bridge];
|
|
24
24
|
} else {
|
|
25
25
|
return NULL;
|
|
26
26
|
}
|
|
@@ -40,6 +40,7 @@ RCT_EXPORT_VIEW_PROPERTY(fitPolicy, int);
|
|
|
40
40
|
RCT_EXPORT_VIEW_PROPERTY(spacing, int);
|
|
41
41
|
RCT_EXPORT_VIEW_PROPERTY(password, NSString);
|
|
42
42
|
RCT_EXPORT_VIEW_PROPERTY(onChange, RCTBubblingEventBlock);
|
|
43
|
+
RCT_EXPORT_VIEW_PROPERTY(singlePage, BOOL);
|
|
43
44
|
|
|
44
45
|
RCT_EXPORT_METHOD(supportPDFKit:(RCTResponseSenderBlock)callback)
|
|
45
46
|
{
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
|
3
|
+
<plist version="1.0">
|
|
4
|
+
<dict>
|
|
5
|
+
<key>SchemeUserState</key>
|
|
6
|
+
<dict>
|
|
7
|
+
<key>RCTPdf.xcscheme_^#shared#^_</key>
|
|
8
|
+
<dict>
|
|
9
|
+
<key>orderHint</key>
|
|
10
|
+
<integer>52</integer>
|
|
11
|
+
</dict>
|
|
12
|
+
</dict>
|
|
13
|
+
</dict>
|
|
14
|
+
</plist>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-pdf",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.4.0",
|
|
4
4
|
"summary": "A react native PDF view component",
|
|
5
5
|
"description": "A react native PDF view component, support ios and android platform",
|
|
6
6
|
"main": "index.js",
|
|
@@ -28,9 +28,24 @@
|
|
|
28
28
|
"url": "https://github.com/wonday/react-native-pdf/issues"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"crypto-js": "^3.2.0"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
"
|
|
35
|
-
}
|
|
31
|
+
"crypto-js": "^3.2.0"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"prop-types": "^15.7.2"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"android/",
|
|
38
|
+
"ios/",
|
|
39
|
+
"windows/",
|
|
40
|
+
"DoubleTapView.js",
|
|
41
|
+
"index.d.ts",
|
|
42
|
+
"index.js",
|
|
43
|
+
"index.js.flow",
|
|
44
|
+
"PdfManager.js",
|
|
45
|
+
"PdfPageView.js",
|
|
46
|
+
"PdfView.js",
|
|
47
|
+
"PdfViewFlatList.js",
|
|
48
|
+
"PinchZoomView.js",
|
|
49
|
+
"react-native-pdf.podspec"
|
|
50
|
+
]
|
|
36
51
|
}
|
package/react-native-pdf.podspec
CHANGED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
|
3
|
+
<ImportGroup Label="PropertySheets" />
|
|
4
|
+
<PropertyGroup Label="UserMacros" />
|
|
5
|
+
<!--
|
|
6
|
+
To customize common C++/WinRT project properties:
|
|
7
|
+
* right-click the project node
|
|
8
|
+
* expand the Common Properties item
|
|
9
|
+
* select the C++/WinRT property page
|
|
10
|
+
|
|
11
|
+
For more advanced scenarios, and complete documentation, please see:
|
|
12
|
+
https://github.com/Microsoft/xlang/tree/master/src/package/cppwinrt/nuget
|
|
13
|
+
-->
|
|
14
|
+
<PropertyGroup />
|
|
15
|
+
<ItemDefinitionGroup />
|
|
16
|
+
</Project>
|