@papyrus-sdk/engine-native 0.2.22-beta.6 → 0.2.22-beta.8
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/android/src/main/java/com/papyrus/engine/PapyrusComicDocumentView.java +164 -26
- package/android/src/main/java/com/papyrus/engine/PapyrusComicPageLayout.java +21 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusNativeEngineModule.java +12 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerView.java +195 -5
- package/android/src/main/java/com/papyrus/engine/PapyrusPdfViewerViewManager.java +20 -1
- package/android/src/main/java/com/papyrus/engine/PapyrusSelectionMenuIcon.java +48 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextAnnotationModel.java +22 -0
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentView.java +239 -17
- package/android/src/main/java/com/papyrus/engine/PapyrusTextDocumentViewManager.java +6 -0
- package/dist/index.d.mts +137 -1
- package/dist/index.d.ts +137 -1
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -0
- package/dist/index.mjs.map +1 -1
- package/ios/PapyrusComicDocumentView.m +200 -27
- package/ios/PapyrusNativeEngine.m +12 -0
- package/ios/PapyrusPdfDocumentView.h +5 -0
- package/ios/PapyrusPdfDocumentView.m +96 -11
- package/ios/PapyrusPdfDocumentViewManager.m +3 -0
- package/ios/PapyrusSelectionMenu.h +27 -0
- package/ios/PapyrusTextAnnotationRange.h +2 -0
- package/ios/PapyrusTextAnnotationRange.m +29 -0
- package/ios/PapyrusTextDocumentView.h +5 -0
- package/ios/PapyrusTextDocumentView.m +233 -14
- package/ios/PapyrusTextDocumentViewManager.m +5 -0
- package/package.json +3 -3
|
@@ -51,9 +51,16 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
51
51
|
@property (nonatomic, strong) UICollectionView *collectionView;
|
|
52
52
|
@property (nonatomic, strong) UICollectionViewFlowLayout *flowLayout;
|
|
53
53
|
@property (nonatomic, strong) UIPinchGestureRecognizer *pinchRecognizer;
|
|
54
|
+
@property (nonatomic, strong) UITapGestureRecognizer *doubleTapRecognizer;
|
|
54
55
|
@property (nonatomic, strong) UIPanGestureRecognizer *pagePanRecognizer;
|
|
55
56
|
@property (nonatomic, assign) BOOL applyingProgrammaticPage;
|
|
56
57
|
@property (nonatomic, strong) NSMutableSet<NSString *> *reportedErrors;
|
|
58
|
+
@property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSValue *> *pageSizes;
|
|
59
|
+
@property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSValue *> *pendingPageSizes;
|
|
60
|
+
@property (nonatomic, assign) BOOL pendingViewportLayout;
|
|
61
|
+
@property (nonatomic, assign) CGSize viewportSize;
|
|
62
|
+
@property (nonatomic, assign) NSInteger requestedPage;
|
|
63
|
+
@property (nonatomic, assign) BOOL pendingNavigation;
|
|
57
64
|
@property (nonatomic, assign) CGPoint panOffset;
|
|
58
65
|
@property (nonatomic, assign) CGPoint panGestureStartOffset;
|
|
59
66
|
@end
|
|
@@ -65,6 +72,10 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
65
72
|
if (self) {
|
|
66
73
|
_pageCount = 0;
|
|
67
74
|
_currentPage = 1;
|
|
75
|
+
_requestedPage = 1;
|
|
76
|
+
_pendingNavigation = YES;
|
|
77
|
+
_pageSizes = [NSMutableDictionary dictionary];
|
|
78
|
+
_pendingPageSizes = [NSMutableDictionary dictionary];
|
|
68
79
|
_layoutMode = @"single";
|
|
69
80
|
_fitMode = @"width";
|
|
70
81
|
_readingDirection = @"ltr";
|
|
@@ -88,6 +99,12 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
88
99
|
_pinchRecognizer.cancelsTouchesInView = NO;
|
|
89
100
|
_pinchRecognizer.delegate = self;
|
|
90
101
|
[_collectionView addGestureRecognizer:_pinchRecognizer];
|
|
102
|
+
_doubleTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleDoubleTap:)];
|
|
103
|
+
_doubleTapRecognizer.numberOfTapsRequired = 2;
|
|
104
|
+
_doubleTapRecognizer.numberOfTouchesRequired = 1;
|
|
105
|
+
_doubleTapRecognizer.cancelsTouchesInView = YES;
|
|
106
|
+
_doubleTapRecognizer.delegate = self;
|
|
107
|
+
[_collectionView addGestureRecognizer:_doubleTapRecognizer];
|
|
91
108
|
_pagePanRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePagePan:)];
|
|
92
109
|
_pagePanRecognizer.minimumNumberOfTouches = 1;
|
|
93
110
|
_pagePanRecognizer.maximumNumberOfTouches = 1;
|
|
@@ -100,56 +117,148 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
100
117
|
return self;
|
|
101
118
|
}
|
|
102
119
|
|
|
120
|
+
// Anchors reference the page, not an absolute document offset. Heights can change
|
|
121
|
+
// above the viewport as images arrive; bitmap eviction must not change geometry.
|
|
122
|
+
- (NSDictionary *)captureScrollAnchorForViewport:(CGSize)viewport {
|
|
123
|
+
if (self.pendingNavigation || viewport.width <= 0 || viewport.height <= 0) return nil;
|
|
124
|
+
CGPoint center = CGPointMake(self.collectionView.contentOffset.x + viewport.width / 2,
|
|
125
|
+
self.collectionView.contentOffset.y + viewport.height / 2);
|
|
126
|
+
UICollectionViewLayoutAttributes *nearest = nil;
|
|
127
|
+
CGFloat distance = CGFLOAT_MAX;
|
|
128
|
+
for (NSIndexPath *path in self.collectionView.indexPathsForVisibleItems) {
|
|
129
|
+
UICollectionViewLayoutAttributes *attributes = [self.flowLayout layoutAttributesForItemAtIndexPath:path];
|
|
130
|
+
if (!attributes) continue;
|
|
131
|
+
CGFloat next = ABS(CGRectGetMidY(attributes.frame) - center.y);
|
|
132
|
+
if (next < distance) { nearest = attributes; distance = next; }
|
|
133
|
+
if (CGRectContainsPoint(attributes.frame, center)) { nearest = attributes; break; }
|
|
134
|
+
}
|
|
135
|
+
if (!nearest || nearest.frame.size.height <= 0) return nil;
|
|
136
|
+
return @{ @"pageIndex": @([self logicalPageForItem:nearest.indexPath.item]),
|
|
137
|
+
@"fraction": @(MAX(0, MIN(1, (center.y - nearest.frame.origin.y) / nearest.frame.size.height))) };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
- (void)restoreScrollAnchor:(NSDictionary *)anchor {
|
|
141
|
+
if (self.collectionView.dragging || self.collectionView.decelerating) return;
|
|
142
|
+
if (!anchor || self.pendingNavigation || ![self.layoutMode isEqualToString:@"continuous"]) return;
|
|
143
|
+
NSInteger page = [anchor[@"pageIndex"] integerValue];
|
|
144
|
+
if (page < 0 || page >= self.pageCount) return;
|
|
145
|
+
NSInteger item = [self itemForLogicalPage:page + 1];
|
|
146
|
+
UICollectionViewLayoutAttributes *attributes = [self.flowLayout layoutAttributesForItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:0]];
|
|
147
|
+
if (!attributes) return;
|
|
148
|
+
CGFloat y = attributes.frame.origin.y + [anchor[@"fraction"] doubleValue] * attributes.frame.size.height - self.collectionView.bounds.size.height / 2;
|
|
149
|
+
CGFloat minimum = -self.collectionView.adjustedContentInset.top;
|
|
150
|
+
CGFloat maximum = MAX(minimum, self.collectionView.contentSize.height - self.collectionView.bounds.size.height + self.collectionView.adjustedContentInset.bottom);
|
|
151
|
+
BOOL wasApplying = self.applyingProgrammaticPage;
|
|
152
|
+
self.applyingProgrammaticPage = YES;
|
|
153
|
+
[self.collectionView setContentOffset:CGPointMake(self.collectionView.contentOffset.x, MAX(minimum, MIN(maximum, y))) animated:NO];
|
|
154
|
+
self.applyingProgrammaticPage = wasApplying;
|
|
155
|
+
}
|
|
156
|
+
|
|
103
157
|
- (void)layoutSubviews {
|
|
158
|
+
NSDictionary *anchor = [self captureScrollAnchorForViewport:self.viewportSize];
|
|
104
159
|
[super layoutSubviews];
|
|
105
|
-
|
|
160
|
+
CGSize size = self.collectionView.bounds.size;
|
|
161
|
+
if (CGSizeEqualToSize(size, self.viewportSize)) {
|
|
162
|
+
if (self.pendingNavigation) [self scrollToCurrentPageAnimated:NO];
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
if (self.collectionView.dragging || self.collectionView.decelerating) {
|
|
166
|
+
self.pendingViewportLayout = YES;
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
self.pendingViewportLayout = NO;
|
|
170
|
+
BOOL wasApplying = self.applyingProgrammaticPage;
|
|
171
|
+
self.applyingProgrammaticPage = YES;
|
|
172
|
+
self.viewportSize = size;
|
|
173
|
+
self.flowLayout.itemSize = size;
|
|
106
174
|
[self.flowLayout invalidateLayout];
|
|
175
|
+
[self.collectionView layoutIfNeeded];
|
|
107
176
|
for (PapyrusComicPageCell *cell in self.collectionView.visibleCells) {
|
|
108
177
|
[self configureCell:cell withImage:cell.imageView.image];
|
|
109
178
|
cell.imageView.transform = [self imageTransform];
|
|
110
179
|
}
|
|
111
|
-
[self
|
|
180
|
+
if (self.pendingNavigation || ![self.layoutMode isEqualToString:@"continuous"]) {
|
|
181
|
+
[self scrollToCurrentPageAnimated:NO];
|
|
182
|
+
} else {
|
|
183
|
+
[self restoreScrollAnchor:anchor];
|
|
184
|
+
}
|
|
185
|
+
self.applyingProgrammaticPage = wasApplying;
|
|
112
186
|
}
|
|
113
187
|
|
|
114
188
|
- (void)setEngineId:(NSString *)engineId {
|
|
115
189
|
if ([_engineId isEqualToString:engineId]) return;
|
|
116
190
|
_engineId = [engineId copy];
|
|
191
|
+
[self.pageSizes removeAllObjects];
|
|
192
|
+
[self.pendingPageSizes removeAllObjects];
|
|
193
|
+
@synchronized (self.reportedErrors) { [self.reportedErrors removeAllObjects]; }
|
|
194
|
+
self.pendingNavigation = YES;
|
|
117
195
|
[self.collectionView reloadData];
|
|
196
|
+
[self scrollToCurrentPageAnimated:NO];
|
|
118
197
|
}
|
|
119
198
|
- (void)setDocumentGeneration:(NSInteger)value {
|
|
120
199
|
if (_documentGeneration == value) return;
|
|
121
200
|
_documentGeneration = value;
|
|
201
|
+
[self.pageSizes removeAllObjects];
|
|
202
|
+
[self.pendingPageSizes removeAllObjects];
|
|
203
|
+
@synchronized (self.reportedErrors) { [self.reportedErrors removeAllObjects]; }
|
|
204
|
+
self.pendingNavigation = YES;
|
|
122
205
|
[self.collectionView reloadData];
|
|
206
|
+
[self scrollToCurrentPageAnimated:NO];
|
|
123
207
|
}
|
|
124
208
|
- (void)setPageCount:(NSInteger)value {
|
|
125
|
-
|
|
126
|
-
|
|
209
|
+
NSInteger count = MAX(0, value);
|
|
210
|
+
if (_pageCount == count) return;
|
|
211
|
+
_pageCount = count;
|
|
212
|
+
_currentPage = count > 0 ? MIN(self.requestedPage, count) : self.requestedPage;
|
|
213
|
+
self.pendingNavigation = YES;
|
|
127
214
|
[self.collectionView reloadData];
|
|
128
215
|
[self scrollToCurrentPageAnimated:NO];
|
|
129
216
|
}
|
|
130
217
|
- (void)setCurrentPage:(NSInteger)value {
|
|
131
|
-
NSInteger
|
|
132
|
-
|
|
218
|
+
NSInteger requested = MAX(value, 1);
|
|
219
|
+
NSInteger safe = self.pageCount > 0 ? MIN(requested, self.pageCount) : requested;
|
|
220
|
+
if (_currentPage == safe && self.requestedPage == requested) return;
|
|
221
|
+
self.requestedPage = requested;
|
|
133
222
|
_currentPage = safe;
|
|
223
|
+
self.pendingNavigation = YES;
|
|
134
224
|
[self scrollToCurrentPageAnimated:NO];
|
|
135
225
|
}
|
|
136
226
|
- (void)setLayoutMode:(NSString *)value {
|
|
137
|
-
|
|
138
|
-
|
|
227
|
+
NSString *mode = [value isEqualToString:@"continuous"] ? @"continuous" : @"single";
|
|
228
|
+
if ([_layoutMode isEqualToString:mode]) return;
|
|
229
|
+
_layoutMode = mode;
|
|
139
230
|
[self applyLayoutMode];
|
|
231
|
+
self.pendingNavigation = YES;
|
|
140
232
|
[self.collectionView reloadData];
|
|
233
|
+
[self scrollToCurrentPageAnimated:NO];
|
|
141
234
|
}
|
|
142
235
|
- (void)setFitMode:(NSString *)value {
|
|
143
|
-
|
|
144
|
-
|
|
236
|
+
NSString *mode = [value isEqualToString:@"page"] ? @"page" : @"width";
|
|
237
|
+
if ([_fitMode isEqualToString:mode]) return;
|
|
238
|
+
BOOL wasApplying = self.applyingProgrammaticPage;
|
|
239
|
+
self.applyingProgrammaticPage = YES;
|
|
240
|
+
NSDictionary *anchor = [self captureScrollAnchorForViewport:self.collectionView.bounds.size];
|
|
241
|
+
_fitMode = mode;
|
|
145
242
|
[self.flowLayout invalidateLayout];
|
|
146
243
|
[self.collectionView reloadData];
|
|
244
|
+
[self.collectionView layoutIfNeeded];
|
|
245
|
+
if ([self.layoutMode isEqualToString:@"continuous"]) [self restoreScrollAnchor:anchor];
|
|
246
|
+
else [self scrollToCurrentPageAnimated:NO];
|
|
247
|
+
self.applyingProgrammaticPage = wasApplying;
|
|
147
248
|
}
|
|
148
249
|
- (void)setReadingDirection:(NSString *)value {
|
|
149
|
-
|
|
250
|
+
NSString *direction = [value isEqualToString:@"rtl"] ? @"rtl" : @"ltr";
|
|
251
|
+
if ([_readingDirection isEqualToString:direction]) return;
|
|
252
|
+
BOOL wasApplying = self.applyingProgrammaticPage;
|
|
253
|
+
self.applyingProgrammaticPage = YES;
|
|
254
|
+
NSDictionary *anchor = [self captureScrollAnchorForViewport:self.collectionView.bounds.size];
|
|
255
|
+
_readingDirection = direction;
|
|
150
256
|
[self applyLayoutMode];
|
|
151
257
|
[self.collectionView reloadData];
|
|
152
|
-
[self
|
|
258
|
+
[self.collectionView layoutIfNeeded];
|
|
259
|
+
if ([self.layoutMode isEqualToString:@"continuous"]) [self restoreScrollAnchor:anchor];
|
|
260
|
+
else [self scrollToCurrentPageAnimated:NO];
|
|
261
|
+
self.applyingProgrammaticPage = wasApplying;
|
|
153
262
|
}
|
|
154
263
|
- (void)setZoom:(CGFloat)value {
|
|
155
264
|
_zoom = MAX(1, MIN(5, value));
|
|
@@ -176,7 +285,6 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
176
285
|
self.collectionView.pagingEnabled = !continuous;
|
|
177
286
|
self.collectionView.semanticContentAttribute = [self.readingDirection isEqualToString:@"rtl"] ? UISemanticContentAttributeForceRightToLeft : UISemanticContentAttributeForceLeftToRight;
|
|
178
287
|
[self.flowLayout invalidateLayout];
|
|
179
|
-
[self scrollToCurrentPageAnimated:NO];
|
|
180
288
|
}
|
|
181
289
|
|
|
182
290
|
- (void)applyTheme {
|
|
@@ -223,7 +331,10 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
223
331
|
}
|
|
224
332
|
- (void)scrollToCurrentPageAnimated:(BOOL)animated {
|
|
225
333
|
if (self.pageCount <= 0 || self.collectionView.bounds.size.width <= 0) return;
|
|
334
|
+
[self.collectionView layoutIfNeeded];
|
|
226
335
|
NSInteger item = [self itemForLogicalPage:self.currentPage];
|
|
336
|
+
if (item >= [self.collectionView numberOfItemsInSection:0]) return;
|
|
337
|
+
self.pendingNavigation = NO;
|
|
227
338
|
self.applyingProgrammaticPage = YES;
|
|
228
339
|
[self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForItem:item inSection:0]
|
|
229
340
|
atScrollPosition:[self.layoutMode isEqualToString:@"continuous"] ? UICollectionViewScrollPositionTop : UICollectionViewScrollPositionCenteredHorizontally
|
|
@@ -286,11 +397,13 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
286
397
|
CGImageRelease(image);
|
|
287
398
|
[PapyrusComicImageCache() setObject:page forKey:key cost:cost];
|
|
288
399
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
289
|
-
if ([
|
|
400
|
+
if (![self.engineId isEqualToString:engineId] || self.documentGeneration != generation) return;
|
|
401
|
+
self.pendingPageSizes[@(pageIndex)] = [NSValue valueWithCGSize:page.size];
|
|
402
|
+
[self applyPendingPageSizes];
|
|
403
|
+
if ([cell.representedKey isEqualToString:key]) {
|
|
290
404
|
cell.imageView.image = page;
|
|
291
405
|
[self configureCell:cell withImage:page];
|
|
292
406
|
cell.imageView.transform = [self imageTransform];
|
|
293
|
-
[self.flowLayout invalidateLayout];
|
|
294
407
|
}
|
|
295
408
|
});
|
|
296
409
|
});
|
|
@@ -298,25 +411,59 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
298
411
|
return cell;
|
|
299
412
|
}
|
|
300
413
|
|
|
414
|
+
// Keep geometry fixed during the native gesture; one compensation happens at idle.
|
|
415
|
+
- (void)applyPendingPageSizes {
|
|
416
|
+
if (self.collectionView.dragging || self.collectionView.decelerating) return;
|
|
417
|
+
if (self.pendingViewportLayout) { [self setNeedsLayout]; [self layoutIfNeeded]; }
|
|
418
|
+
if (self.pendingPageSizes.count == 0) return;
|
|
419
|
+
NSDictionary *anchor = [self captureScrollAnchorForViewport:self.collectionView.bounds.size];
|
|
420
|
+
BOOL wasApplying = self.applyingProgrammaticPage;
|
|
421
|
+
self.applyingProgrammaticPage = YES;
|
|
422
|
+
[self.pageSizes addEntriesFromDictionary:self.pendingPageSizes];
|
|
423
|
+
[self.pendingPageSizes removeAllObjects];
|
|
424
|
+
[self.flowLayout invalidateLayout];
|
|
425
|
+
[self.collectionView layoutIfNeeded];
|
|
426
|
+
[self restoreScrollAnchor:anchor];
|
|
427
|
+
self.applyingProgrammaticPage = wasApplying;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
- (CGSize)pageSizeAtIndex:(NSInteger)page {
|
|
431
|
+
NSValue *known = self.pageSizes[@(page)];
|
|
432
|
+
if (known) return known.CGSizeValue;
|
|
433
|
+
NSString *key = [NSString stringWithFormat:@"%@:%ld:%ld", self.engineId ?: @"", (long)self.documentGeneration, (long)page];
|
|
434
|
+
if (self.pendingPageSizes[@(page)]) return CGSizeZero;
|
|
435
|
+
UIImage *cached = [PapyrusComicImageCache() objectForKey:key];
|
|
436
|
+
if (cached) self.pageSizes[@(page)] = [NSValue valueWithCGSize:cached.size];
|
|
437
|
+
return cached ? cached.size : CGSizeZero;
|
|
438
|
+
}
|
|
439
|
+
|
|
301
440
|
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)layout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
|
|
302
441
|
#pragma unused(layout)
|
|
303
442
|
if (![self.layoutMode isEqualToString:@"continuous"]) return collectionView.bounds.size;
|
|
304
443
|
NSInteger page = [self logicalPageForItem:indexPath.item];
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
if (
|
|
308
|
-
CGFloat width =
|
|
309
|
-
CGFloat height = width *
|
|
310
|
-
if ([self.fitMode isEqualToString:@"page"]) height = MIN(height,
|
|
444
|
+
CGSize imageSize = [self pageSizeAtIndex:page];
|
|
445
|
+
CGSize viewport = self.pendingViewportLayout && self.viewportSize.width > 0 ? self.viewportSize : collectionView.bounds.size;
|
|
446
|
+
if (imageSize.width <= 0 || imageSize.height <= 0) return viewport;
|
|
447
|
+
CGFloat width = viewport.width;
|
|
448
|
+
CGFloat height = width * imageSize.height / imageSize.width;
|
|
449
|
+
if ([self.fitMode isEqualToString:@"page"]) height = MIN(height, viewport.height);
|
|
311
450
|
return CGSizeMake(width, MAX(1, height));
|
|
312
451
|
}
|
|
313
452
|
|
|
453
|
+
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
|
|
454
|
+
#pragma unused(scrollView)
|
|
455
|
+
if (!decelerate) [self applyPendingPageSizes];
|
|
456
|
+
[self emitVisiblePage];
|
|
457
|
+
}
|
|
458
|
+
|
|
314
459
|
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
|
|
315
460
|
#pragma unused(scrollView)
|
|
461
|
+
[self applyPendingPageSizes];
|
|
316
462
|
[self emitVisiblePage];
|
|
317
463
|
}
|
|
318
464
|
- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)scrollView {
|
|
319
465
|
#pragma unused(scrollView)
|
|
466
|
+
[self applyPendingPageSizes];
|
|
320
467
|
[self emitVisiblePage];
|
|
321
468
|
}
|
|
322
469
|
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
|
|
@@ -325,23 +472,47 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
325
472
|
}
|
|
326
473
|
|
|
327
474
|
- (void)emitVisiblePage {
|
|
328
|
-
if (self.pageCount <= 0) return;
|
|
329
|
-
CGPoint center = CGPointMake(
|
|
330
|
-
|
|
475
|
+
if (self.applyingProgrammaticPage || self.pendingNavigation || self.pageCount <= 0) return;
|
|
476
|
+
CGPoint center = CGPointMake(self.collectionView.contentOffset.x + self.collectionView.bounds.size.width / 2,
|
|
477
|
+
self.collectionView.contentOffset.y + self.collectionView.bounds.size.height / 2);
|
|
331
478
|
NSIndexPath *indexPath = [self.collectionView indexPathForItemAtPoint:center];
|
|
332
479
|
if (!indexPath) return;
|
|
333
480
|
NSInteger page = [self logicalPageForItem:indexPath.item] + 1;
|
|
334
481
|
if (page == self.currentPage) return;
|
|
335
|
-
|
|
482
|
+
_currentPage = page;
|
|
483
|
+
self.requestedPage = page;
|
|
336
484
|
if (self.onPageChanged) self.onPageChanged(@{ @"page": @(page) });
|
|
337
485
|
}
|
|
338
486
|
|
|
487
|
+
- (void)handleDoubleTap:(UITapGestureRecognizer *)recognizer {
|
|
488
|
+
if (recognizer.state != UIGestureRecognizerStateRecognized ||
|
|
489
|
+
self.pinchRecognizer.state == UIGestureRecognizerStateChanged) return;
|
|
490
|
+
CGFloat previous = MAX(1, self.zoom);
|
|
491
|
+
CGFloat target = previous > 1.05 ? 1.0 : 2.0;
|
|
492
|
+
CGPoint focus = [recognizer locationInView:self.collectionView];
|
|
493
|
+
CGPoint center = CGPointMake(CGRectGetMidX(self.collectionView.bounds),
|
|
494
|
+
CGRectGetMidY(self.collectionView.bounds));
|
|
495
|
+
if (target <= 1.0) {
|
|
496
|
+
self.panOffset = CGPointZero;
|
|
497
|
+
} else {
|
|
498
|
+
CGFloat ratio = target / previous;
|
|
499
|
+
CGFloat maxX = self.collectionView.bounds.size.width * (target - 1.0) / 2.0;
|
|
500
|
+
CGFloat maxY = self.collectionView.bounds.size.height * (target - 1.0) / 2.0;
|
|
501
|
+
CGFloat x = ratio * self.panOffset.x + (1 - ratio) * (focus.x - center.x);
|
|
502
|
+
CGFloat y = ratio * self.panOffset.y + (1 - ratio) * (focus.y - center.y);
|
|
503
|
+
self.panOffset = CGPointMake(MAX(-maxX, MIN(maxX, x)), MAX(-maxY, MIN(maxY, y)));
|
|
504
|
+
}
|
|
505
|
+
self.zoom = target;
|
|
506
|
+
if (self.onZoomChanged) self.onZoomChanged(@{ @"zoom": @(self.zoom) });
|
|
507
|
+
}
|
|
508
|
+
|
|
339
509
|
- (void)handlePinch:(UIPinchGestureRecognizer *)recognizer {
|
|
340
510
|
if (recognizer.state == UIGestureRecognizerStateChanged) {
|
|
341
511
|
self.zoom = MAX(1, MIN(5, self.zoom * recognizer.scale));
|
|
342
512
|
recognizer.scale = 1;
|
|
343
|
-
} else if (recognizer.state == UIGestureRecognizerStateEnded
|
|
344
|
-
self
|
|
513
|
+
} else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) {
|
|
514
|
+
[self applyPendingPageSizes];
|
|
515
|
+
if (self.onZoomChanged) self.onZoomChanged(@{ @"zoom": @(self.zoom) });
|
|
345
516
|
}
|
|
346
517
|
}
|
|
347
518
|
|
|
@@ -368,6 +539,8 @@ static NSCache<NSString *, UIImage *> *PapyrusComicImageCache(void) {
|
|
|
368
539
|
MAX(-maxY, MIN(maxY, translation.y + self.panGestureStartOffset.y))
|
|
369
540
|
);
|
|
370
541
|
for (PapyrusComicPageCell *cell in self.collectionView.visibleCells) cell.imageView.transform = [self imageTransform];
|
|
542
|
+
} else if (recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled || recognizer.state == UIGestureRecognizerStateFailed) {
|
|
543
|
+
[self applyPendingPageSizes];
|
|
371
544
|
}
|
|
372
545
|
}
|
|
373
546
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "PapyrusTextAnnotationRange.h"
|
|
1
2
|
#import <Foundation/Foundation.h>
|
|
2
3
|
#import <React/RCTBridge.h>
|
|
3
4
|
#import <React/RCTBridgeModule.h>
|
|
@@ -757,6 +758,17 @@ RCT_EXPORT_METHOD(getTextRange:(NSString *)engineId
|
|
|
757
758
|
resolve([text substringWithRange:NSMakeRange((NSUInteger)start, (NSUInteger)(end - start))]);
|
|
758
759
|
}
|
|
759
760
|
|
|
761
|
+
RCT_EXPORT_METHOD(resolveTextAnnotationRange:(NSString *)engineId
|
|
762
|
+
generation:(NSInteger)generation
|
|
763
|
+
anchor:(NSDictionary *)anchor
|
|
764
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
765
|
+
rejecter:(RCTPromiseRejectBlock)reject) {
|
|
766
|
+
#pragma unused(reject)
|
|
767
|
+
NSString *text = [[PapyrusTextStore shared] textForEngineId:engineId generation:generation];
|
|
768
|
+
NSRange range = text ? PapyrusResolveTextAnnotationRange(text,anchor) : NSMakeRange(NSNotFound,0);
|
|
769
|
+
resolve(range.location == NSNotFound ? (id)kCFNull : @{@"start":@(range.location),@"end":@(NSMaxRange(range))});
|
|
770
|
+
}
|
|
771
|
+
|
|
760
772
|
RCT_EXPORT_METHOD(searchTextRanges:(NSString *)engineId
|
|
761
773
|
generation:(NSInteger)generation
|
|
762
774
|
query:(NSString *)query
|
|
@@ -14,6 +14,7 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
14
14
|
@property (nonatomic, copy) NSArray<NSDictionary *> *searchResults;
|
|
15
15
|
@property (nonatomic, assign) NSInteger activeSearchIndex;
|
|
16
16
|
@property (nonatomic, copy) NSArray<NSDictionary *> *annotations;
|
|
17
|
+
@property (nonatomic, copy, nullable) NSDictionary *annotationNavigationRequest;
|
|
17
18
|
@property (nonatomic, copy) NSString *activeTool;
|
|
18
19
|
@property (nonatomic, copy) NSString *activeDrawToolPreset;
|
|
19
20
|
@property (nonatomic, assign) CGFloat inkStrokeWidth;
|
|
@@ -23,6 +24,10 @@ NS_ASSUME_NONNULL_BEGIN
|
|
|
23
24
|
@property (nonatomic, copy, nullable) NSString *selectedAnnotationId;
|
|
24
25
|
@property (nonatomic, assign) BOOL selectionActive;
|
|
25
26
|
@property (nonatomic, copy) NSString *defineLabel;
|
|
27
|
+
// This is a localized label getter, not an Objective-C copy-family method.
|
|
28
|
+
- (NSString *)copyLabel __attribute__((objc_method_family(none)));
|
|
29
|
+
@property (nonatomic, copy) NSString *copyLabel;
|
|
30
|
+
@property (nonatomic, copy) NSString *selectAllLabel;
|
|
26
31
|
@property (nonatomic, copy) NSString *defineSelectionMode;
|
|
27
32
|
@property (nonatomic, copy) NSString *annotateLabel;
|
|
28
33
|
@property (nonatomic, copy) NSString *annotationHighlightLabel;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
#import "PapyrusSelectionMenu.h"
|
|
1
2
|
#import "PapyrusPdfDocumentView.h"
|
|
2
3
|
|
|
3
4
|
#import <QuartzCore/QuartzCore.h>
|
|
@@ -216,11 +217,14 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
216
217
|
@end
|
|
217
218
|
|
|
218
219
|
@interface PapyrusCommentPdfAnnotation : PDFAnnotation
|
|
220
|
+
@property (nonatomic, assign) BOOL groupHidden;
|
|
221
|
+
@property (nonatomic, assign) NSInteger groupCount;
|
|
219
222
|
@end
|
|
220
223
|
|
|
221
224
|
@implementation PapyrusCommentPdfAnnotation
|
|
222
225
|
- (void)drawWithBox:(PDFDisplayBox)box inContext:(CGContextRef)context {
|
|
223
226
|
(void)box;
|
|
227
|
+
if (self.groupHidden) return;
|
|
224
228
|
CGRect bounds = self.bounds;
|
|
225
229
|
if (CGRectIsNull(bounds) || CGRectIsEmpty(bounds) || !context) return;
|
|
226
230
|
|
|
@@ -246,6 +250,16 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
246
250
|
CGContextMoveToPoint(context, left, secondY);
|
|
247
251
|
CGContextAddLineToPoint(context, right, secondY);
|
|
248
252
|
CGContextStrokePath(context);
|
|
253
|
+
if (self.groupCount > 1) {
|
|
254
|
+
UIGraphicsPushContext(context);
|
|
255
|
+
CGContextTranslateCTM(context, CGRectGetMidX(bounds), CGRectGetMidY(bounds));
|
|
256
|
+
CGContextScaleCTM(context, 1, -1);
|
|
257
|
+
NSString *label = [NSString stringWithFormat:@"%ld", (long)self.groupCount];
|
|
258
|
+
NSDictionary *attributes = @{NSFontAttributeName:[UIFont boldSystemFontOfSize:MAX(8, bounds.size.height * 0.6)], NSForegroundColorAttributeName:UIColor.whiteColor};
|
|
259
|
+
CGSize size = [label sizeWithAttributes:attributes];
|
|
260
|
+
[label drawAtPoint:CGPointMake(-size.width/2, -size.height/2) withAttributes:attributes];
|
|
261
|
+
UIGraphicsPopContext();
|
|
262
|
+
}
|
|
249
263
|
CGContextRestoreGState(context);
|
|
250
264
|
}
|
|
251
265
|
@end
|
|
@@ -290,6 +304,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
290
304
|
@property (nonatomic, weak) UIScrollView *observedScrollView;
|
|
291
305
|
@property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
|
|
292
306
|
@property (nonatomic, strong) UITapGestureRecognizer *doubleTapRecognizer;
|
|
307
|
+
@property (nonatomic, strong) UILongPressGestureRecognizer *longPressRecognizer;
|
|
293
308
|
@property (nonatomic, assign) CGSize lastLayoutSize;
|
|
294
309
|
@property (nonatomic, assign) NSInteger lastEmittedPage;
|
|
295
310
|
@property (nonatomic, assign) CGFloat lastEmittedZoom;
|
|
@@ -352,6 +367,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
352
367
|
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
353
368
|
self.tapRecognizer.delegate = nil;
|
|
354
369
|
self.doubleTapRecognizer.delegate = nil;
|
|
370
|
+
self.longPressRecognizer.delegate = nil;
|
|
355
371
|
[self clearPapyrusAnnotationsForDocument:self.pdfView.document];
|
|
356
372
|
}
|
|
357
373
|
|
|
@@ -429,6 +445,12 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
429
445
|
_doubleTapRecognizer.delaysTouchesBegan = NO;
|
|
430
446
|
[_pdfView addGestureRecognizer:_doubleTapRecognizer];
|
|
431
447
|
[_tapRecognizer requireGestureRecognizerToFail:_doubleTapRecognizer];
|
|
448
|
+
_longPressRecognizer = [[UILongPressGestureRecognizer alloc]
|
|
449
|
+
initWithTarget:self action:@selector(handleDocumentLongPress:)];
|
|
450
|
+
_longPressRecognizer.delegate = self;
|
|
451
|
+
_longPressRecognizer.cancelsTouchesInView = NO;
|
|
452
|
+
[_pdfView addGestureRecognizer:_longPressRecognizer];
|
|
453
|
+
[_tapRecognizer requireGestureRecognizerToFail:_longPressRecognizer];
|
|
432
454
|
|
|
433
455
|
NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
|
|
434
456
|
[center addObserver:self
|
|
@@ -1143,6 +1165,20 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
1143
1165
|
[self updateSelectedAnnotationAdornment];
|
|
1144
1166
|
}
|
|
1145
1167
|
|
|
1168
|
+
- (void)setAnnotationNavigationRequest:(NSDictionary *)request {
|
|
1169
|
+
_annotationNavigationRequest = [request copy];
|
|
1170
|
+
if (!request) return;
|
|
1171
|
+
PDFDocument *document = self.pdfView.document;
|
|
1172
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
1173
|
+
if (self.pdfView.document != document || ![self.annotationNavigationRequest isEqual:request]) return;
|
|
1174
|
+
NSInteger index = [request[@"pageIndex"] integerValue];
|
|
1175
|
+
if (index < 0 || index >= document.pageCount || ![request[@"rect"] isKindOfClass:[NSDictionary class]]) return;
|
|
1176
|
+
PDFPage *page = [document pageAtIndex:index];
|
|
1177
|
+
CGRect rect = PapyrusPdfRectFromNormalizedRect(request[@"rect"], [page boundsForBox:kPDFDisplayBoxCropBox]);
|
|
1178
|
+
if (!CGRectIsEmpty(rect)) [self.pdfView goToRect:rect onPage:page];
|
|
1179
|
+
});
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1146
1182
|
- (void)setSelectedAnnotationId:(NSString *)selectedAnnotationId {
|
|
1147
1183
|
NSString *normalized = selectedAnnotationId.length > 0
|
|
1148
1184
|
? [selectedAnnotationId copy] : nil;
|
|
@@ -1154,7 +1190,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
1154
1190
|
|
|
1155
1191
|
- (NSString *)annotationSignature:(NSDictionary *)annotation {
|
|
1156
1192
|
NSArray<NSString *> *signatureKeys = @[
|
|
1157
|
-
@"id", @"type", @"pageIndex", @"rect", @"rects", @"color", @"opacity", @"content"
|
|
1193
|
+
@"id", @"type", @"pageIndex", @"rect", @"rects", @"color", @"opacity", @"content", @"anchor", @"markupStyle", @"noteContent"
|
|
1158
1194
|
];
|
|
1159
1195
|
NSMutableDictionary *signatureFields = [NSMutableDictionary dictionary];
|
|
1160
1196
|
for (NSString *key in signatureKeys) {
|
|
@@ -1253,6 +1289,24 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
1253
1289
|
|
|
1254
1290
|
NSString *type = [annotation[@"type"] isKindOfClass:NSString.class]
|
|
1255
1291
|
? annotation[@"type"] : @"";
|
|
1292
|
+
NSString *markup = [annotation[@"markupStyle"] isKindOfClass:NSString.class] ? annotation[@"markupStyle"] : ([@[@"highlight",@"underline",@"strikeout",@"squiggly"] containsObject:annotation[@"type"]] ? annotation[@"type"] : nil);
|
|
1293
|
+
BOOL hasContextNote = annotation[@"noteContent"] != nil;
|
|
1294
|
+
if (hasContextNote && !annotation[@"papyrusIndicatorOnly"]) {
|
|
1295
|
+
NSMutableArray *parts = [NSMutableArray array];
|
|
1296
|
+
if (markup.length && ![markup isEqual:@"none"]) {
|
|
1297
|
+
NSMutableDictionary *mark = [annotation mutableCopy];
|
|
1298
|
+
mark[@"type"] = markup; [mark removeObjectForKey:@"noteContent"]; [mark removeObjectForKey:@"markupStyle"];
|
|
1299
|
+
[parts addObjectsFromArray:[self createPdfAnnotationsForPapyrusAnnotation:mark]];
|
|
1300
|
+
}
|
|
1301
|
+
NSMutableDictionary *note = [annotation mutableCopy];
|
|
1302
|
+
note[@"type"] = @"comment"; note[@"papyrusIndicatorOnly"] = @YES;
|
|
1303
|
+
[parts addObjectsFromArray:[self createPdfAnnotationsForPapyrusAnnotation:note]];
|
|
1304
|
+
return parts;
|
|
1305
|
+
}
|
|
1306
|
+
if (markup.length && !hasContextNote) {
|
|
1307
|
+
if ([markup isEqual:@"none"]) return @[];
|
|
1308
|
+
type = markup;
|
|
1309
|
+
}
|
|
1256
1310
|
NSString *subtype = nil;
|
|
1257
1311
|
if ([type isEqualToString:@"highlight"]) subtype = @"Highlight";
|
|
1258
1312
|
else if ([type isEqualToString:@"underline"]) subtype = @"Underline";
|
|
@@ -1272,9 +1326,14 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
1272
1326
|
NSArray *rects = [annotation[@"rects"] isKindOfClass:NSArray.class]
|
|
1273
1327
|
? annotation[@"rects"] : @[];
|
|
1274
1328
|
if ([type isEqualToString:@"comment"] || [type isEqualToString:@"text"]) {
|
|
1275
|
-
NSDictionary *rect =
|
|
1276
|
-
|
|
1277
|
-
|
|
1329
|
+
NSDictionary *rect = rects.lastObject ?: annotation[@"rect"];
|
|
1330
|
+
if ([rect isKindOfClass:NSDictionary.class]) {
|
|
1331
|
+
CGFloat width = MIN(0.06, 18.0/MAX(1,CGRectGetWidth(pageBounds)));
|
|
1332
|
+
CGFloat height = MIN(0.06, 18.0/MAX(1,CGRectGetHeight(pageBounds)));
|
|
1333
|
+
CGFloat x = MIN(1-width,MAX(0,[rect[@"x"] doubleValue]+[rect[@"width"] doubleValue]));
|
|
1334
|
+
CGFloat y = MIN(1-height,MAX(0,[rect[@"y"] doubleValue]));
|
|
1335
|
+
rects = @[@{@"x":@(x),@"y":@(y),@"width":@(width),@"height":@(height)}];
|
|
1336
|
+
} else rects = @[];
|
|
1278
1337
|
} else if (rects.count == 0 && [annotation[@"rect"] isKindOfClass:NSDictionary.class]) {
|
|
1279
1338
|
rects = @[annotation[@"rect"]];
|
|
1280
1339
|
}
|
|
@@ -1367,6 +1426,18 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
1367
1426
|
didChangeRepresentations = YES;
|
|
1368
1427
|
}
|
|
1369
1428
|
if (didChangeRepresentations) {
|
|
1429
|
+
NSMutableDictionary<NSString *, PapyrusCommentPdfAnnotation *> *leaders = [NSMutableDictionary dictionary];
|
|
1430
|
+
for (NSString *annotationId in self.papyrusAnnotationsById) {
|
|
1431
|
+
for (PDFAnnotation *representation in self.papyrusAnnotationsById[annotationId]) {
|
|
1432
|
+
if (![representation isKindOfClass:PapyrusCommentPdfAnnotation.class]) continue;
|
|
1433
|
+
PapyrusCommentPdfAnnotation *note = (PapyrusCommentPdfAnnotation *)representation;
|
|
1434
|
+
note.groupHidden = NO; note.groupCount = 1;
|
|
1435
|
+
CGRect pageBounds = [note.page boundsForBox:kPDFDisplayBoxCropBox];
|
|
1436
|
+
NSString *key = [NSString stringWithFormat:@"%ld:%ld:%ld", (long)[document indexForPage:note.page], (long)floor((CGRectGetMinX(note.bounds)-pageBounds.origin.x)/(pageBounds.size.width * 0.035)), (long)floor((CGRectGetMinY(note.bounds)-pageBounds.origin.y)/(pageBounds.size.height * 0.035))];
|
|
1437
|
+
PapyrusCommentPdfAnnotation *leader = leaders[key];
|
|
1438
|
+
if (leader) { note.groupHidden = YES; leader.groupCount++; } else {leaders[key] = note;}
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1370
1441
|
[self updateSelectedAnnotationAdornment];
|
|
1371
1442
|
[self.pdfView setNeedsDisplay];
|
|
1372
1443
|
}
|
|
@@ -1923,7 +1994,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
1923
1994
|
[actions addObject:annotationMenu];
|
|
1924
1995
|
}
|
|
1925
1996
|
|
|
1926
|
-
[actions addObjectsFromArray:suggestedActions ?: @[]];
|
|
1997
|
+
[actions addObjectsFromArray:PapyrusLocalizedSelectionActions(suggestedActions ?: @[], self.copyLabel, self.selectAllLabel)];
|
|
1927
1998
|
|
|
1928
1999
|
return [UIMenu menuWithChildren:actions];
|
|
1929
2000
|
}
|
|
@@ -2182,7 +2253,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
2182
2253
|
}
|
|
2183
2254
|
NSString *annotationType = [papyrusAnnotation[@"type"] isKindOfClass:NSString.class]
|
|
2184
2255
|
? papyrusAnnotation[@"type"] : @"";
|
|
2185
|
-
if (![annotationType isEqualToString:@"comment"] &&
|
|
2256
|
+
if (!papyrusAnnotation[@"noteContent"] && ![annotationType isEqualToString:@"comment"] &&
|
|
2186
2257
|
![annotationType isEqualToString:@"text"]) {
|
|
2187
2258
|
[self presentAnnotationEditMenuForId:annotationId atPoint:viewPoint];
|
|
2188
2259
|
}
|
|
@@ -2219,12 +2290,26 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
|
|
|
2219
2290
|
PDFDocument *document = self.pdfView.document;
|
|
2220
2291
|
if (!document) return;
|
|
2221
2292
|
|
|
2222
|
-
|
|
2223
|
-
|
|
2293
|
+
[self selectWordAtViewPoint:[recognizer locationInView:self.pdfView]];
|
|
2294
|
+
}
|
|
2295
|
+
|
|
2296
|
+
- (void)handleDocumentLongPress:(UILongPressGestureRecognizer *)recognizer {
|
|
2297
|
+
if (recognizer.state != UIGestureRecognizerStateBegan ||
|
|
2298
|
+
[self.activeTool isEqualToString:@"ink"]) return;
|
|
2299
|
+
CGPoint point = [recognizer locationInView:self.pdfView];
|
|
2300
|
+
// Existing native handles must retain ownership of an extension gesture.
|
|
2301
|
+
if ([self selectionContainsViewPoint:point]) return;
|
|
2302
|
+
[self selectWordAtViewPoint:point];
|
|
2303
|
+
}
|
|
2304
|
+
|
|
2305
|
+
- (void)selectWordAtViewPoint:(CGPoint)viewPoint {
|
|
2306
|
+
PDFPage *page = [self.pdfView pageForPoint:viewPoint nearest:NO];
|
|
2224
2307
|
if (!page) return;
|
|
2225
|
-
|
|
2226
|
-
|
|
2227
|
-
|
|
2308
|
+
PDFSelection *selection = [page selectionForWordAtPoint:
|
|
2309
|
+
[self.pdfView convertPoint:viewPoint toPage:page]];
|
|
2310
|
+
if (!selection.string.length) return;
|
|
2311
|
+
selection.color = [UIColor.systemBlueColor colorWithAlphaComponent:0.30];
|
|
2312
|
+
[self.pdfView setCurrentSelection:selection animate:NO];
|
|
2228
2313
|
[self emitCurrentSelectionIfNeeded];
|
|
2229
2314
|
}
|
|
2230
2315
|
|
|
@@ -16,6 +16,7 @@ RCT_EXPORT_VIEW_PROPERTY(viewMode, NSString)
|
|
|
16
16
|
RCT_EXPORT_VIEW_PROPERTY(searchResults, NSArray)
|
|
17
17
|
RCT_EXPORT_VIEW_PROPERTY(activeSearchIndex, NSInteger)
|
|
18
18
|
RCT_EXPORT_VIEW_PROPERTY(annotations, NSArray)
|
|
19
|
+
RCT_EXPORT_VIEW_PROPERTY(annotationNavigationRequest, NSDictionary)
|
|
19
20
|
RCT_EXPORT_VIEW_PROPERTY(activeTool, NSString)
|
|
20
21
|
RCT_EXPORT_VIEW_PROPERTY(activeDrawToolPreset, NSString)
|
|
21
22
|
RCT_EXPORT_VIEW_PROPERTY(inkStrokeWidth, CGFloat)
|
|
@@ -25,6 +26,8 @@ RCT_EXPORT_VIEW_PROPERTY(annotationOpacity, CGFloat)
|
|
|
25
26
|
RCT_EXPORT_VIEW_PROPERTY(selectedAnnotationId, NSString)
|
|
26
27
|
RCT_EXPORT_VIEW_PROPERTY(selectionActive, BOOL)
|
|
27
28
|
RCT_EXPORT_VIEW_PROPERTY(defineLabel, NSString)
|
|
29
|
+
RCT_EXPORT_VIEW_PROPERTY(copyLabel, NSString)
|
|
30
|
+
RCT_EXPORT_VIEW_PROPERTY(selectAllLabel, NSString)
|
|
28
31
|
RCT_EXPORT_VIEW_PROPERTY(defineSelectionMode, NSString)
|
|
29
32
|
RCT_EXPORT_VIEW_PROPERTY(annotateLabel, NSString)
|
|
30
33
|
RCT_EXPORT_VIEW_PROPERTY(annotationHighlightLabel, NSString)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
#import <UIKit/UIKit.h>
|
|
2
|
+
|
|
3
|
+
// Keep system submenus and command targets, localizing only standard edit actions.
|
|
4
|
+
static inline NSArray<UIMenuElement *> *PapyrusLocalizedSelectionActions(
|
|
5
|
+
NSArray<UIMenuElement *> *elements, NSString *copyLabel, NSString *selectAllLabel) API_AVAILABLE(ios(13.0)) {
|
|
6
|
+
NSMutableArray<UIMenuElement *> *result = [NSMutableArray array];
|
|
7
|
+
for (UIMenuElement *element in elements) {
|
|
8
|
+
if ([element isKindOfClass:UIMenu.class]) {
|
|
9
|
+
UIMenu *menu = (UIMenu *)element;
|
|
10
|
+
[result addObject:[menu menuByReplacingChildren:
|
|
11
|
+
PapyrusLocalizedSelectionActions(menu.children, copyLabel, selectAllLabel)]];
|
|
12
|
+
} else if ([element isKindOfClass:UICommand.class]) {
|
|
13
|
+
UICommand *command = (UICommand *)element;
|
|
14
|
+
NSString *title = command.action == @selector(copy:) ? copyLabel :
|
|
15
|
+
command.action == @selector(selectAll:) ? selectAllLabel : nil;
|
|
16
|
+
if (title.length) {
|
|
17
|
+
UICommand *translated = [UICommand commandWithTitle:title
|
|
18
|
+
image:command.image ?: [UIImage systemImageNamed:@"doc.on.doc"]
|
|
19
|
+
action:command.action propertyList:command.propertyList];
|
|
20
|
+
translated.attributes = command.attributes;
|
|
21
|
+
translated.state = command.state;
|
|
22
|
+
[result addObject:translated];
|
|
23
|
+
} else [result addObject:element];
|
|
24
|
+
} else [result addObject:element];
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}
|