react-native-gesture-handler is failing to detect a double tap gesture

I recently checked out the latest documentation for RNGH here

Struggling with getting the double tap event to trigger, it seems like RNGH only registers events with fewer taps (I modified the numberOfTaps in the const singleTap to 3 and then the doubleTap started working)

I even attempted changing the Exclusive order (no luck)

Tried replicating an older version of RNGH 1.10.3 as shown in this video

https://www.youtube.com/watch?v=nbEmo0zLJjw&list=PLjHsmVtnAr9TWoMAh-3QMiP7bPUqPFuFZ&index=6

But unfortunately, none of these methods seemed to do the trick

Gesture:

  const singleTap = Gesture.Tap().onEnd((_event, success) => {
    if (success) {
      console.log("single tap!");
    }
  });
  const doubleTap = Gesture.Tap()
    .numberOfTaps(2)
    .onEnd((_event, success) => {
      if (success) {
        console.log("double tap!");
      }
    });

  const taps = Gesture.Exclusive(doubleTap, singleTap);

Component:

    <View style={styles.container}>
      <GestureDetector gesture={taps}>
        <Animated.View>
          <ImageBackground
            source={require("./assets/image.jpg")}
            style={styles.image}
          >
            <Image
              source={require("./assets/heart.png")}
              style={[
                styles.image,
                {
                  shadowOffset: { width: 0, height: 20 },
                  shadowOpacity: 0.35,
                  shadowRadius: 35,
                },
              ]}
              resizeMode={"center"}
            />
          </ImageBackground>
        </Animated.View>
      </GestureDetector>
    </View>

Answer №1

It has been reported that this particular problem is specific to the expo app on iOS devices. Expo developers are aware of this issue and are working on a fix for it in an upcoming update. I am facing the same issue and plan to follow the suggested solution in the meantime.

Answer №2

I attempted to implement the provided example as well as other sources without success, such as:

I am currently using Expo, but I am uncertain if that is causing any issues. If none of the suggested solutions work for you, you may consider my manual approach to implementing the functionality:

import React, { useCallback, useEffect, useState } from "react";
import { Pressable, StyleSheet } from "react-native";

interface DoubleTapWrapperProps {
  delay?: number;
  children: React.ReactNode;
  onSingleTap: () => void;
  onDoubleTap: () => void;
}

export default function DoubleTapWrapper({
  delay = 300,
  children,
  onSingleTap,
  onDoubleTap,
}: DoubleTapWrapperProps) {
  const [firstPress, setFirstPress] = useState(true);
  const [lastTime, setLastTime] = useState(new Date().getTime());
  const [timer, setTimer] = useState<NodeJS.Timeout | null>(null);

  useEffect(() => {
    return () => {
      timer && clearTimeout(timer);
    };
  });

  const onTap = useCallback(() => {
    const now = new Date().getTime();

    // Single tap
    if (firstPress) {
      setFirstPress(false);

      setTimer(
        setTimeout(() => {
          onSingleTap && onSingleTap();

          setFirstPress(true);
          setTimer(null);
        }, delay)
      );

      setLastTime(now);
    } else {
      // Double tap
      if (now - lastTime < delay) {
        timer && clearTimeout(timer);
        onDoubleTap && onDoubleTap();
        setFirstPress(true);
      }
    }
  }, [firstPress, lastTime, delay, onDoubleTap, onSingleTap, timer]);

  return (
    <Pressable onPress={onTap} style={styles.container}>
      {children}
    </Pressable>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
  },
});

This functional component is based on an implementation sourced from here. Here's an example of how it can be used:

export default function Example() {
  return (
    <DoubleTapWrapper
      onSingleTap={() => {
        console.log("single");
      }}
      onDoubleTap={() => {
        console.log("double");
      }}
    >
      <View style={styles.container}>
        <Text style={styles.title}>Double tap example</Text>
      </View>
    </DoubleTapWrapper>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: "center",
    justifyContent: "center",
  },
  title: {
    fontSize: 20,
    fontWeight: "bold",
  },
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Utilizing a for loop to add div elements

I have a HTML form in my code where the user fills out information, including entering a value in the "member" field and clicking a button to generate additional copies of the 'sector_prop' div. The form section is - Number of Sectors (L ...

I seem to be struggling with hiding/showing a div element. Can you figure

I am in the process of creating a gallery that will display a div with images when a button is clicked. The issue I am facing is that when I have two buttons, only the last images are clickable. It's a bit difficult to explain, but you can see it in ...

Having trouble passing data from JavaScript to PHP with AJAX

I attempted to use AJAX to send data from an array (emp) and other string variables like 'gtotal' in my code, but the data did not transfer to the PHP file. Despite no errors being shown, when I removed the isset() function it displayed an error ...

Is there a way for me to store the message I sent using discord.js in a variable?

I'm looking to send a message in the channel and then react to it by getting that message for a message reaction. bot.sendMessage({ to: channelID, message: '@everyone\n' + message.slice(16) + '\n\nThis message is a ...

Change the height of a division element after a script has been loaded

My web application is created using Bootstrap and Flask and it loads a Bokeh server document into a container div. The responsiveness of the Bokeh elements' size depends on a specific fixed initial height set for the containing div. This customization ...

VueJS not refreshing DOM after AJAX data modification

Utilizing Vue.js to make changes to my DOM, I have implemented the fetch_data() method. This method attempts to update data.messages to display 'Love the Vue.JS' once the AJAX call is successfully completed. The AJAX call executes successfully a ...

The issue of useEffect triggering twice is caused by React router redirection

In my route setup, I have the following configuration: <Route path={`list`} element={<ListPage />}> <Route path={`sidePanel1`} element={<SidePanel1 />} /> <Route path={`sidePanel2`} element={<SidePanel2 />} /> < ...

Determine which city is submitted when the form is completed

Is there a way to automatically populate the city parameter in the form details? Please note that I am retrieving data from an Oracle database. Below is the code snippet I am currently using: <script> $(document).ready(function() { $ ...

Is it optimal to count negative indexes in JavaScript arrays towards the total array length?

When working in JavaScript, I typically define an array like this: var arr = [1,2,3]; It's also possible to do something like: arr[-1] = 4; However, if I were to then set arr to undefined using: arr = undefined; I lose reference to the value at ...

The nested transclude directive is displaying the inner transcluded content in the incorrect location

I created a directive called myList that transcludes its content. The issue arises when I try to nest a <my-list> element inside another <my-list>. Check out the JS Fiddle here: http://jsfiddle.net/fqj5svhn/ The directive is implemented as fo ...

Is there a way to display the tooltip at all times in Chart.js version 3.7.1?

https://i.sstatic.net/Lmfqn.png [Chart.js 3.7.1] Is there a way to keep the tooltip always visible? I am looking for a method to have the tooltip constantly displayed. Additionally, I would like the text to be darkened only on today's date. Si ...

Video margins within a webview

After numerous attempts to embed a YouTube video in a WebView, I'm still struggling with a persistent small margin on the right side of the video. I've researched similar issues and attempted to address it through JavaScript adjustments without ...

How can one easily implement a countdown timer in an Ionic 3 app?

Easily create an Ionic3 timer set to 2 minutes that displays countdown like 1:59, 1:58, and finally reaches 00:00. Once the timer hits 00:00, a block of HTML content will be shown. ...

How can I retrieve the height of a div element once its content has been altered in

I am currently updating the content of a div dynamically and I need to immediately get its new height after the change. var text='Bla-bla-bla Bla-bla-bla Bla-bla-bla Bla-bla-bla Bla-bla-bla Bla-bla-bla Bla-bla-bla Bla-bla-bla Bla-bla-bla Bla-bla-bla ...

Exploring the World of Angularjs 2

Currently, I am diving into learning angularjs 2. I found a helpful git repository that I am following closely, which can be found here. The repository contains some interesting codes in the index.html file. <script src="node_modules/core-js/client/shi ...

Struggling to create a web application using parcel-bundler (Java not loading post-compilation)

Hey everyone, I've been searching online for a solution to my problem with parcel while working on a bootstrap web project, but I haven't had any luck. So now, I'm reaching out to you all for help. Bear with me as I explain the situation in ...

Struggling with a stuck Bootstrap Navbar during responsive mode?

I recently designed a website using a bootstrap theme and incorporated a navbar into it. However, I noticed that the navbar collapses in responsive mode, but stays fixed to the right side of the page. This is causing me to horizontally scroll in order to ...

Exploring nested routes with React Router 4

When a user clicks on an image, the URL changes to ("/r/:id") but the content of the page remains unchanged. <BrowserRouter> <Switch> <Route path="/r/:id" component={View} /> </Switch> </BrowserRouter>, <Link ...

Once the Ionic platform is prepared, retrieve from the Angular factory

I have created a firebase Auth factory that looks like this: app.factory("Auth", ["$firebaseAuth", "FIREBASE_URL","$ionicPlatform", function($firebaseAuth, FIREBASE_URL, $ionicPlatform) { var auth = {}; $ionicPlatform.ready(function(){ ...

Calculate the character count of every string within an array

Here is the JavaScript code I wrote: var myArray = ["the", "quick", "brown", "fox"]; console.log(myArray.length); This is what I want the output to look like: [3, 5, 5, 3] ...