react-native-contains
Check whether one element or native view contains another element or native tag.
Install
npm install react react-native react-native-contains
Use
import { useRef } from "react";
import { Pressable, View } from "react-native";
import contains from "react-native-contains";
function Component() {
const ref = useRef(null);
return (
<View>
<View ref={ref}>
<Pressable onPress={(event) => {
console.log(contains(ref.current, event.target)); // true
}} />
</View>
<Pressable onPress={(event) => {
console.log(contains(ref.current, event.target)); // false
}} />
</View>
);
}