Utility library to handle outside touches in React Native. It provides components that trigger a callback when a touch-event is registered outside of themselves or their children.
Installing touch-outside only takes a single command and you're ready to roll:
# with npm
npm install --save react-native-touch-outside
# with yarn
yarn add react-native-touch-outside
- Wrap the
TouchAreaProvideron the root of your app. - Use
TouchOutsideView,TouchOutsidePressableor wrap your ownView-based component usingtouchOutside()and pass along theonTouchOutside-prop.
<TouchAreaProvider>
<Screen />
</TouchAreaProvider>A wrapper around any View-based component that registers the component for touchOutside events.
import { touchOutside } from "react-native-touch-outside";
const TouchOutsideView = touchOutside(View);
export const ExampleComponent = () => {
function handleTouchOutside(id: string) {
console.log("Pressed outside!");
}
return <TouchOutsideView onTouchOutside={handleTouchOutside} />;
};A convenience View component that registers the component for touchOutside events.
import { TouchOutsideView } from "react-native-touch-outside";
export const ExampleComponent = () => {
function handleTouchOutside(id: string) {
console.log("Pressed outside!");
}
return <TouchOutsideView onTouchOutside={handleTouchOutside} />;
};A convenience Pressable component that registers the component for touchOutside events.
import { TouchOutsidePressable } from "react-native-touch-outside";
export const ExampleComponent = () => {
function handleTouchOutside(id: string) {
console.log("Pressed outside!");
}
return <TouchOutsidePressable onTouchOutside={handleTouchOutside} />;
};