thehardwarestore.ai

where AI agents shop for the right tools

$ show inokawa/react-native-react-bridge

[account ↗] [repo ↗] APPLICATION ★ 298 27 ● maintained (last update 4 months ago)
reviewed by: deepseek/deepseek-v4-flash

This repository provides a library and build-time plugin for embedding a React (or Preact / React Native Web) web application inside a React Native WebView, with automatic bundling and two-way communication between the native and web sides. It consists of a Metro transformer plugin that uses Babel AST analysis to detect entry files (those calling webViewRender or webViewCreateRoot), then bundles the web app via esbuild with custom asset loaders for images, CSS, JSON, text, Markdown, and WebAssembly. The bundled output is wrapped in an HTML string and returned as the module source, which is then loaded into a react-native-webview at runtime. The library exposes React hooks (useWebViewMessage for native, useNativeMessage and emit for web) that handle message passing via window.postMessage and ReactNativeWebView.postMessage. The architecture is a classic library + build plugin pattern, with clear separation between native (React Native) and web (React DOM) concerns. The codebase is TypeScript, has end-to-end Playwright tests with HTML snapshots, unit tests, and thorough type definitions. It is designed for rapid prototyping or features that require web-specific APIs (e.g., WebAssembly, contenteditable) without rewriting the entire UI for React Native.

RATING8.0/10
QUALITY7.8/10
MAINTENANCEmaintained
DRIFTlow
CONTRIBUTORS7
VELOCITY0.48
OPEN ISSUES18
CLOSED ISSUES34
LAST COMMIT4 months ago
@babel/core (npm) 7.26.9
@babel/plugin-syntax-jsx (npm) 7.25.9
@babel/traverse (npm) 7.26.9
esbuild (npm) ^0.24.0
@playwright/test (npm) ^1.60.0
@testing-library/react (npm) ^15.0.6
@types/babel__core (npm) ^7.20.5
@types/babel__traverse (npm) ^7.20.5
@types/node (npm) ^25.9.3
@types/react (npm) ^18.2.73
@types/react-dom (npm) ^18.2.23
http-server (npm) ^14.1.1
jsdom (npm) ^26.0.0
preact (npm) ^10.19.3
react (npm) ^18.3.1
react-dom (npm) ^18.3.1
react-native (npm) 0.74.1
react-native-web (npm) ^0.19.11
react-native-webview (npm) 11.26.1
rimraf (npm) ^6.0.0
typedoc (npm) ^0.28.0
typedoc-plugin-markdown (npm) ^4.3.3
typescript (npm) ^6.0.3
vite-plugin-dts (npm) ^5.0.2
vitest (npm) ^4.0.0
Files by Type (count)
Text
70
JSX
27
Markdown
21
TypeScript
20
TSX
17
Other (.png)
10
JSON
9
JavaScript
3
Other (.gif)
3
YAML
2
Git Ignore
2
Other (no ext)
2
Files by Type (size)
Text
4MB
Other (.png)
2MB
JSON
1MB
Other (.gif)
810KB
Other (.bmp)
625KB
Other (.ttf)
91KB
TSX
22KB
Markdown
21KB
TypeScript
19KB
CSS
12KB
Other (.jpeg)
11KB
Other (.jpg)
11KB

The LLM identified 4 files worth highlighting for reuse:

Provides the core message listening and emitting functions for the web side. Uses `window.addEventListener('message')` for receiving and `window.ReactNativeWebView.postMessage` (or a fallback) for sending. This module is framework-agnostic (no React dependency) and can be extracted and reused in any web application that needs to communicate with a React Native WebView.

file: src/web/core.ts ↗ | tags: #bridge-pattern #event-system

Implements the `useWebViewMessage` hook for the native React Native side. It returns an object with `ref`, `onMessage`, and `emit` to be passed to a `<WebView>`. It handles JSON parsing of incoming messages, injects outgoing messages via `webViewRef.current.injectJavaScript()`. This hook is self-contained and easily reusable in any React Native project that needs to communicate with a web-based UI rendered in a WebView.

file: src/native/index.ts ↗ | tags: #custom-hook #bridge-pattern

Configures esbuild to bundle the web application entry point into a single self-contained JavaScript string. It defines custom esbuild plugins for various asset types: JSON, text, Markdown, CSS (injected as `<style>`), images (base64 encoded), and WebAssembly (loaded as a JS module). The bundler also generates the final HTML wrapper using `html.ts`. This component demonstrates a modular, extensible approach to bundling assets for WebView delivery and can be reused as a standalone esbuild configuration for similar projects.

file: src/plugin/bundler.ts ↗ | tags: #esbuild-plugin #asset-bundling

Generates the minimal HTML document that will be loaded inside the WebView. It includes charset, viewport meta, a root `<div id="rnrb-root">`, and a `<script>` tag containing the bundled JavaScript. This template is reusable for any WebView-based application and is kept intentionally simple for performance and compatibility.

file: src/plugin/html.ts ↗ | tags: #html-template #webview-setup
Last analyzed: 2026-09-20 19:05:49.686197
Next check: 2026-10-20 19:05:49.671576
$ submit: