From 4a4ccd814143840edd11cd43bc1a629618019f24 Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Mon, 4 Feb 2019 14:13:14 +0100 Subject: [PATCH 1/9] fix(android/iOS): Fixed react-native 0.58 warnings (#311) --- js/WebView.android.js | 16 +++++++++------- js/WebView.ios.js | 11 ++++------- package.json | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/js/WebView.android.js b/js/WebView.android.js index defef94..3c6d22f 100644 --- a/js/WebView.android.js +++ b/js/WebView.android.js @@ -194,10 +194,12 @@ class WebView extends React.Component { ); } + getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands; + goForward = () => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RNCWebView.Commands.goForward, + this.getCommands().goForward, null, ); }; @@ -205,7 +207,7 @@ class WebView extends React.Component { goBack = () => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RNCWebView.Commands.goBack, + this.getCommands().goBack, null, ); }; @@ -216,7 +218,7 @@ class WebView extends React.Component { }); UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RNCWebView.Commands.reload, + this.getCommands().reload, null, ); }; @@ -224,7 +226,7 @@ class WebView extends React.Component { stopLoading = () => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RNCWebView.Commands.stopLoading, + this.getCommands().stopLoading, null, ); }; @@ -232,7 +234,7 @@ class WebView extends React.Component { postMessage = (data: string) => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RNCWebView.Commands.postMessage, + this.getCommands().postMessage, [String(data)], ); }; @@ -246,7 +248,7 @@ class WebView extends React.Component { injectJavaScript = (data: string) => { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RNCWebView.Commands.injectJavaScript, + this.getCommands().injectJavaScript, [data], ); }; @@ -311,7 +313,7 @@ class WebView extends React.Component { if (shouldStart) { UIManager.dispatchViewManagerCommand( this.getWebViewHandle(), - UIManager.RNCWebView.Commands.loadUrl, + this.getCommands().loadUrl, [String(url)], ); } diff --git a/js/WebView.ios.js b/js/WebView.ios.js index 88adb79..6cb2cee 100644 --- a/js/WebView.ios.js +++ b/js/WebView.ios.js @@ -289,13 +289,10 @@ class WebView extends React.Component { ); } - _getCommands() { - if (!this.props.useWebKit) { - return UIManager.RNCUIWebView.Commands; - } - - return UIManager.RNCWKWebView.Commands; - } + _getCommands = () => + !this.props.useWebKit + ? UIManager.getViewManagerConfig('RNCUIWebView').Commands + : UIManager.getViewManagerConfig('RNCWKWebView').Commands; /** * Go forward one page in the web view's history. diff --git a/package.json b/package.json index 1abea80..8639d33 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,7 @@ "flow-bin": "^0.80.0", "jest": "^24.0.0", "metro-react-native-babel-preset": "^0.51.1", - "react-native": "^0.57", + "react-native": ">=0.57 <0.59", "semantic-release": "15.10.3" }, "repository": { From 0535c04c117fadc98f57af26b7dd4e8fcac0e86f Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 4 Feb 2019 13:14:47 +0000 Subject: [PATCH 2/9] chore(release): 5.0.3 [skip ci] ## [5.0.3](https://github.com/react-native-community/react-native-webview/compare/v5.0.2...v5.0.3) (2019-02-04) ### Bug Fixes * **android/iOS:** Fixed react-native 0.58 warnings ([#311](https://github.com/react-native-community/react-native-webview/issues/311)) ([4a4ccd8](https://github.com/react-native-community/react-native-webview/commit/4a4ccd8)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 8639d33..40b3d00 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "Thibault Malbranche " ], "license": "MIT", - "version": "5.0.2", + "version": "5.0.3", "homepage": "https://github.com/react-native-community/react-native-webview#readme", "scripts": { "test:js": "jest", From 4c8024047b3a3641d38cf8f378cdbb149c1f5c15 Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Mon, 4 Feb 2019 18:58:48 +0100 Subject: [PATCH 3/9] fix(UIWebview): Deprecate UIWebView and add link to issue (#313) * Update WebView.ios.js * Update WebView.ios.js --- js/WebView.ios.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/js/WebView.ios.js b/js/WebView.ios.js index 6cb2cee..385aadd 100644 --- a/js/WebView.ios.js +++ b/js/WebView.ios.js @@ -41,7 +41,7 @@ import type { } from './WebViewTypes'; const resolveAssetSource = Image.resolveAssetSource; - +let didWarnAboutUIWebViewUsage = false; // Imported from https://github.com/facebook/react-native/blob/master/Libraries/Components/ScrollView/processDecelerationRate.js function processDecelerationRate(decelerationRate) { if (decelerationRate === 'normal') { @@ -153,6 +153,13 @@ class WebView extends React.Component { webViewRef = React.createRef(); UNSAFE_componentWillMount() { + if (!this.props.useWebKit && !didWarnAboutUIWebViewUsage) { + didWarnAboutUIWebViewUsage = true; + console.warn( + 'UIWebView is deprecated and will be removed soon, please use WKWebView (do not override useWebkit={true} prop),' + + ' more infos here: https://github.com/react-native-community/react-native-webview/issues/312', + ); + } if ( this.props.useWebKit === true && this.props.scalesPageToFit !== undefined From 0fe45de8790f1e940fe71bcb099717fc9a66ac64 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 4 Feb 2019 18:00:23 +0000 Subject: [PATCH 4/9] chore(release): 5.0.4 [skip ci] ## [5.0.4](https://github.com/react-native-community/react-native-webview/compare/v5.0.3...v5.0.4) (2019-02-04) ### Bug Fixes * **UIWebview:** Deprecate UIWebView and add link to issue ([#313](https://github.com/react-native-community/react-native-webview/issues/313)) ([4c80240](https://github.com/react-native-community/react-native-webview/commit/4c80240)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 40b3d00..2a14274 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "Thibault Malbranche " ], "license": "MIT", - "version": "5.0.3", + "version": "5.0.4", "homepage": "https://github.com/react-native-community/react-native-webview#readme", "scripts": { "test:js": "jest", From a4c6f210cfd3b9eab17423c2c08c525200b6881a Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Tue, 5 Feb 2019 15:15:02 +0100 Subject: [PATCH 5/9] Update README.md --- README.md | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 6641698..038eae8 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,6 @@ _Garrett McCullough, mobile engineer at Virta Health_ - [x] iOS (both UIWebView and WKWebView) - [x] Android -- [ ] Windows 10 (coming soon) _Note: React Native WebView is not currently supported by Expo unless you "eject"._ @@ -19,6 +18,8 @@ _Note: React Native WebView is not currently supported by Expo unless you "eject If you need the exact same WebView as the one from react-native, please use version **2.0.0**. Future versions will follow [semantic versioning](https://semver.org/). +Please note that version >= 5.0.3 only support **react-native >=0.58** + ## Getting Started ``` @@ -44,7 +45,6 @@ class MyWebComponent extends Component { console.log(e.nativeEvent.progress)} /> ); } @@ -61,16 +61,9 @@ Simply install React Native WebView and then use it in place of the core WebView - If you're getting `Invariant Violation: Native component for "RNCWKWebView does not exist"` it likely means you forgot to run `react-native link` or there was some error with the linking process -### Contributor Notes +## Contributing -- I've removed all PropTypes for now. Instead, we'll be using Flow types. TypeScript types will be added at a later date. -- UIWebView is not tested fully and you will encounter some yellow warning boxes. Since it is deprecated, we don't intend to put a lot of time into supporting it, but feel free to submit PRs if you have a special use case. Note that you will need to specify `useWebKit={false}` to use UIWebView -- After pulling this repo and installing all dependencies, you can run flow on iOS and Android-specific files using the commands: - - `yarn test:ios:flow` for iOS - - `yarn test:android:flow` for Android -- If you want to add another React Native platform to this repository, you will need to create another `.flowconfig` for it. If your platform is `example`, copy the main flowconfig and rename it to `.flowconfig.example`. Then edit the config to ignore other platforms, and add `.*/*[.]example.js` to the ignore lists of the other platforms. Then add an entry to `package.json` like this: - - `"test:example:flow": "flow check --flowconfig-name .flowconfig.example"` -- Currently you need to install React Native 0.57 to be able to test these types - `flow check` will not pass against 0.56. +See [Contributing.md](https://github.com/react-native-community/react-native-webview/blob/master/docs/Contributing.md) ## Maintainers From 263fc5ec3c4216e94ebba076a2d8ea7559e96f6d Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Tue, 5 Feb 2019 15:50:40 +0100 Subject: [PATCH 6/9] fix(iOS/android getViewManagerConfig): Fix crash with react-native < 0.58 --- js/WebView.android.js | 9 ++++++++- js/WebView.ios.js | 11 +++++++++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/js/WebView.android.js b/js/WebView.android.js index 3c6d22f..c057381 100644 --- a/js/WebView.android.js +++ b/js/WebView.android.js @@ -194,7 +194,14 @@ class WebView extends React.Component { ); } - getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands; + getViewManagerConfig = viewManagerName => { + if (!UIManager.getViewManagerConfig) { + return UIManager[viewManagerName]; + } + return UIManager.getViewManagerConfig(viewManagerName); + }; + + getCommands = () => this.getViewManagerConfig('RNCWebView').Commands; goForward = () => { UIManager.dispatchViewManagerCommand( diff --git a/js/WebView.ios.js b/js/WebView.ios.js index 385aadd..0387236 100644 --- a/js/WebView.ios.js +++ b/js/WebView.ios.js @@ -296,10 +296,17 @@ class WebView extends React.Component { ); } + _getViewManagerConfig = viewManagerName => { + if (!UIManager.getViewManagerConfig) { + return UIManager[viewManagerName]; + } + return UIManager.getViewManagerConfig(viewManagerName); + }; + _getCommands = () => !this.props.useWebKit - ? UIManager.getViewManagerConfig('RNCUIWebView').Commands - : UIManager.getViewManagerConfig('RNCWKWebView').Commands; + ? this._getViewManagerConfig('RNCUIWebView').Commands + : this._getViewManagerConfig('RNCWKWebView').Commands; /** * Go forward one page in the web view's history. From 5000bde5fd3a13761f91f69028444fca04c01870 Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Tue, 5 Feb 2019 15:51:16 +0100 Subject: [PATCH 7/9] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 038eae8..318f273 100644 --- a/README.md +++ b/README.md @@ -18,8 +18,6 @@ _Note: React Native WebView is not currently supported by Expo unless you "eject If you need the exact same WebView as the one from react-native, please use version **2.0.0**. Future versions will follow [semantic versioning](https://semver.org/). -Please note that version >= 5.0.3 only support **react-native >=0.58** - ## Getting Started ``` From 6c26a892b467b22659eaf51a38a6b4f5b594b828 Mon Sep 17 00:00:00 2001 From: Thibault Malbranche Date: Tue, 5 Feb 2019 15:56:34 +0100 Subject: [PATCH 8/9] updated type for ViewManagerName --- js/WebView.android.js | 2 +- js/WebView.ios.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/js/WebView.android.js b/js/WebView.android.js index c057381..ec959ee 100644 --- a/js/WebView.android.js +++ b/js/WebView.android.js @@ -194,7 +194,7 @@ class WebView extends React.Component { ); } - getViewManagerConfig = viewManagerName => { + getViewManagerConfig = (viewManagerName: string) => { if (!UIManager.getViewManagerConfig) { return UIManager[viewManagerName]; } diff --git a/js/WebView.ios.js b/js/WebView.ios.js index 0387236..b724b5a 100644 --- a/js/WebView.ios.js +++ b/js/WebView.ios.js @@ -296,7 +296,7 @@ class WebView extends React.Component { ); } - _getViewManagerConfig = viewManagerName => { + _getViewManagerConfig = (viewManagerName: string) => { if (!UIManager.getViewManagerConfig) { return UIManager[viewManagerName]; } From a76e0ae811b3bba0b27380bf9e0c91e0f1cb559f Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Tue, 5 Feb 2019 14:59:05 +0000 Subject: [PATCH 9/9] chore(release): 5.0.5 [skip ci] ## [5.0.5](https://github.com/react-native-community/react-native-webview/compare/v5.0.4...v5.0.5) (2019-02-05) ### Bug Fixes * **iOS/android getViewManagerConfig:** Fix crash with react-native < 0.58 ([263fc5e](https://github.com/react-native-community/react-native-webview/commit/263fc5e)) --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2a14274..c8504b2 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "Thibault Malbranche " ], "license": "MIT", - "version": "5.0.4", + "version": "5.0.5", "homepage": "https://github.com/react-native-community/react-native-webview#readme", "scripts": { "test:js": "jest",