wonday / react-native-pdf

A <Pdf /> component for react-native
MIT License
1.58k stars 544 forks source link

Get iOS Context Menu (Copy, Translate ...) to consistently show up on long press #690

Closed psquizzle closed 1 year ago

psquizzle commented 2 years ago

What react-native version are you using?

0.66

What react-native-pdf version are you using?

@latest

What platform does your issue occur on? (android/ios/both)

iOS

Describe your issue as precisely as possible :

  1. Load a pdf
  2. Long press on text

I can get it to show up occasionally by wildly pressing all over the screen. I am assuming the single tap and or double tap functions are capturing the event in most cases.

psquizzle commented 1 year ago

So, I discovered that long press is disabled [self addGestureRecognizer:longPressRecognizer]; within RCTPdfView.m

Is there a reason for this? Would make more sense as a configuration prop

grvrai commented 1 year ago

What's the solution for this?

psquizzle commented 1 year ago

I use the following patch:

diff --git a/node_modules/react-native-pdf/.DS_Store b/node_modules/react-native-pdf/.DS_Store
new file mode 100644
index 0000000..e69de29
diff --git a/node_modules/react-native-pdf/index.js b/node_modules/react-native-pdf/index.js
index 95520c1..4dec0b3 100644
--- a/node_modules/react-native-pdf/index.js
+++ b/node_modules/react-native-pdf/index.js
@@ -7,19 +7,12 @@
  */

 'use strict';
-import React, {Component} from 'react';
+import { ViewPropTypes } from 'deprecated-react-native-prop-types';
 import PropTypes from 'prop-types';
-import {
-    requireNativeComponent,
-    View,
-    Platform,
-    StyleSheet,
-    Image,
-    Text
-} from 'react-native';
-
+import React, { Component } from 'react';
+import { Image, Platform, requireNativeComponent, StyleSheet, Text, View } from 'react-native';
 import ReactNativeBlobUtil from 'react-native-blob-util'
-import {ViewPropTypes} from 'deprecated-react-native-prop-types';
+
 const SHA1 = require('crypto-js/sha1');
 import PdfView from './PdfView';

diff --git a/node_modules/react-native-pdf/ios/.DS_Store b/node_modules/react-native-pdf/ios/.DS_Store
new file mode 100644
index 0000000..e69de29
diff --git a/node_modules/react-native-pdf/ios/RCTPdf/RCTPdfView.m b/node_modules/react-native-pdf/ios/RCTPdf/RCTPdfView.m
index d488083..0d66325 100644
--- a/node_modules/react-native-pdf/ios/RCTPdf/RCTPdfView.m
+++ b/node_modules/react-native-pdf/ios/RCTPdf/RCTPdfView.m
@@ -555,7 +555,7 @@ - (void)bindTap
                                                                                           action:@selector(handleSingleTap:)];
     //trigger by one finger and one touch
     singleTapRecognizer.numberOfTapsRequired = 1;
-    singleTapRecognizer.numberOfTouchesRequired = 1;
+    singleTapRecognizer.numberOfTouchesRequired = 2;
     singleTapRecognizer.delegate = self;

     [self addGestureRecognizer:singleTapRecognizer];
@@ -566,14 +566,14 @@ - (void)bindTap
     [self addGestureRecognizer:pinchRecognizer];
     pinchRecognizer.delegate = self;

-    UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self
-                                                                                            action:@selector(handleLongPress:)];
+    //UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self
+      //                                                                                      action:@selector(handleLongPress:)];
     // Making sure the allowable movement isn not too narrow
-    longPressRecognizer.allowableMovement=100;
+   // longPressRecognizer.allowableMovement=100;
     // Important: The duration must be long enough to allow taps but not longer than the period in which view opens the magnifying glass
-    longPressRecognizer.minimumPressDuration=0.3;
+    //longPressRecognizer.minimumPressDuration=0.3;

-    [self addGestureRecognizer:longPressRecognizer];
+    //[self addGestureRecognizer:longPressRecognizer];

 }
grvrai commented 1 year ago

Thanks a lot, I will try this out.