TouchableOpacity 吞下触摸事件并永不通过 [英] TouchableOpacity swallow touch event and never pass
本文介绍了TouchableOpacity 吞下触摸事件并永不通过的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让 onPress
都发生 TouchableOpacity
,但第二个是唯一触发的:
I'm trying to make both onPress
to happened TouchableOpacity
, but the second one is the only one that fires:
<TouchableOpacity onPress={() => console.warn('first button')}>
<TouchableOpacity onPress={() => console.warn('second button')}>
<Text>
PRESS ME
</Text>
</TouchableOpacity>
</TouchableOpacity>
我怎样才能让它们都着火?
How can I make both of them fire?
提前致谢!
推荐答案
您只需使用 'ref' 概念并调用 onPress 道具即可同时触发它们.
You can fire both of them simply using the 'ref' concept and calling the props onPress.
<TouchableOpacity onPress={() =>
AlertIOS.alert('firstbutton')
}
ref={component => this.myFirstTouchable = component}
>
<TouchableOpacity onPress={() =>
{
AlertIOS.alert('second')
this.myFirstTouchable.props.onPress()
}
}>
<Text>
PRESS ME
</Text>
</TouchableOpacity>
</TouchableOpacity>
这篇关于TouchableOpacity 吞下触摸事件并永不通过的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文