跳到主要内容
新架构实战课 实操 + 基建 + 原理全维度包揽,抢先掌握 React Native 新架构精髓 立即查看 >Version: 0.74

TouchableWithoutFeedback

If you're looking for a more extensive and future-proof way to handle touch-based input, check out the Pressable API.

除非你有一个很好的理由,否则不要用这个组件。所有能够响应触屏操作的元素在触屏后都应该有一个视觉上的反馈(然而本组件没有任何视觉反馈),这也是为什么一个"web"应用总是显得不够"原生"的主要原因之一。

注意TouchableWithoutFeedback只支持一个子节点(不能没有子节点也不能多于一个)。如果你希望包含多个子组件,可以用一个 View 来包装它们。

译注:常见的使用场景比如想实现点击空白处触发某个操作,那么就可以把空白部分用TouchableWithoutFeedback包起来,或者绝对定位覆盖住。

示例


文档

Props

accessibilityComponentType

> Note: accessibilityComponentTypewill soon be deprecated. When possible, use accessibilityRole and accessibilityStates instead.

类型必需
AccessibilityComponentTypes

accessibilityHint

An accessibility hint helps users understand what will happen when they perform an action on the accessibility element when that result is not obvious from the accessibility label.

类型必需
string

accessibilityLabel

Overrides the text that's read by the screen reader when the user interacts with the element. By default, the label is constructed by traversing all the children and accumulating all the Text nodes separated by space.

类型必需
node

accessibilityRole

类型必需
AccessibilityRoles

accessibilityStates

类型必需
array of AccessibilityStates

accessibilityTraits

类型必需
AccessibilityTraits, ,array of AccessibilityTraits

accessible

类型必需
bool

delayLongPress

从 onPressIn 开始,到 onLongPress 被调用的延迟。单位是毫秒.

类型必需
number

delayPressIn

从触摸操作开始到 onPressIn 被调用的延迟。单位是毫秒。

类型必需
number

delayPressOut

从触摸操作结束开始到 onPressOut 被调用的延迟。单位是毫秒。

类型必需
number

disabled

如果设为 true,则禁止此组件的一切交互。

类型必需
bool

hitSlop

这一属性定义了按钮的外延范围。这一范围也会使pressRetentionOffset变得更大。 注意: 触摸范围不会超过父视图的边界,也不会影响原先和本组件层叠的视图(保留原先的触摸优先级)。

类型必需
object: {top: number, left: number, bottom: number, right: number}

onBlur

Invoked when the item loses focus.

类型Required
functionNo

onFocus

Invoked when the item receives focus.

类型Required
functionNo

onLayout

当加载或者布局改变的时候被调用,参数为:

{nativeEvent: {layout: {x, y, width, height}}}

类型必需
function

onLongPress

类型必需
function

onPress

当触摸操作结束时调用,但如果被取消了则不调用(譬如响应者被一个滚动操作取代)。

类型必需
function

onPressIn

Called as soon as the touchable element is pressed and invoked even before onPress. This can be useful when making network requests.

类型必需
function

onPressOut

Called as soon as the touch is released even before onPress.

类型必需
function

pressRetentionOffset

在当前视图不能滚动的前提下指定这个属性,可以决定当手指移开多远距离之后,会不再激活按钮。但如果手指再次移回范围内,按钮会被再次激活。只要视图不能滚动,你可以来回多次这样的操作。确保你传入一个常量来减少内存分配。

类型必需
object: {top: number, left: number, bottom: number, right: number}

testID

Used to locate this view in end-to-end tests.

类型Required
stringNo

类型定义

Event

类型
Object