From bb0f97e4349a592350c5c6ea80eb4a5f15f78e32 Mon Sep 17 00:00:00 2001 From: Louis Lagrange Date: Sat, 1 Aug 2020 16:37:07 +0800 Subject: [PATCH] Upgrade Prettier and add Travis --- .prettierignore | 4 +++ .travis.yml | 14 ++++++++ README.md | 21 ++++++++---- docs/stories/index.js | 4 +-- docs/stories/onMessage.html | 66 ++++++++++++++++++------------------- package.json | 4 +-- src/index.js | 12 +++---- src/postMock.html | 14 ++++---- yarn.lock | 8 ++--- 9 files changed, 84 insertions(+), 63 deletions(-) create mode 100644 .prettierignore create mode 100644 .travis.yml diff --git a/.prettierignore b/.prettierignore new file mode 100644 index 0000000..8df5f5d --- /dev/null +++ b/.prettierignore @@ -0,0 +1,4 @@ +node_modules +package.json +gift.json +dist diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..3bf0e80 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,14 @@ +language: node_js +node_js: + - '12' +install: + - yarn --frozen-lockfile +script: yarn test +cache: + directories: + - node_modules +env: + matrix: + - CI=true TZ=Europe/Paris +notifications: + email: false diff --git a/README.md b/README.md index 1a8d83f..42f9be5 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,9 @@ # react-native-web-webview + > React Native for Web implementation of RN's WebView ## Getting started + `$ npm install react-native-web-webview --save` Alias the package in your webpack config: @@ -31,6 +33,7 @@ const rule = { ``` ## Usage + ```js import { WebView } from 'react-native-webview'; ``` @@ -38,6 +41,7 @@ import { WebView } from 'react-native-webview'; See [RN's doc](https://github.com/react-native-community/react-native-webview). Supported props are: + - `source` - `onMessage` - `scrollEnabled` @@ -45,16 +49,19 @@ Supported props are: - `style` Additional, web-specific props are: -- `newWindow`: (*boolean*|*{ name: string, features: string}*) -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). -By default, the name is `webview` and there are no features set. -This is useful when your target has X-Frame-Options or a no-CORS policy. -It currently only supports a `source` prop with a `method` set to `POST`. -Please feel free to do a PR to support more request types! -- `title`: (*string*) This prop will set the `webview` title. + +- `newWindow`: (_boolean_|_{ name: string, features: string}_) + 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). + By default, the name is `webview` and there are no features set. + This is useful when your target has X-Frame-Options or a no-CORS policy. + It currently only supports a `source` prop with a `method` set to `POST`. + Please feel free to do a PR to support more request types! +- `title`: (_string_) This prop will set the `webview` title. ## Examples + See the [storybook](https://react-native-web-community.github.io/react-native-web-webview/storybook). ## Contributing + PRs are welcome! diff --git a/docs/stories/index.js b/docs/stories/index.js index 370ebfd..e39f4d0 100644 --- a/docs/stories/index.js +++ b/docs/stories/index.js @@ -7,8 +7,6 @@ import { storiesOf } from '@storybook/react'; storiesOf('HTML source', module).add('basic', html.basic); -storiesOf('URI source', module) - .add('basic', uri.basic) - .add('onMessage', uri.onMessage); +storiesOf('URI source', module).add('basic', uri.basic).add('onMessage', uri.onMessage); storiesOf('With method', module).add('basic', method.basic); diff --git a/docs/stories/onMessage.html b/docs/stories/onMessage.html index c91761f..e48f079 100644 --- a/docs/stories/onMessage.html +++ b/docs/stories/onMessage.html @@ -1,38 +1,38 @@ - -

Hello world!

- - - + + diff --git a/package.json b/package.json index 0585cd0..c190d25 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "scripts": { "prepublish": "yarn build", "build": "mkdir -p dist && babel src --out-dir dist --copy-files", - "test": "echo \"Error: no test specified\" && exit 1" + "test": "prettier --check ." }, "babel": { "presets": [ @@ -40,7 +40,7 @@ "babel-loader": "^7.1.2", "babel-preset-react-native": "^4.0.0", "file-loader": "^1.1.4", - "prettier": "^1.7.3", + "prettier": "^2.0.5", "react": "^16.0.0", "react-dom": "^16.0.0", "react-native-web": "^0.1.1", diff --git a/src/index.js b/src/index.js index 7c2814a..1c5d65c 100644 --- a/src/index.js +++ b/src/index.js @@ -14,7 +14,7 @@ export class WebView extends Component { this.handleSource(props.source, props.newWindow); } - setRef = ref => this.frameRef = ref; + setRef = (ref) => (this.frameRef = ref); handleSource = (source, newWindow) => { if (!source.method) return; @@ -26,12 +26,12 @@ export class WebView extends Component { } }; - handleSourceInIFrame = source => { + handleSourceInIFrame = (source) => { const { uri, ...options } = source; const baseUrl = uri.substr(0, uri.lastIndexOf('/') + 1); fetch(uri, options) - .then(response => response.text()) - .then(html => this.setState({ html: `` + html })); + .then((response) => response.text()) + .then((html) => this.setState({ html: `` + html })); }; handleSourceInNewWindow = (source, newWindow) => { @@ -88,13 +88,13 @@ export class WebView extends Component { } } - onMessage = nativeEvent => this.props.onMessage({ nativeEvent }); + onMessage = (nativeEvent) => this.props.onMessage({ nativeEvent }); postMessage = (message, origin) => { this.frameRef.contentWindow.postMessage(message, origin); }; - handleInjectedJavaScript = html => { + handleInjectedJavaScript = (html) => { if (this.props.injectedJavaScript) { if (html) { return html.replace('', ``); diff --git a/src/postMock.html b/src/postMock.html index da1d583..09b3fd1 100644 --- a/src/postMock.html +++ b/src/postMock.html @@ -1,8 +1,8 @@ - - - - + diff --git a/yarn.lock b/yarn.lock index 8b28f16..a41fae8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2109,10 +2109,10 @@ preserve@^0.2.0: resolved "https://registry.yarnpkg.com/preserve/-/preserve-0.2.0.tgz#815ed1f6ebc65926f865b310c0713bcb3315ce4b" integrity sha1-gV7R9uvGWSb4ZbMQwHE7yzMVzks= -prettier@^1.7.3: - version "1.7.3" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.7.3.tgz#8e6974725273914b1c47439959dd3d3ba53664b6" - integrity sha1-jml0clJzkUscR0OZWd09O6U2ZLY= +prettier@^2.0.5: + version "2.0.5" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.0.5.tgz#d6d56282455243f2f92cc1716692c08aa31522d4" + integrity sha512-7PtVymN48hGcO4fGjybyBSIWDsLU4H4XlvOHfq91pz9kkGlonzwTfYkaIEwiRg/dAJF9YlbsduBAgtYLi+8cFg== private@^0.1.6, private@^0.1.7: version "0.1.7"