Skip to content

Commit e2ddd96

Browse files
flyskywhyMinishlink
authored andcommitted
Add support for injectedJavaScript, style.width and style.height (#14)
* Add support for injectedJavaScript * Add support for style.width and style.height * Fix injectedJavaScript when srcDoc is undefined * Fix injectedJavaScript() when this.props.injectedJavaScript is undefined * Refactor to handleInjectedJavaScript(). Refactor width and height. * width and height use the result of StyleSheet.flatten()
1 parent 4006e87 commit e2ddd96

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

src/index.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@ export default class extends Component {
8888

8989
onMessage = nativeEvent => this.props.onMessage({ nativeEvent });
9090

91+
handleInjectedJavaScript = html => {
92+
if (this.props.injectedJavaScript) {
93+
if (html) {
94+
return html.replace('</body>', `<script>${this.props.injectedJavaScript}</script></body>`);
95+
} else {
96+
return html;
97+
}
98+
} else {
99+
return html;
100+
}
101+
};
102+
91103
render() {
92104
if (this.props.newWindow) {
93105
return (
@@ -98,10 +110,13 @@ export default class extends Component {
98110
}
99111

100112
const { title, source, onLoad, scrollEnabled } = this.props;
113+
const styleObj = StyleSheet.flatten(this.props.style);
101114
return createElement('iframe', {
102115
title,
103116
src: !source.method ? source.uri : undefined,
104-
srcDoc: this.state.html || source.html,
117+
srcDoc: this.handleInjectedJavaScript(this.state.html || source.html),
118+
width: styleObj && styleObj.width,
119+
height: styleObj && styleObj.height,
105120
style: [styles.iframe, scrollEnabled && styles.noScroll],
106121
allowFullScreen: true,
107122
allowpaymentrequest: 'true',

0 commit comments

Comments
 (0)