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

Events on Touchables are triggered twice since 2.13.0 on Android device only #2655

Closed
mattijsf opened this issue Oct 23, 2023 · 5 comments · Fixed by #2657
Closed

Events on Touchables are triggered twice since 2.13.0 on Android device only #2655

mattijsf opened this issue Oct 23, 2023 · 5 comments · Fixed by #2657
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided

Comments

@mattijsf
Copy link

mattijsf commented Oct 23, 2023

Description

Adding a TouchableOpacity (or TouchableWithoutFeedback etc) is calling various events such as onPress twice since 2.13.0 on Android only and only on a physical device. Downgrading to 2.12.1 fixed the issue.

Steps to reproduce

  1. Create a new project: npx react-native@latest init GestureHandlerTest
  2. npm i [email protected]
  3. Add following app snippet:
/* eslint-disable prettier/prettier */
/* eslint-disable react-native/no-inline-styles */
import React, { useState } from 'react';
import {Text, View} from 'react-native';
import {
  GestureHandlerRootView,
  TouchableOpacity,
} from 'react-native-gesture-handler';

function App(): JSX.Element {
  const [pressCount, setPressCount] = useState(0);

  return (
    <GestureHandlerRootView style={{flex: 1}}>
      <View style={{flex: 1, backgroundColor: '#000', justifyContent: 'center', alignItems: 'center', gap: 10}}>
      <Text style={{ color: '#fff' }}>Press Count: {pressCount}</Text>
        <TouchableOpacity onPress={(): void => setPressCount(c => c + 1)}>
          <View style={{backgroundColor: '#ff0000', width: 100, height: 100}} />
        </TouchableOpacity>
      </View>
    </GestureHandlerRootView>
  );
}

export default App;
  1. npm run android
  2. Observe the "Press Count" label when tapping the square view:
Android Device (🐞 broken) Android Emulator(✅ working)
android-device-touchable-bug.mov
android-emulator-touchable-working.mov

Snack or a link to a repository

https://github.com/mattijsf/gesture-handler-duplicate-events-test

Gesture Handler version

2.13.0

React Native version

0.72.6

Platforms

Android

JavaScript runtime

Hermes

Workflow

React Native (without Expo)

Architecture

Paper (Old Architecture)

Build type

Debug mode

Device

Real device

Device model

Pixel 6 Pro

Acknowledgements

Yes

@github-actions github-actions bot added Repro provided A reproduction with a snack or repo is provided Platform: Android This issue is specific to Android labels Oct 23, 2023
@mattijsf mattijsf changed the title Events on Touchables are triggered twice since 2.13.0 on Android only Events on Touchables are triggered twice since 2.13.0 on Android device only Oct 23, 2023
@exentrich
Copy link

Confirm! Same problem on a physical device Android 14

@m-bert
Copy link
Contributor

m-bert commented Oct 25, 2023

Hi! I think we identified what causes this issue. Do you have any accessibility settings turned on? And if so, could you please check #2657?

@wbercx
Copy link

wbercx commented Oct 30, 2023

I have Tasker for Android enabled on my device, which uses Accessibility features. While enabled, onPress does fire twice.

Your PR resolves that.

m-bert added a commit that referenced this issue Oct 30, 2023
## Description

One of the changes introduced in release 2.13.0 was [Android TalkBack fix](#2234). To check whether TalkBack is active or not I used `AccessibilityManager.isEnabled` (see [this line](https://github.com/software-mansion/react-native-gesture-handler/blob/fa721ede0cb1cab60ab8fa77a3a5922ad8462f3b/android/src/main/java/com/swmansion/gesturehandler/react/Extensions.kt#L16C80-L16C80)). Turns out that it was not the best idea, since this method will return `true` if any accessibility feature is enabled, not only TalkBack.

This PR changes `isEnabled` to `isTouchExplorationEnabled` so that other accessibility settings shouldn't trigger manual activation of our handlers.

Fixes #2603
Fixes #2655 

## Test plan

Tested on example app on device with other accessibility settings on.
@Bruce-Ming
Copy link

@m-bert This problem reappeared in 2.13.4. I looked at the source code and found that it changed back.
image
this problem

@m-bert
Copy link
Contributor

m-bert commented Nov 22, 2023

Hi @Bruce-Ming! No, it didn't reappear. Fix for that issue was merged after the 2.13.4 release, so it has not been released yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Platform: Android This issue is specific to Android Repro provided A reproduction with a snack or repo is provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants