react-nativepressable

How is HitRect used with Pressable in React Native?


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?


Solution

  • You can set HitRect with hitSlop as the example given below

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