Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsJul 20, 2026·3 min de lectura

React Native WebView — Embed Web Content in Mobile Apps

A cross-platform WebView component for React Native that renders web pages, local HTML, and JavaScript bridges inside iOS and Android apps with full navigation control and message passing between native and web layers.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
WebView Overview
Comando de instalación directa
npx -y tokrepo@latest install 79a5f79e-83f4-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

react-native-webview is the community-maintained replacement for the built-in WebView that was removed from React Native core. It wraps WKWebView on iOS and the Chromium-based WebView on Android, providing a consistent API for embedding web content with native-to-web communication.

What React Native WebView Does

  • Renders remote URLs, local HTML strings, and bundled HTML files inside a native view
  • Provides bidirectional message passing between React Native and embedded JavaScript
  • Supports custom headers, cookies, user agents, and authentication challenges
  • Handles file uploads, downloads, and camera/microphone permission prompts
  • Exposes navigation events (load start, load end, error, redirect) via callbacks

Architecture Overview

The component creates a platform-native web view (WKWebView on iOS, android.webkit.WebView on Android) and manages its lifecycle through the React Native bridge. The injectedJavaScript prop executes scripts after page load, and window.ReactNativeWebView.postMessage() sends data from web to native. On the native side, onMessage receives these payloads as React events.

Self-Hosting & Configuration

  • Set javaScriptEnabled (default true) and domStorageEnabled for web app compatibility
  • Use injectedJavaScriptBeforeContentLoaded for early script injection before DOM renders
  • Configure originWhitelist to control which URLs the WebView is allowed to navigate to
  • Set mixedContentMode on Android to handle HTTP content inside HTTPS pages
  • Enable allowFileAccess and allowFileAccessFromFileURLs for local file loading

Key Features

  • Native-to-web bridge via postMessage and onMessage for seamless data exchange
  • Custom error and loading views via renderError and renderLoading render props
  • Download handling with onFileDownload callback for iOS and automatic handling on Android
  • Pull-to-refresh support via pullToRefreshEnabled prop
  • Basic authentication support via onHttpError and custom header injection

Comparison with Similar Tools

  • expo-web-browser — opens URLs in an external browser; WebView embeds content inline
  • InAppBrowser — in-app browser overlay; WebView is a fully embeddable React component
  • iframe (web) — web-only; react-native-webview provides native container with bridge APIs
  • Custom Tabs (Android) — Chrome-powered browser tab; WebView offers tighter integration

FAQ

Q: How do I communicate between React Native and web content? A: Inject JavaScript with injectedJavaScript, and use window.ReactNativeWebView.postMessage() to send data back. Handle it with the onMessage prop.

Q: Can I intercept navigation requests? A: Yes. Use onShouldStartLoadWithRequest to inspect and allow or block URL navigations.

Q: Does it support cookies? A: Yes. The sharedCookiesEnabled prop shares cookies with native HTTP clients. Use CookieManager for manual cookie management.

Q: Can I render local HTML files? A: Yes. Use source={{ html: '<h1>Hello</h1>' }} for inline HTML or source={{ uri: 'file:///...' }} for bundled files.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados