question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. ItĀ collects links to all the places you might be looking at while hunting down a tough bug.

And, if youā€™re still stuck at the end, weā€™re happy to hop on a call to see how we can help out.

TouchableWithoutFeedback does not fire onPress like other Touchable Components

See original GitHub issue

šŸ› Bug Report

Same as closed bug #18611 TouchableWithoutFeedback does not call the onPress handler unless itā€™s direct child is a View Component. This is counter to the fact that other touchable components will allow custom components as their child.

To Reproduce

  1. Create a FlatList
  2. Create a ListItem that utilizes a TouchableWithoutFeedback component with an onPress handler
  3. Add a non-View child Component, any custom component that renders content.
  4. Test by tapping ListItem and find that no onPress event is fired.

Expected Behavior

I would think that the expected behavior would be that the onPress event would be fired no matter what child component the TouchableWithoutFeedback component

Code Example

https://github.com/haddow777/tech_stack

Specifically look at the file ./src/components/ListItem.js. That is where the TouchableWithoutFeedback component is used. In itā€™s current state, the event does not fire. If I encapsulate the current children in a View component tag, the event will fire. I changed the TouchableWithoutFeedback with a TouchableOpacity component without the View component child, and the onPress fires. It seems they should both work the same.

Environment

React Native Environment Info:
    System:
      OS: Windows 10
      CPU: (4) x64 Intel(R) Core(TM) i5-4300U CPU @ 1.90GHz
      Memory: 1.27 GB / 7.91 GB
    Binaries:
      Yarn: 1.13.0 - C:\Users\SURFACE\AppData\Roaming\npm\yarn.CMD
      npm: 6.8.0 - C:\Program Files\nodejs\npm.CMD
    IDEs:
      Android Studio: Version  3.2.0.0 AI-181.5540.7.32.5056338

Android Emulator api 27

react-native-cli: 2.0.1
react-native: n/a - not inside a React Native project directory

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:7
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
canpoyrazoglucommented, May 28, 2019

Iā€™m on 0.59.8 and I can confirm that this issue is present. My TouchableWithoutFeedback does not fire inside my FlatList cells, whereas TouchableOpacity does.

5reactions
mgcreacommented, Apr 25, 2019

Using latest react-native (0.59.5), I canā€™t make a TouchableWithoutFeedback or TouchableNativeFeedback work inside a FlatList, the ripple is there (with native feedback) but onPress is never called, even with a basic <View />.

No issues with Opacity/Highlight touchable components.

eg:

    <FlatList
      data={data}
      renderItem={({item, separators}) => (
        <TouchableNativeFeedback
          onPress={() => onPress(item.key)}
        >
          <View style={{flex: 1}}>
            <Text>FooBar</Text>
          </View>
        </TouchableNativeFeedback>
      )}
    />
Read more comments on GitHub >

github_iconTop Results From Across the Web

React native onPress with TouchableWithoutFeedback is not ...
I am implementing touch event using TouchableWithoutFeedback. This is my code. class AlbumList extends React.Component { constructor(props) {Ā ...
Read more >
TouchableWithoutFeedback - React Native
Do not use unless you have a very good reason. All elements that respond to press should have a visual feedback when touched....
Read more >
React Native touchable vs. pressable components
Learn the difference between touchable and pressable components in React Native, and how to implement different effects with each kind.
Read more >
React Native's ā€œTouchableā€ Components | by Ross Mawdsley
TouchableOpacity: the component has its opacity reduced, making it see-through; TouchableWithoutFeedback: no visual feedback. TouchableHighlight.
Read more >
Click Events - Buttons - JavaScript Camp
If this button is not suitable for your application, you can create your own button using ... The Pressable and Touchable components are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found