Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React-native, render a button click dynamically

Tags:

react-native

i want to generate a button click dynamically for a TouchableOpacity in react-native, i didn't find anything about that,

all i want is to call the TouchableOpacity onPress from a fuction (or see its effect on the button)

in titanium we were doing $.button.click i tried using Animated but no luck https://facebook.github.io/react-native/docs/animations.html

so can anybody help? thanks in advance

like image 847
Hanane Avatar asked Dec 24 '22 05:12

Hanane


1 Answers

It's really inadvisable but something like this should work:

simulatePress() {
  this.touchable.props.onPress();
}

render() {
    return (
        <TouchableOpacity ref={component => this.touchable = component} onPress={() => console.log('onPress')}>
          <Text>Tap me</Text>
        </TouchableOpacity
    );
}

Really though, what you are trying to achieve? There is likely a better way to do it.

like image 78
oblador Avatar answered Dec 31 '22 03:12

oblador