react-native-webview-android
Simple React Native Android module to use Android's WebView inside your app (with experimental html file upload input support).
![npm licence](http://img.shields.io/npm/l/react-native-webview-android.svg?style=flat-square)
Installation
npm install react-native-webview-android --save
Add it to your android project
- In
android/setting.gradle
...
include ':RNWebView', ':app'
project(':RNWebView').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-webview-android/android')
- In
android/app/build.gradle
...
dependencies {
...
compile project(':RNWebView')
}
- Register Module - RN >= 0.18 (in MainActivity.java)
import com.burnweb.rnwebview.RNWebViewPackage;
public class MainActivity extends ReactActivity {
......
@Override
protected List<ReactPackage> getPackages() {
return Arrays.<ReactPackage>asList(
new MainReactPackage(),
new RNWebViewPackage());
}
......
}
Example
var React = require('react-native');
var { StyleSheet } = React;
var WebViewAndroid = require('react-native-webview-android');
var SITE_URL = "https://www.google.com";
var WebViewAndroidExample = React.createClass({
getInitialState: function() {
return {
url: SITE_URL,
status: 'No Page Loaded',
backButtonEnabled: false,
forwardButtonEnabled: false,
loading: true,
};
},
goBack: function() {
this.refs.webViewAndroidSample.goBack();
},
goForward: function() {
this.refs.webViewAndroidSample.goForward();
},
reload: function() {
this.refs.webViewAndroidSample.reload();
},
onNavigationStateChange: function(event) {
console.log(event);
this.setState({
backButtonEnabled: event.canGoBack,
forwardButtonEnabled: event.canGoForward,
url: event.url,
status: event.title,
loading: event.loading
});
},
render: function() {
return (
<WebViewAndroid
ref="webViewAndroidSample"
javaScriptEnabled={true}
geolocationEnabled={false}
builtInZoomControls={false}
onNavigationStateChange={this.onNavigationStateChange}
url={SITE_URL} // or use the source(object) attribute...
style={styles.containerWebView} />
);
}
});
var styles = StyleSheet.create({
containerWebView: {
flex: 1,
}
});
Tips for Video (HTML5) inside WebView
To work with some html5 video player inside your Webview, I recommend you to set the android:hardwareAccelerated="true" in your AndroidManifest.xml file.
More info here: http://stackoverflow.com/questions/17259636/enabling-html5-video-playback-in-android-webview
License
MIT