Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Web] Fix onStart firing on Pan with activateAfterLongPress when gesture is disabled while being pressed down. #3075

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

latekvo
Copy link
Contributor

@latekvo latekvo commented Aug 29, 2024

Description

Pan gesture allows for use of activateAfterLongPress modifier, which allows it to be activated after holding down the gesture down for a specified amount of time.

This modifier uses setTimeout underneath, which was not properly cleared when the gesture was disabled while being pressed down.

Closes: #3074

Test plan

  • run the attached code
  • when the button is clicked 2 times, nothing happens
  • without this PR, clicking the button 2 times results in onStart firing on the Pan gesture due to lack of timeout clearing

Attached code

  • make sure to have @shopify/flash-list installed
Collapsed code
import React from 'react';
import { Button, View } from 'react-native';
import { FlashList } from '@shopify/flash-list';
import { Gesture, GestureDetector } from 'react-native-gesture-handler';

export default function HomeScreen() {
  const [enabled, setEnabled] = React.useState(true);
  const data = [0];

  const panGesture = Gesture.Pan()
    .enabled(enabled)
    .activateAfterLongPress(750)
    .onStart(() => {
      console.warn('pan triggered');
    });

  return (
    <GestureDetector gesture={panGesture}>
      <FlashList
        data={data}
        ListHeaderComponent={
          <Button
            title={enabled ? 'Disable Gestures' : 'Enable Gestures'}
            onPress={() => {
              setEnabled((prev) => !prev);
            }}
          />
        }
        renderItem={() => {
          return (
            <View
              style={{
                height: 70,
                backgroundColor: 'tomato',
              }}
            />
          );
        }}
      />
    </GestureDetector>
  );
}

Results

Collapsed results recordings

Before

Screen.Recording.2024-08-29.at.11.10.22.mov

Fixed

Screen.Recording.2024-08-29.at.11.09.38.mov

Important:

As far as I see, all the other calls to this.clearActivationTimeout() can be activated individually, and none of them are redundant.

@latekvo latekvo marked this pull request as ready for review August 29, 2024 09:20
Copy link

@frankcalise frankcalise left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works perfectly! Tested a patch on 2.18.1, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[web] Gesture.Pan() fires onStart when toggling enabled
3 participants