TouchableNativeFeedback
如果你在寻找一种更全面且更具前瞻性的方式来处理基于触摸的输入,可以查看 Pressable API。
一个用于让视图正确响应触摸的包装器(仅限 Android)。在 Android 上,这个组件使用原生状态 drawable 来显示触摸反馈。
目前它只支持将单个 View 实例作为子节点,因为它的实现方式是用另一个带有一些额外属性设置的 RCTView 节点替换该 View。
原生反馈触摸组件的背景 drawable 可以通过 background 属性自定义。
示例
参考
属性
TouchableWithoutFeedback Props
继承自 TouchableWithoutFeedback Props。
background
决定将用于显示反馈的背景 drawable 类型。它接受一个带有 type 属性的对象,以及取决于 type 的额外数据。建议使用静态方法之一来生成该字典。
| 类型 |
|---|
| backgroundPropType |
useForeground
设置为 true 时,会将 ripple 效果添加到视图前景,而不是背景。当你的某个子视图本身已有背景,或者你正在例如显示图片,并且不希望 ripple 被它们遮挡时,这很有用。
请先检查 TouchableNativeFeedback.canUseNativeForeground(),因为它仅在 Android 6.0 及以上版本可用。如果你在旧版本上尝试使用它,会收到警告并回退到背景。
| 类型 |
|---|
| bool |
hasTVPreferredFocus Android
TV 首选焦点(请参阅 View 组件的文档)。
| 类型 |
|---|
| bool |
nextFocusDown Android
TV 下一个聚焦方向为下(请参阅 View 组件的文档)。
| 类型 |
|---|
| number |
nextFocusForward Android
TV 下一个聚焦方向为前(请参阅 View 组件的文档)。
| 类型 |
|---|
| number |
nextFocusLeft Android
TV 下一个聚焦方向为左(请参阅 View 组件的文档)。
| 类型 |
|---|
| number |
nextFocusRight Android
TV 下一个聚焦方向为右(请参阅 View 组件的文档)。
| 类型 |
|---|
| number |
nextFocusUp Android
TV 下一个聚焦方向为上(请参阅 View 组件的文档)。
| 类型 |
|---|
| number |
方法
SelectableBackground()
static SelectableBackground(
rippleRadius: number | null,
): ThemeAttributeBackgroundPropType;
创建一个表示 Android 主题中可选元素默认背景的对象(?android:attr/selectableItemBackground)。rippleRadius 参数控制 ripple 效果的半径。
SelectableBackgroundBorderless()
static SelectableBackgroundBorderless(
rippleRadius: number | null,
): ThemeAttributeBackgroundPropType;
创建一个表示 Android 主题中无边框可选元素默认背景的对象(?android:attr/selectableItemBackgroundBorderless)。可在 Android API 21 及以上版本使用。rippleRadius 参数控制 ripple 效果的半径。
Ripple()
static Ripple(
color: ColorValue,
borderless: boolean,
rippleRadius?: number | null,
): RippleBackgroundPropType;
创建一个表示指定颜色(字符串形式)ripple drawable 的对象。如果属性 borderless 为 true,ripple 将在视图边界之外渲染(例如原生 actionbar 按钮就表现出这种行为)。此背景类型在 Android API 21 及以上版本可用。
参数:
| 名称 | 类型 | 必需 | 描述 |
|---|---|---|---|
| color | string | 是 | ripple 颜色 |
| borderless | boolean | 是 | ripple 是否可以在其边界之外渲染 |
| rippleRadius | ?number | 否 | 控制 ripple 效果的半径 |
canUseNativeForeground()
static canUseNativeForeground(): boolean;