Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/SampleRN20/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ var React = require('react-native');
var {
StyleSheet,
Text,
View,
WebView
View
} = React;
var WebView = require('react-native-webview')
var createReactClass = require('create-react-class');

var WebViewBridge = require('react-native-webview-bridge');
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"create-react-class": "^15.6.0",
"invariant": "^2.2.2",
"keymirror": "0.1.1",
"prop-types": "^15.5.10"
"prop-types": "^15.5.10",
"react-native-webview": "^5.2.1"
}
}
40 changes: 20 additions & 20 deletions webview-bridge/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ var createReactClass = require('create-react-class');
var invariant = require('invariant');
var keyMirror = require('keymirror');
var resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource');
var WebView = require('react-native-webview');

var {
ReactNativeViewAttributes,
Expand All @@ -29,7 +30,6 @@ var {
Text,
View,
ViewPropTypes,
WebView,
requireNativeComponent,
DeviceEventEmitter,
NativeModules: {
Expand Down Expand Up @@ -61,16 +61,16 @@ var WebViewBridge = createReactClass({
onBridgeMessage: PropTypes.func,
},

getInitialState: function() {
getInitialState: function () {
return {
viewState: WebViewBridgeState.IDLE,
lastErrorEvent: null,
startInLoadingState: true,
};
},

componentWillMount: function() {

componentWillMount: function () {
DeviceEventEmitter.addListener("webViewBridgeMessage", (body) => {
const { onBridgeMessage } = this.props;
const message = body.message;
Expand All @@ -80,14 +80,14 @@ var WebViewBridge = createReactClass({
});

if (this.props.startInLoadingState) {
this.setState({viewState: WebViewBridgeState.LOADING});
this.setState({ viewState: WebViewBridgeState.LOADING });
}
},

render: function() {
render: function () {
var otherView = null;

if (this.state.viewState === WebViewBridgeState.LOADING) {
if (this.state.viewState === WebViewBridgeState.LOADING) {
otherView = this.props.renderLoading && this.props.renderLoading();
} else if (this.state.viewState === WebViewBridgeState.ERROR) {
var errorEvent = this.state.lastErrorEvent;
Expand All @@ -106,7 +106,7 @@ var WebViewBridge = createReactClass({
webViewStyles.push(styles.hidden);
}

var {javaScriptEnabled, domStorageEnabled} = this.props;
var { javaScriptEnabled, domStorageEnabled } = this.props;
if (this.props.javaScriptEnabledAndroid) {
console.warn('javaScriptEnabledAndroid is deprecated. Use javaScriptEnabled instead');
javaScriptEnabled = this.props.javaScriptEnabledAndroid;
Expand All @@ -116,13 +116,13 @@ var WebViewBridge = createReactClass({
domStorageEnabled = this.props.domStorageEnabledAndroid;
}

let {source, ...props} = {...this.props};
let { source, ...props } = { ...this.props };

var webView =
<RCTWebViewBridge
ref={RCT_WEBVIEWBRIDGE_REF}
key="webViewKey"
javaScriptEnabled={true}
javaScriptEnabled={true}
{...props}
source={resolveAssetSource(source)}
style={webViewStyles}
Expand All @@ -146,23 +146,23 @@ var WebViewBridge = createReactClass({
}
},

goForward: function() {
goForward: function () {
UIManager.dispatchViewManagerCommand(
this.getWebViewBridgeHandle(),
UIManager.RCTWebViewBridge.Commands.goForward,
null
);
},

goBack: function() {
goBack: function () {
UIManager.dispatchViewManagerCommand(
this.getWebViewBridgeHandle(),
UIManager.RCTWebViewBridge.Commands.goBack,
null
);
},

reload: function() {
reload: function () {
UIManager.dispatchViewManagerCommand(
this.getWebViewBridgeHandle(),
UIManager.RCTWebViewBridge.Commands.reload,
Expand All @@ -182,25 +182,25 @@ var WebViewBridge = createReactClass({
* We return an event with a bunch of fields including:
* url, title, loading, canGoBack, canGoForward
*/
updateNavigationState: function(event) {
updateNavigationState: function (event) {
if (this.props.onNavigationStateChange) {
this.props.onNavigationStateChange(event.nativeEvent);
}
},

getWebViewBridgeHandle: function() {
getWebViewBridgeHandle: function () {
return ReactNative.findNodeHandle(this.refs[RCT_WEBVIEWBRIDGE_REF]);
},

onLoadingStart: function(event) {
onLoadingStart: function (event) {
var onLoadStart = this.props.onLoadStart;
onLoadStart && onLoadStart(event);
this.updateNavigationState(event);
},

onLoadingError: function(event) {
onLoadingError: function (event) {
event.persist(); // persist this event because we need to store it
var {onError, onLoadEnd} = this.props;
var { onError, onLoadEnd } = this.props;
onError && onError(event);
onLoadEnd && onLoadEnd(event);

Expand All @@ -210,8 +210,8 @@ var WebViewBridge = createReactClass({
});
},

onLoadingFinish: function(event) {
var {onLoad, onLoadEnd} = this.props;
onLoadingFinish: function (event) {
var { onLoad, onLoadEnd } = this.props;
onLoad && onLoad(event);
onLoadEnd && onLoadEnd(event);
this.setState({
Expand Down
Loading