Skip to content

Commit d3ca3c5

Browse files
authored
Upgrade Prettier and add Travis (#34)
1 parent a690113 commit d3ca3c5

File tree

9 files changed

+84
-63
lines changed

9 files changed

+84
-63
lines changed

.prettierignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
node_modules
2+
package.json
3+
gift.json
4+
dist

.travis.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
language: node_js
2+
node_js:
3+
- '12'
4+
install:
5+
- yarn --frozen-lockfile
6+
script: yarn test
7+
cache:
8+
directories:
9+
- node_modules
10+
env:
11+
matrix:
12+
- CI=true TZ=Europe/Paris
13+
notifications:
14+
email: false

README.md

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# react-native-web-webview
2+
23
> React Native for Web implementation of RN's WebView
34
45
## Getting started
6+
57
`$ npm install react-native-web-webview --save`
68

79
Alias the package in your webpack config:
@@ -31,30 +33,35 @@ const rule = {
3133
```
3234

3335
## Usage
36+
3437
```js
3538
import { WebView } from 'react-native-webview';
3639
```
3740

3841
See [RN's doc](https://github.com/react-native-community/react-native-webview).
3942

4043
Supported props are:
44+
4145
- `source`
4246
- `onMessage`
4347
- `scrollEnabled`
4448
- `injectedJavaScript`
4549
- `style`
4650

4751
Additional, web-specific props are:
48-
- `newWindow`: (*boolean*|*{ name: string, features: string}*)
49-
This will open the source in a new window, optionally giving it an [internal name and custom features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open).
50-
By default, the name is `webview` and there are no features set.
51-
This is useful when your target has X-Frame-Options or a no-CORS policy.
52-
It currently only supports a `source` prop with a `method` set to `POST`.
53-
Please feel free to do a PR to support more request types!
54-
- `title`: (*string*) This prop will set the `webview` title.
52+
53+
- `newWindow`: (_boolean_|_{ name: string, features: string}_)
54+
This will open the source in a new window, optionally giving it an [internal name and custom features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open).
55+
By default, the name is `webview` and there are no features set.
56+
This is useful when your target has X-Frame-Options or a no-CORS policy.
57+
It currently only supports a `source` prop with a `method` set to `POST`.
58+
Please feel free to do a PR to support more request types!
59+
- `title`: (_string_) This prop will set the `webview` title.
5560

5661
## Examples
62+
5763
See the [storybook](https://react-native-web-community.github.io/react-native-web-webview/storybook).
5864

5965
## Contributing
66+
6067
PRs are welcome!

docs/stories/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import { storiesOf } from '@storybook/react';
77

88
storiesOf('HTML source', module).add('basic', html.basic);
99

10-
storiesOf('URI source', module)
11-
.add('basic', uri.basic)
12-
.add('onMessage', uri.onMessage);
10+
storiesOf('URI source', module).add('basic', uri.basic).add('onMessage', uri.onMessage);
1311

1412
storiesOf('With method', module).add('basic', method.basic);

docs/stories/onMessage.html

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,38 @@
11
<html>
2-
<body>
3-
<h1>Hello world!</h1>
4-
<button id="button">Send message</button>
5-
<script type="text/javascript">
6-
// React Native
7-
function onBridgeReady(cb) {
8-
if (window.postMessage.length !== 1) {
9-
setTimeout(function() {
10-
onBridgeReady(cb)
11-
}, 100);
12-
} else {
13-
cb();
14-
}
15-
}
2+
<body>
3+
<h1>Hello world!</h1>
4+
<button id="button">Send message</button>
5+
<script type="text/javascript">
6+
// React Native
7+
function onBridgeReady(cb) {
8+
if (window.postMessage.length !== 1) {
9+
setTimeout(function () {
10+
onBridgeReady(cb);
11+
}, 100);
12+
} else {
13+
cb();
14+
}
15+
}
1616

17-
var payload = JSON.stringify({
18-
name: 'WebView',
19-
});
17+
var payload = JSON.stringify({
18+
name: 'WebView',
19+
});
2020

21-
document.getElementById('button').addEventListener('click', function() {
22-
if (window.opener) {
23-
// Web new window
24-
window.opener.postMessage(payload, window.opener.origin);
25-
window.close();
26-
} else if (window.parent) {
27-
// Web iframe
28-
window.parent.postMessage(payload, window.parent.origin);
29-
} else {
30-
// React Native
31-
onBridgeReady(function() {
32-
window.postMessage(payload);
21+
document.getElementById('button').addEventListener('click', function () {
22+
if (window.opener) {
23+
// Web new window
24+
window.opener.postMessage(payload, window.opener.origin);
25+
window.close();
26+
} else if (window.parent) {
27+
// Web iframe
28+
window.parent.postMessage(payload, window.parent.origin);
29+
} else {
30+
// React Native
31+
onBridgeReady(function () {
32+
window.postMessage(payload);
33+
});
34+
}
3335
});
34-
}
35-
});
36-
</script>
37-
</body>
36+
</script>
37+
</body>
3838
</html>

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"scripts": {
2323
"prepublish": "yarn build",
2424
"build": "mkdir -p dist && babel src --out-dir dist --copy-files",
25-
"test": "echo \"Error: no test specified\" && exit 1"
25+
"test": "prettier --check ."
2626
},
2727
"babel": {
2828
"presets": [
@@ -40,7 +40,7 @@
4040
"babel-loader": "^7.1.2",
4141
"babel-preset-react-native": "^4.0.0",
4242
"file-loader": "^1.1.4",
43-
"prettier": "^1.7.3",
43+
"prettier": "^2.0.5",
4444
"react": "^16.0.0",
4545
"react-dom": "^16.0.0",
4646
"react-native-web": "^0.1.1",

src/index.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export class WebView extends Component {
1414
this.handleSource(props.source, props.newWindow);
1515
}
1616

17-
setRef = ref => this.frameRef = ref;
17+
setRef = (ref) => (this.frameRef = ref);
1818

1919
handleSource = (source, newWindow) => {
2020
if (!source.method) return;
@@ -26,12 +26,12 @@ export class WebView extends Component {
2626
}
2727
};
2828

29-
handleSourceInIFrame = source => {
29+
handleSourceInIFrame = (source) => {
3030
const { uri, ...options } = source;
3131
const baseUrl = uri.substr(0, uri.lastIndexOf('/') + 1);
3232
fetch(uri, options)
33-
.then(response => response.text())
34-
.then(html => this.setState({ html: `<base href="${baseUrl}" />` + html }));
33+
.then((response) => response.text())
34+
.then((html) => this.setState({ html: `<base href="${baseUrl}" />` + html }));
3535
};
3636

3737
handleSourceInNewWindow = (source, newWindow) => {
@@ -88,13 +88,13 @@ export class WebView extends Component {
8888
}
8989
}
9090

91-
onMessage = nativeEvent => this.props.onMessage({ nativeEvent });
91+
onMessage = (nativeEvent) => this.props.onMessage({ nativeEvent });
9292

9393
postMessage = (message, origin) => {
9494
this.frameRef.contentWindow.postMessage(message, origin);
9595
};
9696

97-
handleInjectedJavaScript = html => {
97+
handleInjectedJavaScript = (html) => {
9898
if (this.props.injectedJavaScript) {
9999
if (html) {
100100
return html.replace('</body>', `<script>${this.props.injectedJavaScript}</script></body>`);

src/postMock.html

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<html>
2-
<body>
3-
<div id="content" style="display: none"></div>
4-
</body>
5-
<script>
2+
<body>
3+
<div id="content" style="display: none;"></div>
4+
</body>
5+
<script>
66
const source = new URLSearchParams(window.location.search);
77

88
let html = `<form method="POST" action="${source.get('uri')}">`;
@@ -11,13 +11,11 @@
1111

1212
Object.entries(params).forEach(([name, value]) => (html += `<input name="${name}" value="${value}" />`));
1313

14-
html +=
15-
"<input id='submit' type='submit' />" +
16-
"</form>";
14+
html += "<input id='submit' type='submit' />" + '</form>';
1715

1816
const div = document.createElement('div');
1917
div.innerHTML = html;
2018
document.getElementById('content').appendChild(div);
2119
document.getElementById('submit').click();
22-
</script>
20+
</script>
2321
</html>

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2109,10 +2109,10 @@ preserve@^0.2.0:
21092109
resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b"
21102110
integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks=
21112111

2112-
prettier@^1.7.3:
2113-
version "1.7.3"
2114-
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.3.tgz#8e6974725273914b1c47439959dd3d3ba53664b6"
2115-
integrity sha1-jml0clJzkUscR0OZWd09O6U2ZLY=
2112+
prettier@^2.0.5:
2113+
version "2.0.5"
2114+
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4"
2115+
integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg==
21162116

21172117
private@^0.1.6, private@^0.1.7:
21182118
version "0.1.7"

0 commit comments

Comments
 (0)