How to trigger another Touchable component's press event by tap a touchable component? thanks!
Example:-
<TouchableHighlight onPress={this._triggerSecond}>
<Image
style={styles.button}
source={require('./myButton.png')}
/>
</TouchableHighlight>
If user will tap on first TouchableHighlight then it should trigger second TouchableHighlight.
<TouchableHighlight>
<Image
style={styles.button}
source={require('./myButton.png')}
/>
</TouchableHighlight>
For those who still need to fire a press programmatically, I found a solution. First you need to bind your touchable to this
by using ref :
<TouchableOpacity
onPress={() => alert("click")}
ref={(touchable) => this._touchable = touchable}
>
then when you want to launch onPress without clicking it just call
this._touchable.touchableHandlePress()
Well I guess instead of thinking in that way I guess you can thinking this as just another TouchableHighlight
calling the same method such as:
// First one
<TouchableHighlight onPress={this._method}>
<Image
style={styles.button}
source={require('./myButton.png')}
/>
</TouchableHighlight>
// Second one
<TouchableHighlight onPress={this._method}>
<Image
style={styles.button}
source={require('./myButton.png')}
/>
</TouchableHighlight>
In this way both components when tap are going to invoke to the same method
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With