How is HitRect used with Pressable in React Native?

1.4k Views Asked by At

We're planning on switching from TouchableOpacity to 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.

The Pressable documentation has no information about using HitRect. I've found references to HitRect elsewhere, but they also have no useful information.

Can anyone describe how one should implement HitRect with Pressable?

2

There are 2 best solutions below

0
On BEST ANSWER

You can set HitRect with hitSlop as the example given below

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

Ah, I found it. hitSlop is the property used to set the HitRect in a Pressable.