admin管理员组文章数量:1301514
How to trigger another Touchable ponent's press event by tap a touchable ponent? 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>
How to trigger another Touchable ponent's press event by tap a touchable ponent? 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>
Share
asked Apr 12, 2017 at 12:15
Irfan AliIrfan Ali
2,2581 gold badge24 silver badges23 bronze badges
2 Answers
Reset to default 7For 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 ponents when tap are going to invoke to the same method
.
本文标签:
版权声明:本文标题:javascript - How to trigger another Touchable component's press event by tap a touchable component? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741678677a2392037.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论