
Product
Introducing Repository Access Permissions and Custom Roles
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.
expo-click-outside
Advanced tools
A way to listen click outside of react-native (use native platform api).
A React Native Expo module for detecting clicks outside of specified components. Perfect for implementing dropdown menus, modals, and other interactive UI elements that need to respond to outside clicks.
npx expo install expo-click-outside
This module uses native code to listen for global touch events across the entire screen. When a touch event occurs, the module:
This approach is more reliable than JavaScript-only solutions and handles edge cases like clicks on native UI elements or status bars.
useClickOutsideA hook that detects clicks outside a specific component.
function useClickOutside(
ref: React.RefObject<View>,
callback: (info: {
x: number;
y: number;
targetIsTextInput: boolean;
target: string;
}) => void
): void
import { useClickOutside } from 'expo-click-outside';
function MyComponent() {
const ref = useRef<View>(null);
useClickOutside(ref, (info) => {
console.log('Clicked outside!', info);
});
return <View ref={ref}>...</View>;
}
ClickOutsideViewA component wrapper that provides outside click detection.
type ClickOutsideViewProps = ViewProps & {
onOutsideClick?: (info: {
x: number;
y: number;
targetIsTextInput: boolean;
target: string;
}) => void;
};
import { ClickOutsideView } from 'expo-click-outside';
function MyComponent() {
return (
<ClickOutsideView
onOutsideClick={(info) => {
console.log('Clicked outside!', info);
}}
>
<View>...</View>
</ClickOutsideView>
);
}
useListenerGlobalClickA hook that listens to all clicks in the app across the entire screen.
function useListenerGlobalClick(
callback: (info: {
x: number;
y: number;
targetIsTextInput: boolean;
target: string;
}) => void
): void
import { useListenerGlobalClick } from 'expo-click-outside';
function MyComponent() {
useListenerGlobalClick((info) => {
console.log('Click detected:', info);
});
return <View>...</View>;
}
All callbacks receive a click info object with the following properties:
x: number - The X coordinate of the click (in dp/pt units)y: number - The Y coordinate of the click (in dp/pt units)targetIsTextInput: boolean - Whether the click target was a text inputtarget: string - The identifier of the clicked elementDropdown Menus & Select Components
function Dropdown() {
const [isOpen, setIsOpen] = useState(false);
return (
<ClickOutsideView
onOutsideClick={() => setIsOpen(false)}
>
<View>
<Button onPress={() => setIsOpen(!isOpen)} title="Toggle" />
{isOpen && <View>Dropdown content...</View>}
</View>
</ClickOutsideView>
);
}
Modal Dialogs & Popups
function Modal() {
const modalRef = useRef(null);
const [visible, setVisible] = useState(true);
useClickOutside(modalRef, () => {
setVisible(false);
});
return visible ? (
<View style={styles.overlay}>
<View ref={modalRef} style={styles.modal}>
Modal content...
</View>
</View>
) : null;
}
Context Menus
function ContextMenu() {
const [position, setPosition] = useState({ x: 0, y: 0 });
const [visible, setVisible] = useState(false);
const menuRef = useRef(null);
useClickOutside(menuRef, () => setVisible(false));
const handleLongPress = (event) => {
setPosition({
x: event.nativeEvent.locationX,
y: event.nativeEvent.locationY
});
setVisible(true);
};
return (
<View onLongPress={handleLongPress} style={styles.container}>
{visible && (
<View
ref={menuRef}
style={[styles.menu, { left: position.x, top: position.y }]}
>
Context menu items...
</View>
)}
</View>
);
}
Tooltip Dismissal
function Tooltip() {
const [showTooltip, setShowTooltip] = useState(false);
const tooltipRef = useRef(null);
useClickOutside(tooltipRef, () => setShowTooltip(false));
return (
<View>
<Button onPress={() => setShowTooltip(true)} title="Show Info" />
{showTooltip && (
<View ref={tooltipRef} style={styles.tooltip}>
Helpful information...
</View>
)}
</View>
);
}
Form Dismissal on Outside Click
function SearchForm() {
const [expanded, setExpanded] = useState(false);
const formRef = useRef(null);
useClickOutside(formRef, () => {
setExpanded(false);
});
return (
<View ref={formRef} style={expanded ? styles.expandedForm : styles.collapsedForm}>
<TextInput
placeholder="Search..."
onFocus={() => setExpanded(true)}
/>
{expanded && (
<View style={styles.searchSuggestions}>
Search suggestions and filters...
</View>
)}
</View>
);
}
ClickOutsideView are set to collapsable={false} to ensure accurate measurementMIT
FAQs
A way to listen click outside of react-native (use native platform api).
The npm package expo-click-outside receives a total of 156 weekly downloads. As such, expo-click-outside popularity was classified as not popular.
We found that expo-click-outside demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.

Product
Socket Firewall blocks malicious VS Code and Open VSX extensions before install, protecting developers from compromised editor marketplaces.