Skip to content

Example of Create React Native App with a webview, and 2-way postMessage

License

Notifications You must be signed in to change notification settings

yanamal/Webview-Example

Repository files navigation

This is an almost1-minimal example of a create-react-native app with a full-screen webview2, set up so that the webview can communicate with the app itself by posting messages in both directions.

I pieced this together from a bunch of documentation and examples, which were neither minimal nor complete. That was a pretty painful process, so hopefully this will help someone avoid doing just that themselves.

The relevant files are:

  • App.js
  • WebviewScreen.js
  • WebviewContent/index.html

(The rest are unchanged3 from what create-react-native generates)

For simplicity, I kept some things together in the same files that probably ought to be brought out into separate files if you were doing it "properly" (e.g. home screen and app, webview style and webview itself).

This project was bootstrapped with Create React Native App.

The most recent version of the Create React Native App guide is available here.


1 I also threw in a StackNavigator to link together the home screen and the actual webview.

2 i.e. a view that renders arbitrary web-like HTML/CSS/JS within your app, which you can also dynamically load and change on the fly.

3 except this readme, and also package.json, which was automatically modified by running:

npm install --save react-navigation

About

Example of Create React Native App with a webview, and 2-way postMessage

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published