Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 20, 2026·3 min de lecture

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.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
WebView Overview
Commande d'installation directe
npx -y tokrepo@latest install 79a5f79e-83f4-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en 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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires