TouchableNativeFeedback
如果你正在寻找更广泛且面向未来的方法来处理基于触摸的输入,请查看 Pressable API。
¥If you're looking for a more extensive and future-proof way to handle touch-based input, check out the Pressable API.
用于使视图正确响应触摸的封装器(仅限 Android)。在 Android 上,该组件使用原生状态可绘制来显示触摸反馈。
¥A wrapper for making views respond properly to touches (Android only). On Android this component uses native state drawable to display touch feedback.
目前,它仅支持将单个 View 实例作为子节点,因为它是通过用设置了一些附加属性的 RCTView 节点的另一个实例替换该 View 来实现的。
¥At the moment it only supports having a single View instance as a child node, as it's implemented by replacing that View with another instance of RCTView node with some additional properties set.
原生反馈可触摸的背景可绘制可以使用 background
属性进行自定义。
¥Background drawable of native feedback touchable can be customized with background
property.
示例
¥Example
参考
¥Reference
属性
¥Props
TouchableWithoutFeedback 属性
¥TouchableWithoutFeedback Props
继承 TouchableWithoutFeedback 属性。
¥Inherits TouchableWithoutFeedback Props.
background
确定将用于显示反馈的背景可绘制对象的类型。它需要一个具有 type
属性的对象和取决于 type
的额外数据。建议使用其中一种静态方法来生成该字典。
¥Determines the type of background drawable that's going to be used to display feedback. It takes an object with type
property and extra data depending on the type
. It's recommended to use one of the static methods to generate that dictionary.
类型 |
---|
backgroundPropType |
useForeground
设置为 true 可将波纹效果添加到视图的前景而不是背景。如果你的子视图之一有自己的背景,或者你是例如 显示图片,并且你不希望波纹被它们覆盖。
¥Set to true to add the ripple effect to the foreground of the view, instead of the background. This is useful if one of your child views has a background of its own, or you're e.g. displaying images, and you don't want the ripple to be covered by them.
首先检查 TouchableNativeFeedback.canUseNativeForeground(),因为这仅适用于 Android 6.0 及更高版本。如果你尝试在旧版本上使用此功能,你将收到警告并退回到后台。
¥Check TouchableNativeFeedback.canUseNativeForeground() first, as this is only available on Android 6.0 and above. If you try to use this on older versions you will get a warning and fallback to background.
类型 |
---|
bool |
hasTVPreferredFocus
Android
TV 首选焦点(请参阅 View 组件的文档)。
¥TV preferred focus (see documentation for the View component).
类型 |
---|
bool |
nextFocusDown
Android
接下来电视焦点向下(请参阅查看组件的文档)。
¥TV next focus down (see documentation for the View component).
类型 |
---|
number |
nextFocusForward
Android
TV 下一个焦点向前(请参阅 View 组件的文档)。
¥TV next focus forward (see documentation for the View component).
类型 |
---|
number |
nextFocusLeft
Android
TV 的下一个焦点向左(请参阅 View 组件的文档)。
¥TV next focus left (see documentation for the View component).
类型 |
---|
number |
nextFocusRight
Android
电视下一个焦点向右(请参阅查看组件的文档)。
¥TV next focus right (see documentation for the View component).
类型 |
---|
number |
nextFocusUp
Android
接下来聚焦电视(请参阅查看组件的文档)。
¥TV next focus up (see documentation for the View component).
类型 |
---|
number |
方法
¥Methods
SelectableBackground()
static SelectableBackground(
rippleRadius: number | null,
): ThemeAttributeBackgroundPropType;
创建一个代表可选元素 (?android:attr/selectableItemBackground
) 的 Android 主题默认背景的对象。rippleRadius
参数控制波纹效果的半径。
¥Creates an object that represents android theme's default background for selectable elements (?android:attr/selectableItemBackground
). rippleRadius
parameter controls the radius of the ripple effect.
SelectableBackgroundBorderless()
static SelectableBackgroundBorderless(
rippleRadius: number | null,
): ThemeAttributeBackgroundPropType;
创建一个代表无边框可选元素 (?android:attr/selectableItemBackgroundBorderless
) 的 Android 主题默认背景的对象。适用于 Android API 级别 21+。rippleRadius
参数控制波纹效果的半径。
¥Creates an object that represent android theme's default background for borderless selectable elements (?android:attr/selectableItemBackgroundBorderless
). Available on android API level 21+. rippleRadius
parameter controls the radius of the ripple effect.
Ripple()
static Ripple(
color: ColorValue,
borderless: boolean,
rippleRadius?: number | null,
): RippleBackgroundPropType;
创建一个对象,该对象表示具有指定颜色的可绘制波纹(作为字符串)。如果属性 borderless
的计算结果为 true,波纹将渲染在视图边界之外(请参阅原生操作栏按钮作为该行为的示例)。此背景类型可在 Android API 级别 21+ 上使用。
¥Creates an object that represents ripple drawable with specified color (as a string). If property borderless
evaluates to true the ripple will render outside of the view bounds (see native actionbar buttons as an example of that behavior). This background type is available on Android API level 21+.
参数:
¥Parameters:
名称 | 类型 | 必需的 | 描述 |
---|---|---|---|
color | string | 是的 | 波纹颜色 |
borderless | boolean | 是的 | 如果波纹可以渲染到其边界之外 |
rippleRadius | ?数字 | 不 | 控制波纹效果的半径 |
canUseNativeForeground()
static canUseNativeForeground(): boolean;