How dcangulo/react-native-outside-press works
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