Home React Native Outside Press
React Native Outside Press
Cancel

React Native Outside Press

Project Information

airbnb/react-outside-click-handler but for React Native.

Usage

Wrap your app with EventProvider.

1
2
3
4
5
6
7
8
9
import { EventProvider } from 'react-native-outside-press';

export default function App() {
  return (
    <EventProvider style={{ flex: 1 }}>
      <RestOfYourApp />
    </EventProvider>
  );
}

Then wrap every component you want with OutsidePressHandler to detect outside press.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
import { View } from 'react-native';
import OutsidePressHandler from 'react-native-outside-press';

export default function MyComponent() {
  return (
    <OutsidePressHandler
      onOutsidePress={() => {
        console.log('Pressed outside the box!');
      }}
    >
      <View style={{ height: 200, width: 200, backgroundColor: 'black' }} />
    </OutsidePressHandler>
  );
}