
Security News
Browserslist-rs Gets Major Refactor, Cutting Binary Size by Over 1MB
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
react-native-html5-loader
Advanced tools
Mini library to help you easily integrate existing web library into React Native
Mini library to help you easily integrate existing web library into React Native!
npm install --save react-native-html5-loader
This is indeed a mini library, but it offers some good stuff to you:
postMessage
. The message format is redux like: type
and payload
, so you won't need to manually stringify or parse anything youself.avoid the possible race condition between WebView and React Native
, since there're running in their own JS runtimewrite JS function for web directly in your React Native project
(NOTICE: es5 syntax only)Please see examples
directory, we have provided 3 examples for now:
Counter
exampleSignaturePad
js libraryThreeJs
to show 3D objectLet's use a simple Counter
example to explain the usage.
What we want to accomplish is:
WebView
React Native
side.The full code is here, very short and clean:
import React, {Component} from 'react';
import {View, Text, TouchableOpacity, WebView} from 'react-native';
import Html5Loader from 'react-native-html5-loader';
export default class App extends Component {
render() {
return (
<Html5Loader
head={`
<style>
body { margin:0; padding: 20px; }
h1 { font-size: 100px; }
</style>
`}
body={`
<h1>0</h1>
`}
webHandler={function webHandler(action, callRN, window) {
var count = parseInt(window.document.querySelector('h1').innerHTML, 10);
if (action.type === 'inc') {
window.document.querySelector('h1').innerHTML = (count + 1);
} else if (action.type === 'dec') {
window.document.querySelector('h1').innerHTML = (count - 1);
}
callRN('ack', 'message ' + action.type + ' received')
}}
rnHandler={(action, callWeb) => console.log(action.type, action.payload)}
>
{({callWeb, webViewProps}) => (
<View style={{flex: 1}}>
<WebView
{...webViewProps}
style={{flex: 1, alignSelf: 'stretch'}}
/>
<View style={{flexDirection: 'row', height: 60, justifyContent: 'space-around'}}>
<TouchableOpacity onPress={() => callWeb('inc', null)}>
<Text>+1</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => callWeb('dec', null)}>
<Text>-1</Text>
</TouchableOpacity>
</View>
</View>
)}
</Html5Loader>
);
}
}
string
): will be injected into the <head>
section of WebView HTML.string
): will be injected into the <body>
section of WebView HTML.es5 function
): the code to execute inside Web when receiving message from React Native side. The signature:
{type, payload}
callRN
also has two positional params type
(string) and payload
(any)window
object for WebView.function
): the code to execute inside RN when receiving message from Web side. The signature:
{type, payload}
callWeb
also has two positional params type
(string) and payload
(any)This library uses render props pattern
and the props.children
should be a function returning JSX
, with a single param which is an object containing following properties:
callWeb
also has two positional params type
(string) and payload
(any)WebView
, use spread operator to pass those props to let the magic happen!Welcome!
FAQs
Mini library to help you easily integrate existing web library into React Native
The npm package react-native-html5-loader receives a total of 5 weekly downloads. As such, react-native-html5-loader popularity was classified as not popular.
We found that react-native-html5-loader demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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
Browserslist-rs now uses static data to reduce binary size by over 1MB, improving memory use and performance for Rust-based frontend tools.
Research
Security News
Eight new malicious Firefox extensions impersonate games, steal OAuth tokens, hijack sessions, and exploit browser permissions to spy on users.
Security News
The official Go SDK for the Model Context Protocol is in development, with a stable, production-ready release expected by August 2025.