airbnb/react-outside-click-handler but for React Native.
iOS | Android | Web | Windows | macOS | Expo |
---|---|---|---|---|---|
✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
yarn add react-native-outside-press
Wrap your app with EventProvider
.
import { EventProvider } from 'react-native-outside-press';
export default function App() {
return (
<EventProvider>
<RestOfYourApp />
</EventProvider>
);
}
Name | Description | Type | Default | Required? |
---|---|---|---|---|
style |
ViewStyle | { flex: 1 } |
false |
|
ViewProps |
Inherits ViewProps. | ViewProps | false |
Wrap every component you want to detect outside press with OutsidePressHandler
.
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>
);
}
Name | Description | Type | Default | Required? |
---|---|---|---|---|
onOutsidePress |
Function to run when pressed outside of component. | function | true |
|
disabled |
Controls whether onOutsidePress should run or not. |
boolean | false |
false |
ViewProps |
Inherits ViewProps. | ViewProps | false |
See CHANGELOGS.md
Copyright © 2023 David Angulo, released under the MIT license, see LICENSE.