Skip to content

Commit 70c22da

Browse files
committed
Merge branch 'feature/0.19-ios' into develop
2 parents d89f1da + 63b6d6a commit 70c22da

File tree

3 files changed

+96
-32
lines changed

3 files changed

+96
-32
lines changed

examples/Sample2/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"start": "react-native start"
77
},
88
"dependencies": {
9-
"react-native": "^0.16.0",
9+
"react-native": "^0.19.0",
1010
"react-native-webview-bridge": "../.."
1111
}
1212
}

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-webview-bridge",
3-
"version": "0.16.1",
3+
"version": "0.19.0",
44
"description": "React Native WebView Javascript Bridge",
55
"main": "webview-bridge",
66
"directories": {

webview-bridge/index.ios.js

Lines changed: 94 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
* Copyright (c) 2015-present, Facebook, Inc.
33
* All rights reserved.
44
*
5+
* Copyright (c) 2016-present, Ali Najafizadeh
6+
* All rights reserved.
7+
*
58
* This source code is licensed under the BSD-style license found in the
69
* LICENSE file in the root directory of this source tree. An additional grant
710
* of patent rights can be found in the PATENTS file in the same directory.
811
*
9-
* Copyright (c) 2015-present, Ali Najafizadeh (github.com/alinz)
10-
* All rights reserved
11-
*
1212
* @providesModule WebViewBridge
1313
* @flow
1414
*/
@@ -26,13 +26,16 @@ var {
2626
View,
2727
requireNativeComponent,
2828
PropTypes,
29+
UIManager,
2930
NativeModules: {
3031
WebViewBridgeManager
3132
}
3233
} = React;
3334

3435
var BGWASH = 'rgba(255,255,255,0.8)';
35-
var RCT_WEBVIEW_BRIDGE_REF = 'webviewbridge';
36+
var RCT_WEBVIEWBRIDGE_REF = 'webviewbridge';
37+
38+
var RCTWebViewBridgeManager = WebViewBridgeManager;
3639

3740
var WebViewBridgeState = keyMirror({
3841
IDLE: null,
@@ -41,15 +44,15 @@ var WebViewBridgeState = keyMirror({
4144
});
4245

4346
var NavigationType = {
44-
click: WebViewBridgeManager.NavigationType.LinkClicked,
45-
formsubmit: WebViewBridgeManager.NavigationType.FormSubmitted,
46-
backforward: WebViewBridgeManager.NavigationType.BackForward,
47-
reload: WebViewBridgeManager.NavigationType.Reload,
48-
formresubmit: WebViewBridgeManager.NavigationType.FormResubmitted,
49-
other: WebViewBridgeManager.NavigationType.Other,
47+
click: RCTWebViewBridgeManager.NavigationType.LinkClicked,
48+
formsubmit: RCTWebViewBridgeManager.NavigationType.FormSubmitted,
49+
backforward: RCTWebViewBridgeManager.NavigationType.BackForward,
50+
reload: RCTWebViewBridgeManager.NavigationType.Reload,
51+
formresubmit: RCTWebViewBridgeManager.NavigationType.FormResubmitted,
52+
other: RCTWebViewBridgeManager.NavigationType.Other,
5053
};
5154

52-
var JSNavigationScheme = WebViewBridgeManager.JSNavigationScheme;
55+
var JSNavigationScheme = RCTWebViewBridgeManager.JSNavigationScheme;
5356

5457
type ErrorEvent = {
5558
domain: any;
@@ -83,9 +86,6 @@ var defaultRenderError = (errorDomain, errorCode, errorDesc) => (
8386

8487
/**
8588
* Renders a native WebView.
86-
*
87-
* Note that WebView is only supported on iOS for now,
88-
* see https://facebook.github.io/react-native/docs/known-issues.html
8989
*/
9090
var WebViewBridge = React.createClass({
9191
statics: {
@@ -97,9 +97,37 @@ var WebViewBridge = React.createClass({
9797
...View.propTypes,
9898
url: PropTypes.string,
9999
html: PropTypes.string,
100+
/**
101+
* Function that returns a view to show if there's an error.
102+
*/
100103
renderError: PropTypes.func, // view to show if there's an error
101-
renderLoading: PropTypes.func, // loading indicator to show
104+
/**
105+
* Function that returns a loading indicator.
106+
*/
107+
renderLoading: PropTypes.func,
108+
/**
109+
* Invoked when load finish
110+
*/
111+
onLoad: PropTypes.func,
112+
/**
113+
* Invoked when load either succeeds or fails
114+
*/
115+
onLoadEnd: PropTypes.func,
116+
/**
117+
* Invoked on load start
118+
*/
119+
onLoadStart: PropTypes.func,
120+
/**
121+
* Invoked when load fails
122+
*/
123+
onError: PropTypes.func,
124+
/**
125+
* @platform ios
126+
*/
102127
bounces: PropTypes.bool,
128+
/**
129+
* @platform ios
130+
*/
103131
scrollEnabled: PropTypes.bool,
104132
automaticallyAdjustContentInsets: PropTypes.bool,
105133
contentInset: EdgeInsetsPropType,
@@ -108,10 +136,16 @@ var WebViewBridge = React.createClass({
108136
style: View.propTypes.style,
109137

110138
/**
111-
* Used for android only, JS is enabled by default for WebView on iOS
139+
* Used on Android only, JS is enabled by default for WebView on iOS
140+
* @platform android
141+
*/
142+
javaScriptEnabled: PropTypes.bool,
143+
144+
/**
145+
* Used on Android only, controls whether DOM Storage is enabled or not
112146
* @platform android
113147
*/
114-
javaScriptEnabledAndroid: PropTypes.bool,
148+
domStorageEnabled: PropTypes.bool,
115149

116150
/**
117151
* Sets the JS to be injected when the webpage loads.
@@ -184,19 +218,29 @@ var WebViewBridge = React.createClass({
184218
);
185219
}
186220

187-
var webViewBridgeStyles = [styles.container, styles.webViewBridge, this.props.style];
221+
var webViewStyles = [styles.container, styles.webView, this.props.style];
188222
if (this.state.viewState === WebViewBridgeState.LOADING ||
189223
this.state.viewState === WebViewBridgeState.ERROR) {
190224
// if we're in either LOADING or ERROR states, don't show the webView
191-
webViewBridgeStyles.push(styles.hidden);
225+
webViewStyles.push(styles.hidden);
192226
}
193227

194228
var onShouldStartLoadWithRequest = this.props.onShouldStartLoadWithRequest && ((event: Event) => {
195229
var shouldStart = this.props.onShouldStartLoadWithRequest &&
196230
this.props.onShouldStartLoadWithRequest(event.nativeEvent);
197-
WebViewBridgeManager.startLoadWithResult(!!shouldStart, event.nativeEvent.lockIdentifier);
231+
RCTWebViewBridgeManager.startLoadWithResult(!!shouldStart, event.nativeEvent.lockIdentifier);
198232
});
199233

234+
var {javaScriptEnabled, domStorageEnabled} = this.props;
235+
if (this.props.javaScriptEnabledAndroid) {
236+
console.warn('javaScriptEnabledAndroid is deprecated. Use javaScriptEnabled instead');
237+
javaScriptEnabled = this.props.javaScriptEnabledAndroid;
238+
}
239+
if (this.props.domStorageEnabledAndroid) {
240+
console.warn('domStorageEnabledAndroid is deprecated. Use domStorageEnabled instead');
241+
domStorageEnabled = this.props.domStorageEnabledAndroid;
242+
}
243+
200244
var onBridgeMessage = (event: Event) => {
201245
const onBridgeMessageCallback = this.props.onBridgeMessage;
202246
if (onBridgeMessageCallback) {
@@ -207,11 +251,11 @@ var WebViewBridge = React.createClass({
207251
}
208252
};
209253

210-
var webViewBridge =
254+
var webView =
211255
<RCTWebViewBridge
212-
ref={RCT_WEBVIEW_BRIDGE_REF}
213-
key="webViewBridgeKey"
214-
style={webViewBridgeStyles}
256+
ref={RCT_WEBVIEWBRIDGE_REF}
257+
key="webViewKey"
258+
style={webViewStyles}
215259
url={this.props.url}
216260
html={this.props.html}
217261
injectedJavaScript={this.props.injectedJavaScript}
@@ -230,22 +274,34 @@ var WebViewBridge = React.createClass({
230274

231275
return (
232276
<View style={styles.container}>
233-
{webViewBridge}
277+
{webView}
234278
{otherView}
235279
</View>
236280
);
237281
},
238282

239283
goForward: function() {
240-
WebViewBridgeManager.goForward(this.getWebViewBridgeHandle());
284+
UIManager.dispatchViewManagerCommand(
285+
this.getWebViewBridgeHandle(),
286+
UIManager.RCTWebViewBridge.Commands.goForward,
287+
null
288+
);
241289
},
242290

243291
goBack: function() {
244-
WebViewBridgeManager.goBack(this.getWebViewBridgeHandle());
292+
UIManager.dispatchViewManagerCommand(
293+
this.getWebViewBridgeHandle(),
294+
UIManager.RCTWebViewBridge.Commands.goBack,
295+
null
296+
);
245297
},
246298

247299
reload: function() {
248-
WebViewBridgeManager.reload(this.getWebViewBridgeHandle());
300+
UIManager.dispatchViewManagerCommand(
301+
this.getWebViewBridgeHandle(),
302+
UIManager.RCTWebViewBridge.Commands.reload,
303+
null
304+
);
249305
},
250306

251307
sendToBridge: function (message: string) {
@@ -263,15 +319,20 @@ var WebViewBridge = React.createClass({
263319
},
264320

265321
getWebViewBridgeHandle: function(): any {
266-
return React.findNodeHandle(this.refs[RCT_WEBVIEW_BRIDGE_REF]);
322+
return React.findNodeHandle(this.refs[RCT_WEBVIEWBRIDGE_REF]);
267323
},
268324

269325
onLoadingStart: function(event: Event) {
326+
var onLoadStart = this.props.onLoadStart;
327+
onLoadStart && onLoadStart(event);
270328
this.updateNavigationState(event);
271329
},
272330

273331
onLoadingError: function(event: Event) {
274332
event.persist(); // persist this event because we need to store it
333+
var {onError, onLoadEnd} = this.props;
334+
onError && onError(event);
335+
onLoadEnd && onLoadEnd(event);
275336
console.warn('Encountered an error loading page', event.nativeEvent);
276337

277338
this.setState({
@@ -281,6 +342,9 @@ var WebViewBridge = React.createClass({
281342
},
282343

283344
onLoadingFinish: function(event: Event) {
345+
var {onLoad, onLoadEnd} = this.props;
346+
onLoad && onLoad(event);
347+
onLoadEnd && onLoadEnd(event);
284348
this.setState({
285349
viewState: WebViewBridgeState.IDLE,
286350
});
@@ -326,7 +390,7 @@ var styles = StyleSheet.create({
326390
justifyContent: 'center',
327391
alignItems: 'center',
328392
},
329-
webViewBridge: {
393+
webView: {
330394
backgroundColor: '#ffffff',
331395
}
332396
});

0 commit comments

Comments
 (0)