最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Prevent parent from being clickable while allowing child to capture touches - Stack Overflow

programmeradmin7浏览0评论

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).

Share Improve this question asked Mar 22, 2018 at 4:00 Wassim GrWassim Gr 5982 gold badges8 silver badges17 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

React 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>
发布评论

评论列表(0)

  1. 暂无评论