Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
react-native-webview
Advanced tools
React Native WebView component for iOS, Android, macOS, and Windows
The react-native-webview package is a powerful tool for embedding web content into a React Native application. It allows developers to render web pages, handle navigation, and interact with web content using JavaScript. This package is highly customizable and supports various features such as injecting JavaScript, handling navigation events, and more.
Basic WebView
This feature allows you to embed a basic web page within your React Native application. The WebView component takes a source prop that specifies the URL of the web page to be loaded.
import React from 'react';
import { WebView } from 'react-native-webview';
const MyWebView = () => (
<WebView
source={{ uri: 'https://www.example.com' }}
style={{ marginTop: 20 }}
/>
);
export default MyWebView;
Injecting JavaScript
This feature allows you to inject JavaScript into the web page being loaded. The injectedJavaScript prop takes a string of JavaScript code that will be executed once the page has loaded.
import React from 'react';
import { WebView } from 'react-native-webview';
const MyWebView = () => (
<WebView
source={{ uri: 'https://www.example.com' }}
injectedJavaScript={"document.body.style.backgroundColor = 'red';"}
style={{ marginTop: 20 }}
/>
);
export default MyWebView;
Handling Navigation Events
This feature allows you to handle navigation events within the WebView. The onNavigationStateChange prop takes a function that will be called whenever the navigation state changes, providing details about the navigation event.
import React from 'react';
import { WebView } from 'react-native-webview';
const MyWebView = () => (
<WebView
source={{ uri: 'https://www.example.com' }}
onNavigationStateChange={(navState) => {
console.log('Navigation state changed:', navState);
}}
style={{ marginTop: 20 }}
/>
);
export default MyWebView;
The react-native-inappbrowser-reborn package allows you to open web content in an in-app browser. It provides a more native feel compared to a WebView and supports features like custom animations and toolbar customization. However, it is not as flexible as react-native-webview for embedding web content directly within your application.
React Native WebView is a community-maintained WebView component for React Native. It is intended to be a replacement for the built-in WebView (which was removed from core).
Many thanks to these companies for providing us with time to work on open source.
Please note that maintainers spend a lot of free time working on this too so feel free to sponsor them, it really makes a difference.
Windows and macOS are managed by Microsoft, notably:
Shout-out to Jamon Holmgren from Infinite Red for helping a lot with the repo when he had more available time.
Maintaining WebView is very complex because it is often used for many different use cases (rendering SVGs, PDFs, login flows, and much more). We also support many platforms and both architectures of react-native.
Since WebView was extracted from the React Native core, nearly 500 pull requests have been merged.
Considering that we have limited time, issues will mostly serve as a discussion place for the community, while we will prioritize reviewing and merging pull requests.
This project is compatible with iOS, Android, Windows and macOS.
This project supports both the old (paper) and the new architecture (fabric).
This project is compatible with expo.
Read our Getting Started Guide. If any step seems unclear, please create a pull request.
This project follows semantic versioning. We do not hesitate to release breaking changes but they will be in a major version.
Import the WebView
component from react-native-webview
and use it like so:
import React, { Component } from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { WebView } from 'react-native-webview';
// ...
const MyWebComponent = () => {
return <WebView source={{ uri: 'https://reactnative.dev/' }} style={{ flex: 1 }} />;
}
For more, read the API Reference and Guide. If you're interested in contributing, check out the Contributing Guide.
Invariant Violation: Native component for "RNCWebView does not exist"
it likely means you forgot to run react-native link
or there was some error with the linking process:app:mergeDexRelease
, you need to enable multidex support in android/app/build.gradle
as discussed in this issueContributions are welcome, see Contributing.md
MIT
This readme is available in:
FAQs
React Native WebView component for iOS, Android, macOS, and Windows
The npm package react-native-webview receives a total of 663,904 weekly downloads. As such, react-native-webview popularity was classified as popular.
We found that react-native-webview demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.