Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TouchableHighlight onPress not working

Tags:

react-native

I implemented a sign in page that worked up until I upgraded react-native.

The problem I'm having is that the onPress prop isn't being called:

<TouchableHighlight style={styles.button}
        underlayColor='#f1c40f'
        onPress={this.signIn}>
   <Text style={styles.buttonText}>Sign In</Text>
</TouchableHighlight>

Here is my signIn function:

signIn: function(){
console.log("SignInAction signIn")
this.fetchData();  },

The signIn button appears to be depressed when I click it but the log statement isn't firing.

like image 471
lernerbot Avatar asked Nov 29 '15 22:11

lernerbot


2 Answers

Try calling it like this:

onPress={ () => this.signIn() }>

It looks like the "this" in your function is bound to the wrong scope.

like image 131
Nader Dabit Avatar answered Oct 20 '22 18:10

Nader Dabit


you can also do it like this:

onPress={this.signIn.bind(this)}>

the rest of code don't need change.

like image 45
李振纲 Avatar answered Oct 20 '22 17:10

李振纲