admin管理员组文章数量:1388046
In react-native
sometimes it is useful to prevent a parent from capturing and handling touch / click events while allowing its children to receive and react to the events. Specifically, this is useful when using a <View/>
or <ImageBackground/>
container that acts as a transparent background to its child elements (example: gradient based shadows or wrapper views used to center elements of absolute positioning).
In react-native
sometimes it is useful to prevent a parent from capturing and handling touch / click events while allowing its children to receive and react to the events. Specifically, this is useful when using a <View/>
or <ImageBackground/>
container that acts as a transparent background to its child elements (example: gradient based shadows or wrapper views used to center elements of absolute positioning).
1 Answer
Reset to default 10React Native offers a pointerEvents
prop for <View/>
elements which can be set to 'none'
in order to stop reacting to touches and clicks, however the trick to allowing the children to still be touchable is to set the pointerEvents
prop to 'box-none'
instead of 'none'
.
Warning: In contrast to regular CSS, pointerEvents
is ` prop and not a style. So to use it, you can do
<View style={styles.parentWithoutTouchEvents} pointerEvents='box-none'>
<View style={styles.touchableChild}>
</View>
</View>
本文标签: javascriptPrevent parent from being clickable while allowing child to capture touchesStack Overflow
版权声明:本文标题:javascript - Prevent parent from being clickable while allowing child to capture touches - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744569676a2613261.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论