简体   繁体   English

HitRect 如何在 React Native 中与 Pressable 一起使用?

[英]How is HitRect used with Pressable in React Native?

We're planning on switching from TouchableOpacity to Pressable.我们计划从 TouchableOpacity 切换到 Pressable。

We want to use Pressable's optional HitRec to ensure our hit targets are appropriately sized (we'll calculate the dimensions) for accessibility purposes.我们希望使用 Pressable 的可选 HitRec 来确保我们的命中目标大小合适(我们将计算尺寸)以实现可访问性目的。

The Pressable documentation has no information about using HitRect. Pressable 文档没有关于使用 HitRect 的信息。 I've found references to HitRect elsewhere, but they also have no useful information.我在其他地方找到了对 HitRect 的引用,但它们也没有有用的信息。

Can anyone describe how one should implement HitRect with Pressable?谁能描述应该如何使用 Pressable 实现 HitRect?

You can set HitRect with hitSlop as the example given below您可以使用 hitSlop 设置 HitRect,如下例所示

<Pressable
       onPress={() => navigation.toggleDrawer()}
       hitSlop = {50} // to increase the clickable area
       >
                    Menu
</Pressable>

Ah, I found it.啊,我找到了。 hitSlop is the property used to set the HitRect in a Pressable. hitSlop是用于在 Pressable 中设置 HitRect 的属性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM