Skip to content

Commit c9d3783

Browse files
committed
Fix for Passing require('<SomeLocalURI>') to .source, results in “Error while updating property ‘source’ of a view managed by RCTWebViewBridge”. #61
1 parent 1f0b0cc commit c9d3783

File tree

4 files changed

+47
-2
lines changed

4 files changed

+47
-2
lines changed

examples/SampleRN20/app.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,29 @@ var Sample2 = React.createClass({
4444
},
4545
render: function() {
4646
return (
47+
<View style={styles.container}>
4748
<WebViewBridge
4849
ref="webviewbridge"
4950
onBridgeMessage={this.onBridgeMessage}
5051
javaScriptEnabled={true}
5152
injectedJavaScript={injectScript}
5253
source={{uri: "https://google.com"}}/>
54+
<WebViewBridge
55+
ref="webviewbridge"
56+
onBridgeMessage={this.onBridgeMessage}
57+
javaScriptEnabled={true}
58+
injectedJavaScript={injectScript}
59+
source={require('./test.html')}/>
60+
</View>
5361
);
5462
}
5563
});
5664

5765
module.exports = Sample2;
66+
67+
const styles = StyleSheet.create({
68+
container: {
69+
flex: 1
70+
}
71+
});
72+

examples/SampleRN20/test.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title></title>
5+
</head>
6+
<body>
7+
Hello test html
8+
</body>
9+
</html>

webview-bridge/index.android.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ var React = require('react-native');
1717
var invariant = require('invariant');
1818
var keyMirror = require('keymirror');
1919
var merge = require('merge');
20+
var resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource.js');
21+
2022

2123
var {
2224
ReactNativeViewAttributes,
@@ -110,11 +112,20 @@ var WebViewBridge = React.createClass({
110112
domStorageEnabled = this.props.domStorageEnabledAndroid;
111113
}
112114

115+
let props = {...this.props};
116+
var source = props.source || {};
117+
if(this.props.html) {
118+
source.html = this.props.html;
119+
} else if(this.props.url) {
120+
source.uri = this.props.url;
121+
}
122+
props.source = resolveAssetSource(source);
123+
113124
var webView =
114125
<RCTWebViewBridge
115126
ref={RCT_WEBVIEWBRIDGE_REF}
116127
key="webViewKey"
117-
{...this.props}
128+
{...props}
118129
style={webViewStyles}
119130
onLoadingStart={this.onLoadingStart}
120131
onLoadingFinish={this.onLoadingFinish}

webview-bridge/index.ios.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
var React = require('react-native');
1818
var invariant = require('invariant');
1919
var keyMirror = require('keymirror');
20+
var resolveAssetSource = require('react-native/Libraries/Image/resolveAssetSource.js');
2021

2122
var {
2223
ActivityIndicatorIOS,
@@ -174,10 +175,19 @@ var WebViewBridge = React.createClass({
174175
}
175176
};
176177

177-
const props = {...this.props};
178+
let props = {...this.props};
178179
delete props.onBridgeMessage;
179180
delete props.onShouldStartLoadWithRequest;
180181

182+
var source = props.source || {};
183+
if(this.props.html) {
184+
source.html = this.props.html;
185+
} else if(this.props.url) {
186+
source.uri = this.props.url;
187+
}
188+
props.source = resolveAssetSource(source);
189+
190+
181191
var webView =
182192
<RCTWebViewBridge
183193
ref={RCT_WEBVIEWBRIDGE_REF}

0 commit comments

Comments
 (0)