Skip to content

Commit 28758c6

Browse files
authored
Merge pull request #22 from jamespearson/master
Allow onMessage to be set and processed
2 parents 4550c52 + 98a5086 commit 28758c6

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

index.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
WebView,
1919
Platform,
2020
} from 'react-native';
21+
import PropTypes from "prop-types";
2122

2223
const injectedScript = function() {
2324
function waitForBridge() {
@@ -38,9 +39,14 @@ export default class MyWebView extends Component {
3839
webViewHeight: Number
3940
};
4041

42+
static propTypes = {
43+
onMessage: PropTypes.func
44+
};
45+
4146
static defaultProps = {
42-
autoHeight: true,
43-
}
47+
autoHeight: true,
48+
onMessage: () => {}
49+
};
4450

4551
constructor (props: Object) {
4652
super(props);
@@ -52,9 +58,11 @@ export default class MyWebView extends Component {
5258
}
5359

5460
_onMessage(e) {
61+
const { onMessage } = this.props;
5562
this.setState({
5663
webViewHeight: parseInt(e.nativeEvent.data)
5764
});
65+
onMessage(e);
5866
}
5967

6068
stopLoading() {
@@ -76,11 +84,11 @@ export default class MyWebView extends Component {
7684
ref={(ref) => { this.webview = ref; }}
7785
injectedJavaScript={Platform.OS === 'ios' ? iosScript : androidScript}
7886
scrollEnabled={this.props.scrollEnabled || false}
79-
onMessage={this._onMessage}
8087
javaScriptEnabled={true}
8188
automaticallyAdjustContentInsets={true}
8289
{...this.props}
83-
style={[{width: _w}, this.props.style, {height: _h}]}
90+
onMessage={this._onMessage}
91+
style={[{ width: _w }, this.props.style, { height: _h }]}
8492
/>
8593
)
8694
}

0 commit comments

Comments
 (0)