Paul
Paul

Reputation: 4486

TouchableNativeFeedback on a component does not execute the onPress function

I have something like this:

<TouchableNativeFeedback
  onPress={this._changeAccount.bind(this, user)}
  delayPressIn={0}
  delayPressOut={0}
  useForeground={true}
  background={RippleColor('#ccc')}
>
  <PhotoStatus>
</TouchableNativeFeedback>

When I click on the "PhotoStatus" component, nothing happens.

The onPress function is not called.

It would be such a thing: PhotoStatus

<View>
  <Image
    source={image}
    style={{
      width: dim - 30,
      height: dim - 30,
      borderRadius: (dim - 30) / 2,
    }}
  />
</View>

if instead I replace directly with the component code contained in it, it works.

In the example on expo the used where in the image below there are the two red squares marked.

enter image description here

Link Expo: expo

Upvotes: 0

Views: 680

Answers (1)

slashsharp
slashsharp

Reputation: 2833

Wrap your component in View and it should fix the error

<TouchableNativeFeedback
  onPress={this._changeAccount.bind(this, user)}
  delayPressIn={0}
  delayPressOut={0}
  useForeground={true}
  background={RippleColor('#ccc')}
>
  <View>
   <PhotoStatus>
  </View>
</TouchableNativeFeedback>

Expo Snack

Upvotes: 1

Related Questions