# dcangulo/react-native-outside-press architecture

> Architecture diagram of the GitHub repository dcangulo/react-native-outside-press, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dcangulo/react-native-outside-press
- Repository: https://github.com/dcangulo/react-native-outside-press

## Overview

##### Project type and purpose
- This is an open-source React Native UI utility library (“react-native-outside-press”) that provides two main components—EventProvider and OutsidePressHandler—to handle “press outside” events across iOS, Android, Web, Windows, macOS, and Expo.
- It is distributed as an NPM package, with a bundled example app under the /example folder.

##### File structure
- Top-level:
- CI/CD and repo metadata: .github/, lefthook.yml, CHANGELOGS.md, LICENSE
- Build & tooling: babel.config.js, tsconfig.json / tsconfig.build.json, webpack.config.js
- scripts/: bootstrap.js for wiring the example to the library
- src/: core library source
- src breakdown:
- components/: container.tsx, event-provider.tsx, outside-press-handler.tsx
- hooks/: use-event.ts, use-event-store.ts
- event-context.ts: React Context + in-memory event store
- utils/: deep-clone.ts
- index.ts: public entrypoint exporting components/hooks
- example/:
- A minimal React Native + Web demo that imports the local library via scripts/bootstrap.js
- Own babel.config, metro.config, webpack.config for cross-platform bundling

##### Extract architectural insights from README
- The library uses the React Context + custom Hooks pattern to broadcast global press events.
- EventProvider sits at the root to intercept all touch/press events; child OutsidePressHandler components subscribe and fire callbacks when an outer press is detected.
- No external microservices or databases—purely in-memory event dispatch.

##### Main components & interactions
- External React Native App (example or any consuming app)
- Wraps the entire view tree with EventProvider
- EventProvider
- Renders a top-level “touchable container” (container.tsx) that catches every press
- Updates eventContext (publish event to store)
- event-context
- Holds a list of active handler registrations
- Exposes subscribe/unsubscribe APIs
- OutsidePressHandler
- On unmount, deregisters
- On each global event, context invokes handlers whose region did not contain the press
- Hooks (use-event, use-event-store)
- Encapsulate context logic—subscribe, compute deepest handlers, manage re-renders
- Utils (deep-clone)
- Used internally to duplicate event objects safely

##### Architectural patterns & design principles
- Publish/Subscribe (Observer) via React Context + Hooks
- Separation of concerns:
- Event capturing (EventProvider)
- Event dispatch (event-context)
- Component registration (OutsidePressHandler)
- Consumer callback invocation
- Pure functional components; no class components
- TypeScript for strong typing and safe builds

## Diagram (Mermaid)

```mermaid
graph TD
    %% External App
    subgraph "React Native App" 
        direction TB
        App["App.tsx"]:::example
    end

    %% Example Scripts and Configs
    subgraph "Example & Scripts" 
        direction TB
        Bootstrap["bootstrap.js"]:::script
        BabelConfig["babel.config.js"]:::script
        MetroConfig["metro.config.js"]:::script
        WebpackConfig["webpack.config.js"]:::script
    end

    %% Library Package
    subgraph "react-native-outside-press (Library Package)" 
        direction TB
        Index["index.ts"]:::core
        subgraph "Components" 
            direction TB
            EventProvider["EventProvider"]:::core
            Container["TouchableContainer"]:::core
            OutsidePressHandler["OutsidePressHandler"]:::core
        end
        EventContext["event-context"]:::store
        subgraph "Hooks" 
            direction TB
            UseStore["useEventStore"]:::hooks
            UseEvent["useEvent"]:::hooks
        end
        DeepClone["deep-clone"]:::core
    end

    %% Connections
    App -->|"wraps with EventProvider"| EventProvider
    EventProvider -->|"renders"| Container
    Container -->|"onPress"| EventContext
    OutsidePressHandler -->|"subscribe() via"| UseStore
    UseStore -->|"updates registry in"| EventContext
    EventContext -->|"publishEvent()"| OutsidePressHandler
    OutsidePressHandler -->|"callback()"| App
    App -->|"import from package"| Index
    Bootstrap -->|"wires local lib into example"| Index
    Bootstrap -->|executes| App
    BabelConfig -->|configures| App
    MetroConfig -->|configures| App
    WebpackConfig -->|configures| App

    %% Click Events
    click EventProvider "https://github.com/dcangulo/react-native-outside-press/blob/main/src/components/event-provider.tsx"
    click OutsidePressHandler "https://github.com/dcangulo/react-native-outside-press/blob/main/src/components/outside-press-handler.tsx"
    click Container "https://github.com/dcangulo/react-native-outside-press/blob/main/src/components/container.tsx"
    click EventContext "https://github.com/dcangulo/react-native-outside-press/blob/main/src/event-context.ts"
    click UseStore "https://github.com/dcangulo/react-native-outside-press/blob/main/src/hooks/use-event-store.ts"
    click UseEvent "https://github.com/dcangulo/react-native-outside-press/blob/main/src/hooks/use-event.ts"
    click DeepClone "https://github.com/dcangulo/react-native-outside-press/blob/main/src/utils/deep-clone.ts"
    click Index "https://github.com/dcangulo/react-native-outside-press/blob/main/src/index.ts"
    click App "https://github.com/dcangulo/react-native-outside-press/blob/main/example/src/App.tsx"
    click Bootstrap "https://github.com/dcangulo/react-native-outside-press/blob/main/scripts/bootstrap.js"
    click BabelConfig "https://github.com/dcangulo/react-native-outside-press/blob/main/example/babel.config.js"
    click MetroConfig "https://github.com/dcangulo/react-native-outside-press/blob/main/example/metro.config.js"
    click WebpackConfig "https://github.com/dcangulo/react-native-outside-press/blob/main/example/webpack.config.js"

    %% Styles
    classDef core fill:#cce5ff,stroke:#004085,color:#004085;
    classDef store fill:#cce5ff,stroke:#004085,color:#004085,stroke-dasharray: 5 5;
    classDef hooks fill:#e2e3e5,stroke:#6c757d,color:#6c757d;
    classDef example fill:#d4edda,stroke:#155724,color:#155724;
    classDef script fill:#f8f9fa,stroke:#6c757d,color:#6c757d;
```
