gpt4 book ai didi

react-native - React-Native 中的指针事件是什么

转载 作者:行者123 更新时间:2023-12-05 01:40:11 24 4
gpt4 key购买 nike

我正在浏览 pointer event in React-native

在文档中,他们提到了

Controls whether the View can be the target of touch events.
• 'auto': The View can be the target of touch events.
• 'none': The View is never the target of touch events.
• 'box-none': The View is never the target of touch events but it's subviews can be. It behaves like if the view had the following classes in CSS:

我来了能够从属性 none 中理解没有触摸事件会起作用,即 touchableOpacity(和其他触摸事件)?那是对的吗?

但来自 YouTube 上的以下教程视频

https://www.youtube.com/watch?v=aFwBzWV6A-w

看起来作者正在使用它来禁用像 textInput 这样的事件,而是将它用于像 touchableOpactiy 这样的事件。

最佳答案

当将 pointerEvents 设置为 none 时,您将禁用 View 子项的所有触摸事件。这适用于所有 Touchables,也适用于 Inputs 等。在视频中,作者使用它来防止 TextInput 获得焦点,但他保持启用 TouchableOpacity 以触发动画。 (见下面的例子)

示例:

在这里,我禁用了 TextInput,但我保持 Touchable 处于事件状态:

<View>
<TouchableOpacity>
<View pointerEvents="none">
<TextInput ... />
</View>
</TouchableOpacity>
</View>

如果我将 pointerEvents="none" 添加到 Root View ,Touchable 和 TextInput 都将被停用。

关于react-native - React-Native 中的指针事件是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56912834/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com