Skip to content

add: expo-click-outside.#1574

Merged
Simek merged 2 commits intoreact-native-community:mainfrom
w88975:main
Apr 8, 2025
Merged

add: expo-click-outside.#1574
Simek merged 2 commits intoreact-native-community:mainfrom
w88975:main

Conversation

@w88975
Copy link
Copy Markdown
Contributor

@w88975 w88975 commented Apr 7, 2025

📝 Why & how

Added a new library to support click outside behavior, just like on the web. It supports event passthrough and does not interfere with any existing events.

useClickOutside

A 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

Example

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>;
}

ClickOutsideView

  • A component wrapper that provides outside click detection.
type ClickOutsideViewProps = ViewProps & {
  onOutsideClick?: (info: {
    x: number;
    y: number;
    targetIsTextInput: boolean;
    target: string;
  }) => void;
};

Example

import { ClickOutsideView } from 'expo-click-outside';

function MyComponent() {
  return (
    <ClickOutsideView
      onOutsideClick={(info) => {
        console.log('Clicked outside!', info);
      }}
    >
      <View>...</View>
    </ClickOutsideView>
  );
}

✅ Checklist

  • Added library to react-native-libraries.json
  • Updated library in react-native-libraries.json

Copy link
Copy Markdown
Member

@Simek Simek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @w88975, thanks for adding a new entry to the directory! 👍

@Simek Simek merged commit 72e932f into react-native-community:main Apr 8, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants