2

I'm trying to create something where if a user long presses on the screen, a button appears at the position of the press (I know how to do this), and while the finger is still down, the button gets pressed. That is, I don't want the user to have to lift their finger after the button reaches their finger's position before they can press it.

Any thoughts on how this can be done, if at all? I need to be able to begin the onPress event of the button even before the onLongPress event of the screen has technically ended (I assume it ends once you release your finger)

sidharth ramanan
  • 321
  • 1
  • 15
  • 1
    You should look into https://github.com/software-mansion/react-native-gesture-handler because you can hook into the touch event itself and build your logic around that. – Eric Bachhuber Apr 18 '21 at 00:52
  • 4
    If you know when to show the button, why not simply call the onPress function at the same time? – LonelyCpp Apr 20 '21 at 12:11

2 Answers2

0

You can simply call the click function in JavaScript:

document.getElementById('elementID').click();

This question also has more answers here: How to simulate a click with JavaScript?

Kunal Katiyar
  • 304
  • 2
  • 15
0

Judging by the question it seems you are trying to make a button draggable without the button clicking. In order to do this note down the amount of time the button is held down for, if it exceeds a certain period of time, do not click.

//Sample code coming right up.
DerpyCoder
  • 127
  • 1
  • 6