跳至主内容
版本:0.80

TouchableNativeFeedback

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

如果你正在寻找更全面且面向未来的触摸输入处理方案,请查看 Pressable API。

用于使视图正确响应触摸操作的包装组件(仅限 Android)。在 Android 平台上,该组件使用原生状态可绘制对象来显示触摸反馈。

当前仅支持将单个 View 实例作为子节点,其实现原理是将该 View 替换为设置了附加属性的 RCTView 节点实例。

可通过 background 属性自定义原生反馈触摸操作的背景可绘制对象。

示例


参考

属性

无触摸反馈属性

继承无触摸反馈属性


background

决定用于显示反馈的背景可绘制对象类型。接收包含 type 属性的对象,其额外数据取决于 type 值。建议使用静态方法生成该字典对象。

Type
backgroundPropType

useForeground

设置为 true 可将涟漪效果添加到视图前景而非背景。这在子视图具有自身背景(例如显示图片)且不希望涟漪效果被遮挡时特别有用。

请先通过 TouchableNativeFeedback.canUseNativeForeground() 检测兼容性,此特性仅适用于 Android 6.0 及以上版本。在旧版本中使用将触发警告并自动回退到背景模式。

Type
bool

hasTVPreferredFocus
Android

TV 首选焦点(详见 View 组件文档)。

Type
bool

nextFocusDown
Android

电视下一个向下焦点(请参阅 View 组件的文档)。

Type
number

nextFocusForward
Android

电视下一个向前焦点(请参阅 View 组件的文档)。

Type
number

nextFocusLeft
Android

电视下一个向左焦点(请参阅 View 组件的文档)。

Type
number

nextFocusRight
Android

电视下一个向右焦点(请参阅 View 组件的文档)。

Type
number

nextFocusUp
Android

电视下一个向上焦点(请参阅 View 组件的文档)。

Type
number

方法

SelectableBackground()

tsx
static SelectableBackground(
rippleRadius: number | null,
): ThemeAttributeBackgroundPropType;

创建代表 Android 主题默认可选元素背景的对象 (?android:attr/selectableItemBackground)。rippleRadius 参数控制涟漪效果半径。


SelectableBackgroundBorderless()

tsx
static SelectableBackgroundBorderless(
rippleRadius: number | null,
): ThemeAttributeBackgroundPropType;

创建代表 Android 主题默认无边框可选元素背景的对象 (?android:attr/selectableItemBackgroundBorderless)。适用于 Android API 21+ 版本。rippleRadius 参数控制涟漪效果半径。


Ripple()

tsx
static Ripple(
color: ColorValue,
borderless: boolean,
rippleRadius?: number | null,
): RippleBackgroundPropType;

创建代表指定颜色(字符串格式)涟漪可绘制对象的实例。若 borderless 属性值为 true,涟漪将在视图边界外渲染(参见原生操作栏按钮示例)。此背景类型需 Android API 21+ 支持。

参数:

NameTypeRequiredDescription
colorstringYesThe ripple color
borderlessbooleanYesIf the ripple can render outside its bounds
rippleRadius?numberNocontrols the radius of the ripple effect

canUseNativeForeground()

tsx
static canUseNativeForeground(): boolean;