@papyrus-sdk/engine-native 0.2.26 → 0.2.28

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.
@@ -284,6 +284,44 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
284
284
  }
285
285
  @end
286
286
 
287
+
288
+ // Drops PDFKit's built-in highlight item (no public identifier) from a menu
289
+ // tree, keeping Papyrus's own actions.
290
+ static NSArray<UIMenuElement *> *PapyrusWithoutSystemHighlight(NSArray<UIMenuElement *> *children) API_AVAILABLE(ios(16.0)) {
291
+ NSMutableArray<UIMenuElement *> *kept = [NSMutableArray arrayWithCapacity:children.count];
292
+ for (UIMenuElement *element in children) {
293
+ if ([element isKindOfClass:UIMenu.class]) {
294
+ UIMenu *menu = (UIMenu *)element;
295
+ if ([menu.identifier hasPrefix:@"com.papyrus."]) { [kept addObject:menu]; continue; }
296
+ NSArray<UIMenuElement *> *inner = PapyrusWithoutSystemHighlight(menu.children);
297
+ if (inner.count > 0) [kept addObject:[menu menuByReplacingChildren:inner]];
298
+ continue;
299
+ }
300
+ if ([element isKindOfClass:UICommand.class]) {
301
+ NSString *selectorName = NSStringFromSelector(((UICommand *)element).action).lowercaseString;
302
+ if ([selectorName containsString:@"highlight"]) continue;
303
+ }
304
+ if ([element isKindOfClass:UIAction.class]) {
305
+ NSString *identifier = ((UIAction *)element).identifier ?: @"";
306
+ if (![identifier hasPrefix:@"com.papyrus."] &&
307
+ [identifier.lowercaseString containsString:@"highlight"]) continue;
308
+ }
309
+ [kept addObject:element];
310
+ }
311
+ return kept;
312
+ }
313
+
314
+ @class PapyrusPdfDocumentView;
315
+
316
+ // PDFKit owns text selection and its edit menu. Since iOS 16 a separate
317
+ // UIEditMenuInteraction on a PDFView fights PDFKit's own menu (the system
318
+ // "Copy | Select All" shows first, ours much later), so the reader's actions
319
+ // are inserted into PDFKit's menu through buildMenu, as Readium's PDF
320
+ // navigator does.
321
+ @interface PapyrusPdfKitView : PDFView
322
+ @property (nonatomic, weak, nullable) PapyrusPdfDocumentView *papyrusOwner;
323
+ @end
324
+
287
325
  @interface PapyrusPdfDocumentView () <UIEditMenuInteractionDelegate,
288
326
  PDFPageOverlayViewProvider,
289
327
  PKCanvasViewDelegate,
@@ -304,7 +342,6 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
304
342
  @property (nonatomic, weak) UIScrollView *observedScrollView;
305
343
  @property (nonatomic, strong) UITapGestureRecognizer *tapRecognizer;
306
344
  @property (nonatomic, strong) UITapGestureRecognizer *doubleTapRecognizer;
307
- @property (nonatomic, strong) UILongPressGestureRecognizer *longPressRecognizer;
308
345
  @property (nonatomic, assign) CGSize lastLayoutSize;
309
346
  @property (nonatomic, assign) NSInteger lastEmittedPage;
310
347
  @property (nonatomic, assign) CGFloat lastEmittedZoom;
@@ -317,15 +354,13 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
317
354
  @property (nonatomic, copy) NSString *lastSelectionSignature;
318
355
  @property (nonatomic, assign) NSInteger lastSelectionPageIndex;
319
356
  @property (nonatomic, assign) BOOL lastSelectionWasActive;
320
- @property (nonatomic, assign) NSUInteger selectionMenuGeneration;
321
357
  @property (nonatomic, strong) NSMutableDictionary<NSNumber *, PapyrusPdfPageInkCanvasView *> *inkCanvasesByPageIndex;
322
358
  @property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSString *> *inkAnnotationSignaturesByPageIndex;
323
359
  @property (nonatomic, weak) PapyrusPdfPageInkCanvasView *activeInkCanvas;
324
360
  @property (nonatomic, strong) PKToolPicker *activeInkToolPicker;
325
361
  @property (nonatomic, copy) NSString *lastAppliedInkToolConfiguration;
326
- - (void)scheduleSelectionEditMenuForSignature:(NSString *)signature;
327
- - (void)attemptSelectionEditMenuForSignature:(NSString *)signature generation:(NSUInteger)generation;
328
- - (BOOL)hasActiveGestureInView:(UIView *)view;
362
+ - (NSArray<UIMenuElement *> *)papyrusSelectionMenuElements API_AVAILABLE(ios(16.0));
363
+ - (void)buildPapyrusSelectionMenuWithBuilder:(id<UIMenuBuilder>)builder API_AVAILABLE(ios(16.0));
329
364
  - (void)emitDefineSelection;
330
365
  - (BOOL)isSingleWordSelection:(NSString *)text;
331
366
  - (void)rebuildSearchHighlights;
@@ -341,6 +376,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
341
376
  - (NSArray<PDFAnnotation *> *)createPdfAnnotationsForPapyrusAnnotation:(NSDictionary *)annotation;
342
377
  - (NSString *)annotationSignature:(NSDictionary *)annotation;
343
378
  - (void)emitAnnotationFromCurrentSelectionWithType:(NSString *)type;
379
+ - (void)emitAnnotationFromCurrentSelectionWithType:(NSString *)type color:(nullable NSString *)color;
344
380
  - (void)presentAnnotationEditMenuForId:(NSString *)annotationId atPoint:(CGPoint)point;
345
381
  - (void)emitAnnotationDeleteWithId:(NSString *)annotationId;
346
382
  - (void)emitCommentAtPage:(PDFPage *)page pageIndex:(NSInteger)pageIndex normalizedPoint:(CGPoint)point;
@@ -367,7 +403,6 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
367
403
  [[NSNotificationCenter defaultCenter] removeObserver:self];
368
404
  self.tapRecognizer.delegate = nil;
369
405
  self.doubleTapRecognizer.delegate = nil;
370
- self.longPressRecognizer.delegate = nil;
371
406
  [self clearPapyrusAnnotationsForDocument:self.pdfView.document];
372
407
  }
373
408
 
@@ -411,7 +446,9 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
411
446
  self.clipsToBounds = YES;
412
447
  self.backgroundColor = UIColor.whiteColor;
413
448
 
414
- _pdfView = [[PDFView alloc] initWithFrame:CGRectZero];
449
+ PapyrusPdfKitView *pdfKitView = [[PapyrusPdfKitView alloc] initWithFrame:CGRectZero];
450
+ pdfKitView.papyrusOwner = self;
451
+ _pdfView = pdfKitView;
415
452
  _pdfView.displayBox = kPDFDisplayBoxCropBox;
416
453
  _pdfView.displayDirection = kPDFDisplayDirectionVertical;
417
454
  _pdfView.displayMode = kPDFDisplaySinglePageContinuous;
@@ -445,12 +482,6 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
445
482
  _doubleTapRecognizer.delaysTouchesBegan = NO;
446
483
  [_pdfView addGestureRecognizer:_doubleTapRecognizer];
447
484
  [_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];
454
485
 
455
486
  NSNotificationCenter *center = [NSNotificationCenter defaultCenter];
456
487
  [center addObserver:self
@@ -1340,6 +1371,9 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1340
1371
  CGFloat opacity = [annotation[@"opacity"] respondsToSelector:@selector(doubleValue)]
1341
1372
  ? [annotation[@"opacity"] doubleValue] : defaultOpacity;
1342
1373
  if (!isfinite(opacity)) opacity = 1.0;
1374
+ // A highlight fills over the text: never opaque, whatever opacity it was
1375
+ // saved with (marks made after using the pen kept its 1.0).
1376
+ if ([type isEqualToString:@"highlight"]) opacity = MIN(opacity, 0.4);
1343
1377
  NSString *hexColor = [annotation[@"color"] isKindOfClass:NSString.class]
1344
1378
  ? annotation[@"color"] : self.annotationColor;
1345
1379
  UIColor *color = PapyrusAnnotationColor(hexColor, opacity);
@@ -1441,6 +1475,10 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1441
1475
  }
1442
1476
 
1443
1477
  - (void)emitAnnotationFromCurrentSelectionWithType:(NSString *)type {
1478
+ [self emitAnnotationFromCurrentSelectionWithType:type color:nil];
1479
+ }
1480
+
1481
+ - (void)emitAnnotationFromCurrentSelectionWithType:(NSString *)type color:(NSString *)color {
1444
1482
  if (!self.onAnnotationCreated) return;
1445
1483
  PDFSelection *selection = self.pdfView.currentSelection;
1446
1484
  NSString *text = selection.string ?: @"";
@@ -1494,7 +1532,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1494
1532
  @"type" : type,
1495
1533
  @"rect" : annotationRect,
1496
1534
  @"rects" : rects,
1497
- @"color" : self.annotationColor ?: @"#fbbf24",
1535
+ @"color" : color.length > 0 ? color : (self.annotationColor ?: @"#fbbf24"),
1498
1536
  @"opacity" : @(opacity),
1499
1537
  @"content" : text,
1500
1538
  @"createdAt" : @((long long)([[NSDate date] timeIntervalSince1970] * 1000.0))
@@ -1812,12 +1850,10 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1812
1850
  if (self.onTextSelected) {
1813
1851
  self.onTextSelected(@{@"text" : text, @"pageIndex" : @(pageIndex), @"rects" : rects});
1814
1852
  }
1815
- [self scheduleSelectionEditMenuForSignature:signature];
1816
1853
  }
1817
1854
 
1818
1855
  - (void)emitSelectionClearedIfNeeded {
1819
1856
  if (!self.lastSelectionWasActive) return;
1820
- self.selectionMenuGeneration += 1;
1821
1857
  if (@available(iOS 16.0, *)) {
1822
1858
  [self.editMenuInteraction dismissMenu];
1823
1859
  }
@@ -1831,56 +1867,6 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1831
1867
  }
1832
1868
  }
1833
1869
 
1834
- - (void)scheduleSelectionEditMenuForSignature:(NSString *)signature {
1835
- if (@available(iOS 16.0, *)) {
1836
- UIEditMenuInteraction *interaction = self.editMenuInteraction;
1837
- if (!interaction || signature.length == 0) return;
1838
-
1839
- NSUInteger generation = ++self.selectionMenuGeneration;
1840
- __weak typeof(self) weakSelf = self;
1841
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.22 * NSEC_PER_SEC)),
1842
- dispatch_get_main_queue(), ^{
1843
- typeof(self) strongSelf = weakSelf;
1844
- [strongSelf attemptSelectionEditMenuForSignature:signature generation:generation];
1845
- });
1846
- }
1847
- }
1848
-
1849
- - (void)attemptSelectionEditMenuForSignature:(NSString *)signature generation:(NSUInteger)generation {
1850
- if (@available(iOS 16.0, *)) {
1851
- if (generation != self.selectionMenuGeneration ||
1852
- ![signature isEqualToString:self.lastSelectionSignature]) {
1853
- return;
1854
- }
1855
-
1856
- if ([self hasActiveGestureInView:self.pdfView]) {
1857
- __weak typeof(self) weakSelf = self;
1858
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.10 * NSEC_PER_SEC)),
1859
- dispatch_get_main_queue(), ^{
1860
- typeof(self) strongSelf = weakSelf;
1861
- [strongSelf attemptSelectionEditMenuForSignature:signature generation:generation];
1862
- });
1863
- return;
1864
- }
1865
-
1866
- UIEditMenuInteraction *interaction = self.editMenuInteraction;
1867
- PDFSelection *selection = self.pdfView.currentSelection;
1868
- PDFPage *page = selection.pages.firstObject;
1869
- if (!interaction || !selection.string.length || !page ||
1870
- (!self.onDefineSelection && !self.onAnnotationCreated)) return;
1871
-
1872
- CGRect selectionRect = [selection boundsForPage:page];
1873
- CGRect viewRect = [self.pdfView convertRect:selectionRect fromPage:page];
1874
- if (CGRectIsNull(viewRect) || CGRectIsEmpty(viewRect)) return;
1875
- self.contextualAnnotationMenuId = nil;
1876
- self.contextualAnnotationMenuConfigurationId = nil;
1877
- CGPoint sourcePoint = CGPointMake(CGRectGetMidX(viewRect), CGRectGetMidY(viewRect));
1878
- UIEditMenuConfiguration *configuration =
1879
- [UIEditMenuConfiguration configurationWithIdentifier:signature sourcePoint:sourcePoint];
1880
- [interaction presentEditMenuWithConfiguration:configuration];
1881
- }
1882
- }
1883
-
1884
1870
  - (void)presentAnnotationEditMenuForId:(NSString *)annotationId atPoint:(CGPoint)point {
1885
1871
  if (@available(iOS 16.0, *)) {
1886
1872
  UIEditMenuInteraction *interaction = self.editMenuInteraction;
@@ -1907,20 +1893,6 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1907
1893
  if (self.onAnnotationDeselected) self.onAnnotationDeselected(@{});
1908
1894
  }
1909
1895
 
1910
- - (BOOL)hasActiveGestureInView:(UIView *)view {
1911
- for (UIGestureRecognizer *recognizer in view.gestureRecognizers) {
1912
- if (recognizer.state == UIGestureRecognizerStateBegan ||
1913
- recognizer.state == UIGestureRecognizerStateChanged) {
1914
- return YES;
1915
- }
1916
- }
1917
-
1918
- for (UIView *subview in view.subviews) {
1919
- if ([self hasActiveGestureInView:subview]) return YES;
1920
- }
1921
- return NO;
1922
- }
1923
-
1924
1896
  - (nullable UIMenu *)editMenuInteraction:(UIEditMenuInteraction *)interaction
1925
1897
  menuForConfiguration:(UIEditMenuConfiguration *)configuration
1926
1898
  suggestedActions:(NSArray<UIMenuElement *> *)suggestedActions API_AVAILABLE(ios(16.0)) {
@@ -1955,6 +1927,24 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1955
1927
  }
1956
1928
  }
1957
1929
 
1930
+ [rootActions addObjectsFromArray:[self papyrusSelectionMenuElements]];
1931
+
1932
+ NSMutableArray<UIMenuElement *> *remainingSystemActions = [NSMutableArray array];
1933
+ for (UIMenuElement *element in localizedSystemActions) {
1934
+ if (element != nativeCopyAction) [remainingSystemActions addObject:element];
1935
+ }
1936
+ [rootActions addObjectsFromArray:remainingSystemActions];
1937
+
1938
+ UIMenu *rootMenu = [UIMenu menuWithChildren:rootActions];
1939
+ if (@available(iOS 16.0, *)) {
1940
+ // UIKit may still choose a platform-specific layout for edit menus.
1941
+ rootMenu.preferredElementSize = UIMenuElementSizeMedium;
1942
+ }
1943
+ return rootMenu;
1944
+ }
1945
+
1946
+ - (NSArray<UIMenuElement *> *)papyrusSelectionMenuElements {
1947
+ NSMutableArray<UIMenuElement *> *elements = [NSMutableArray array];
1958
1948
  if (self.onDefineSelection && self.defineLabel.length > 0 &&
1959
1949
  self.pdfView.currentSelection.string.length > 0 &&
1960
1950
  (![self.defineSelectionMode isEqualToString:@"single-word"] ||
@@ -1967,7 +1957,7 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
1967
1957
  handler:^(__kindof UIAction *action) {
1968
1958
  [weakSelf emitDefineSelection];
1969
1959
  }];
1970
- [rootActions addObject:defineAction];
1960
+ [elements addObject:defineAction];
1971
1961
  }
1972
1962
 
1973
1963
  UIAction *highlightAction = nil;
@@ -2009,25 +1999,76 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
2009
1999
  handler:^(__kindof UIAction *action) {
2010
2000
  [weakSelf emitAnnotationFromCurrentSelectionWithType:@"comment"];
2011
2001
  }];
2012
- [rootActions addObject:highlightAction];
2013
- UIMenu *annotationMenu = [UIMenu menuWithTitle:self.annotateLabel
2014
- children:@[underlineAction, strikeoutAction,
2015
- squigglyAction, noteAction]];
2016
- [rootActions addObject:annotationMenu];
2017
- }
2018
-
2019
- NSMutableArray<UIMenuElement *> *remainingSystemActions = [NSMutableArray array];
2020
- for (UIMenuElement *element in localizedSystemActions) {
2021
- if (element != nativeCopyAction) [remainingSystemActions addObject:element];
2022
- }
2023
- [rootActions addObjectsFromArray:remainingSystemActions];
2024
-
2025
- UIMenu *rootMenu = [UIMenu menuWithChildren:rootActions];
2026
- if (@available(iOS 16.0, *)) {
2027
- // UIKit may still choose a platform-specific layout for edit menus.
2028
- rootMenu.preferredElementSize = UIMenuElementSizeMedium;
2029
- }
2030
- return rootMenu;
2002
+ // Destacar › opens the colours (a dot and its name each) and, below
2003
+ // them, the other text marks; the note stays one tap away.
2004
+ NSArray<UIMenuElement *> *colorActions = [self highlightColorActions];
2005
+ UIMenu *colorsSection = [UIMenu menuWithTitle:@""
2006
+ image:nil
2007
+ identifier:@"com.papyrus.annotation.highlight-colors"
2008
+ options:UIMenuOptionsDisplayInline
2009
+ children:colorActions.count > 0 ? colorActions : @[highlightAction]];
2010
+ UIMenu *stylesSection = [UIMenu menuWithTitle:@""
2011
+ image:nil
2012
+ identifier:@"com.papyrus.annotation.text-marks"
2013
+ options:UIMenuOptionsDisplayInline
2014
+ children:@[underlineAction, strikeoutAction, squigglyAction]];
2015
+ UIMenu *highlightMenu = [UIMenu menuWithTitle:self.annotationHighlightLabel
2016
+ image:[UIImage systemImageNamed:@"highlighter"]
2017
+ identifier:@"com.papyrus.annotation.highlight-menu"
2018
+ options:0
2019
+ children:@[colorsSection, stylesSection]];
2020
+ [elements addObject:highlightMenu];
2021
+ [elements addObject:noteAction];
2022
+ }
2023
+ return elements;
2024
+ }
2025
+
2026
+ // Called by PapyrusPdfKitView while PDFKit builds its text-selection menu.
2027
+ - (void)buildPapyrusSelectionMenuWithBuilder:(id<UIMenuBuilder>)builder {
2028
+ if (!self.pdfView.currentSelection.string.length) return;
2029
+ NSArray<UIMenuElement *> *elements = [self papyrusSelectionMenuElements];
2030
+ if (elements.count == 0) return;
2031
+ // PDFKit's own "Highlight" does nothing for the app and duplicates ours;
2032
+ // "Look Up" duplicates Define.
2033
+ if (self.onDefineSelection) [builder removeMenuForIdentifier:UIMenuLookup];
2034
+ [builder replaceChildrenOfMenuForIdentifier:UIMenuRoot fromChildrenBlock:^NSArray<UIMenuElement *> *(NSArray<UIMenuElement *> *children) {
2035
+ return PapyrusWithoutSystemHighlight(children);
2036
+ }];
2037
+ UIMenu *papyrusMenu = [UIMenu menuWithTitle:@""
2038
+ image:nil
2039
+ identifier:@"com.papyrus.selection"
2040
+ options:UIMenuOptionsDisplayInline
2041
+ children:elements];
2042
+ [builder insertChildMenu:papyrusMenu atStartOfMenuForIdentifier:UIMenuStandardEdit];
2043
+ }
2044
+
2045
+ // One action per highlight colour, a tinted dot and its name, so the reader
2046
+ // picks the colour while selecting (as the Android/EPUB selection menu does).
2047
+ - (NSArray<UIMenuElement *> *)highlightColorActions {
2048
+ NSArray<NSString *> *colors = self.annotationHighlightColors;
2049
+ if (colors.count == 0) return @[];
2050
+ NSArray<NSString *> *labels = self.annotationHighlightColorLabels;
2051
+ NSMutableArray<UIMenuElement *> *swatches = [NSMutableArray array];
2052
+ __weak typeof(self) weakSelf = self;
2053
+ [colors enumerateObjectsUsingBlock:^(NSString *hex, NSUInteger index, BOOL *stop) {
2054
+ if (![hex isKindOfClass:NSString.class] || hex.length == 0) return;
2055
+ UIColor *swatchColor = PapyrusAnnotationColor(hex, 1.0);
2056
+ UIImage *swatch = [[UIImage systemImageNamed:@"circle.fill"]
2057
+ imageWithTintColor:swatchColor renderingMode:UIImageRenderingModeAlwaysOriginal];
2058
+ NSString *name = index < labels.count && [labels[index] isKindOfClass:NSString.class]
2059
+ ? labels[index] : hex;
2060
+ NSString *colorHex = [hex copy];
2061
+ UIAction *action = [UIAction actionWithTitle:name
2062
+ image:swatch
2063
+ identifier:[NSString stringWithFormat:
2064
+ @"com.papyrus.annotation.highlight.%lu",
2065
+ (unsigned long)index]
2066
+ handler:^(__kindof UIAction *a) {
2067
+ [weakSelf emitAnnotationFromCurrentSelectionWithType:@"highlight" color:colorHex];
2068
+ }];
2069
+ [swatches addObject:action];
2070
+ }];
2071
+ return swatches;
2031
2072
  }
2032
2073
 
2033
2074
  - (BOOL)isSingleWordSelection:(NSString *)text {
@@ -2284,7 +2325,10 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
2284
2325
  }
2285
2326
  NSString *annotationType = [papyrusAnnotation[@"type"] isKindOfClass:NSString.class]
2286
2327
  ? papyrusAnnotation[@"type"] : @"";
2287
- if (!papyrusAnnotation[@"noteContent"] && ![annotationType isEqualToString:@"comment"] &&
2328
+ // The host opens its own sheet for the tapped mark; a second, native
2329
+ // edit menu presented at the same moment made iOS show neither.
2330
+ if (!self.onAnnotationTap && !papyrusAnnotation[@"noteContent"] &&
2331
+ ![annotationType isEqualToString:@"comment"] &&
2288
2332
  ![annotationType isEqualToString:@"text"]) {
2289
2333
  [self presentAnnotationEditMenuForId:annotationId atPoint:viewPoint];
2290
2334
  }
@@ -2316,33 +2360,8 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
2316
2360
  }
2317
2361
 
2318
2362
  - (void)handleDocumentDoubleTap:(UITapGestureRecognizer *)recognizer {
2319
- if (recognizer.state != UIGestureRecognizerStateEnded) return;
2320
- if ([self.activeTool isEqualToString:@"ink"]) return;
2321
- PDFDocument *document = self.pdfView.document;
2322
- if (!document) return;
2323
-
2324
- [self selectWordAtViewPoint:[recognizer locationInView:self.pdfView]];
2325
- }
2326
-
2327
- - (void)handleDocumentLongPress:(UILongPressGestureRecognizer *)recognizer {
2328
- if (recognizer.state != UIGestureRecognizerStateBegan ||
2329
- [self.activeTool isEqualToString:@"ink"]) return;
2330
- CGPoint point = [recognizer locationInView:self.pdfView];
2331
- // Existing native handles must retain ownership of an extension gesture.
2332
- if ([self selectionContainsViewPoint:point]) return;
2333
- [self selectWordAtViewPoint:point];
2334
- }
2335
-
2336
- - (void)selectWordAtViewPoint:(CGPoint)viewPoint {
2337
- PDFPage *page = [self.pdfView pageForPoint:viewPoint nearest:NO];
2338
- if (!page) return;
2339
- PDFSelection *selection = [page selectionForWordAtPoint:
2340
- [self.pdfView convertPoint:viewPoint toPage:page]];
2341
- if (!selection.string.length) return;
2342
- [self.pdfView becomeFirstResponder];
2343
- selection.color = [UIColor.systemBlueColor colorWithAlphaComponent:0.30];
2344
- [self.pdfView setCurrentSelection:selection animate:NO];
2345
- [self emitCurrentSelectionIfNeeded];
2363
+ // Only makes the single tap wait for a possible double tap: PDFKit selects
2364
+ // the word itself and shows its edit menu with the Papyrus actions.
2346
2365
  }
2347
2366
 
2348
2367
  - (BOOL)selectionContainsViewPoint:(CGPoint)viewPoint {
@@ -2368,3 +2387,21 @@ static NSString *PapyrusHexColorFromUIColor(UIColor *color, CGFloat *opacity) {
2368
2387
  }
2369
2388
 
2370
2389
  @end
2390
+
2391
+ @implementation PapyrusPdfKitView
2392
+
2393
+ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender {
2394
+ // Selecting every page of a long PDF hangs PDFKit (1,400 pages froze the
2395
+ // reader); the reader has no use for it.
2396
+ if (action == @selector(selectAll:)) return NO;
2397
+ return [super canPerformAction:action withSender:sender];
2398
+ }
2399
+
2400
+ - (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder {
2401
+ [super buildMenuWithBuilder:builder];
2402
+ if (@available(iOS 16.0, *)) {
2403
+ [self.papyrusOwner buildPapyrusSelectionMenuWithBuilder:builder];
2404
+ }
2405
+ }
2406
+
2407
+ @end
@@ -31,6 +31,8 @@ RCT_EXPORT_VIEW_PROPERTY(selectAllLabel, NSString)
31
31
  RCT_EXPORT_VIEW_PROPERTY(defineSelectionMode, NSString)
32
32
  RCT_EXPORT_VIEW_PROPERTY(annotateLabel, NSString)
33
33
  RCT_EXPORT_VIEW_PROPERTY(annotationHighlightLabel, NSString)
34
+ RCT_EXPORT_VIEW_PROPERTY(annotationHighlightColors, NSArray)
35
+ RCT_EXPORT_VIEW_PROPERTY(annotationHighlightColorLabels, NSArray)
34
36
  RCT_EXPORT_VIEW_PROPERTY(annotationUnderlineLabel, NSString)
35
37
  RCT_EXPORT_VIEW_PROPERTY(annotationStrikeoutLabel, NSString)
36
38
  RCT_EXPORT_VIEW_PROPERTY(annotationSquigglyLabel, NSString)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@papyrus-sdk/engine-native",
3
- "version": "0.2.26",
3
+ "version": "0.2.28",
4
4
  "license": "MIT",
5
5
  "keywords": [
6
6
  "papyrus",
@@ -49,13 +49,13 @@
49
49
  "url": "https://github.com/solrachix/Papyrus/issues"
50
50
  },
51
51
  "peerDependencies": {
52
- "@papyrus-sdk/core": "0.2.25",
53
- "@papyrus-sdk/types": "0.2.17",
52
+ "@papyrus-sdk/core": ">=0.2.25 <0.3.0",
53
+ "@papyrus-sdk/types": ">=0.2.17 <0.3.0",
54
54
  "react-native": ">=0.81.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@papyrus-sdk/core": "0.2.25",
58
- "@papyrus-sdk/types": "0.2.17",
57
+ "@papyrus-sdk/core": "0.2.26",
58
+ "@papyrus-sdk/types": "0.2.18",
59
59
  "react-native": "^0.81.0"
60
60
  },
61
61
  "scripts": {