0.1.20 • Published 10 months ago

react-native-outside v0.1.20

Weekly downloads
-
License
MIT
Repository
github
Last release
10 months ago

react-native-outside

React components for react-native click outside

For a react-dom version, check out react-dom-outside

Example 1: Active Component

import { forwardRef } from "react",
import { View } from "react-native",
import { Active } from "react-native-outside";
import { EventProvider } from "react-native-event";

const Component = forwardRef(({ isActive, setIsActive }, ref) => {
  return (
    <View ref={ref}>
      <Text testID="text">{isActive ? 'active' : 'not active'}</Text>
      <TouchableOpacity
        testID="toggle"
        onPress={function () {
          setIsActive(!isActive);
        }}
      />
    </View>
  );
});

export default function App() {
  return (
    <EventProvider>
      <Active>
        <Component />
      </Active>
      <Active>
        <Component />
      </Active>
    </EventProvider>
  );
}

Example 1: Active Boundary Component

import { forwardRef } from "react",
import { View } from "react-native",
import { Active } from "react-native-outside";
import { EventProvider } from "react-native-event";
import { PortalProvider, Portal } from '@gorhom/portal';
import { useRef as useBoundaryRef } from 'react-ref-boundary';

// a modal for example outside the hierarchy
const PortalComponent = () => {
  const ref = useBoundaryRef(null); // react-ref-boundary ref
  return (
    <Portal>
      <TouchableOpacity
        ref={ref}
        testID="portal-click"
        onPress={() => { /* this click will not inactivate due to react-ref-boundary ref */ }}
      />
    </Portal>
  );
}

// react-ref-boundary ref passed in
const Component = forwardRef(({ isActive, setIsActive }, ref) => {
  return (
    <View ref={ref}>
      <Text testID="text">{isActive ? 'active' : 'not active'}</Text>
      <TouchableOpacity
        testID="toggle"
        onPress={function () {
          setIsActive(!isActive);
        }}
      />
      <PortalComponent/>
    </View>
  );
});

export default function App() {
  return (
    <EventProvider>
      <Active>
        <Component />
      </Active>
      <Active>
        <Component />
      </Active>
    </EventProvider>
  );
}

Documentation

API Docs

0.1.20

10 months ago

0.1.10

12 months ago

0.1.11

12 months ago

0.1.12

12 months ago

0.1.13

12 months ago

0.1.14

11 months ago

0.1.15

11 months ago

0.1.16

11 months ago

0.1.17

11 months ago

0.1.7

12 months ago

0.1.18

11 months ago

0.1.9

12 months ago

0.1.4

12 months ago

0.1.6

12 months ago

0.1.5

12 months ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

3 years ago

0.1.0

3 years ago