Skip to content

Commit 9057c53

Browse files
committed
Add newWindow prop
1 parent 16fa952 commit 9057c53

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Supported props are:
4444
- html
4545
- onMessage
4646

47+
Additional props are:
48+
- `newWindow`: this will open the source in a new window. Useful when your target has X-Frame-Options or a no-CORS policy.
49+
4750
## Examples
4851
See the [storybook](https://react-native-web-community.github.io/react-native-web-webview/storybook).
4952

src/index.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,37 @@ export default class extends Component {
66
constructor(props) {
77
super(props);
88

9-
if (props.source.method === 'POST') {
10-
const contentType = props.source.headers['Content-Type'];
11-
let body = '';
12-
if (contentType && contentType.includes('application/x-www-form-urlencoded')) {
13-
body = Qs.parse(props.source.body);
14-
} else {
15-
console.warn('[WebView] Content type is not supported yet, please make a PR!', contentType);
16-
return;
17-
}
9+
const { source } = props;
10+
if (source.method) {
11+
if (props.newWindow) {
12+
if (source.method === 'POST') {
13+
const contentType = source.headers['Content-Type'];
14+
let body = '';
15+
if (contentType && contentType.includes('application/x-www-form-urlencoded')) {
16+
body = Qs.parse(source.body);
17+
} else {
18+
console.warn(
19+
'[WebView] When opening a new window, this content-type is not supported yet, please make a PR!',
20+
contentType
21+
);
22+
return;
23+
}
1824

19-
window.open(
20-
require('./postMock.html') + '?' +
21-
Qs.stringify({
22-
uri: props.source.uri,
23-
body: JSON.stringify(body),
24-
})
25-
);
25+
window.open(
26+
require('./postMock.html') +
27+
'?' +
28+
Qs.stringify({
29+
uri: source.uri,
30+
body: JSON.stringify(body),
31+
})
32+
);
33+
} else {
34+
console.warn(
35+
'[WebView] When opening a new window, this method is not supported yet, please make a PR!',
36+
source.method
37+
);
38+
}
39+
}
2640
}
2741
}
2842

@@ -41,7 +55,7 @@ export default class extends Component {
4155
onMessage = nativeEvent => nativeEvent.isTrusted && this.props.onMessage({ nativeEvent });
4256

4357
render() {
44-
if (this.props.source.method === 'POST') {
58+
if (this.props.newWindow) {
4559
return (
4660
<View style={styles.loadingContainer}>
4761
<ActivityIndicator />

0 commit comments

Comments
 (0)