fix(whitelisted origins): Prevent handling of un-whitelisted URLs
* Preventing an unhandled promise rejection when: a URL is loaded by the WebView, but the URL isn't in the origin whitelist, so it is handed off to the OS to handle by calling Linking.openURL(), but Linking.openURL has an error. The code wasn't catching the error, so this would result in an unhandled promise rejection. Now the error is being caught.
* Fixing a problem where a URL is handled to the OS to deal with, via Linking.openURL, and also loaded in the WebView by making those cases mutually exclusive (they weren't previously). In more detail: when a URL is loaded by the WebView that isn't in the origin whitelist it is handled off to the OS to handle by calling Linking.openURL. But, if the onShouldStartLoadWithRequest prop is set, then that function would also be called, and then that would determine whether the URL should be loaded. This can result in a situation where the URL is passed to Linking.openURL and onShouldStartLoadWithRequest returns true so it is also loaded in the WebView. The client can fix this by duplicating the origin whitelist logic in their onShouldStartLoadWithRequest of course, but this change makes it so they don't have to.
Co-authored-by: Jason Safaiyeh <safaiyeh@protonmail.com>
# [8.0.0](https://github.com/react-native-community/react-native-webview/compare/v7.6.0...v8.0.0) (2019-12-16)
### Features
* **ios:** Generate history API events on iOS ([#1082](https://github.com/react-native-community/react-native-webview/issues/1082)) ([3615296](https://github.com/react-native-community/react-native-webview/commit/3615296))
### BREAKING CHANGES
* **ios:** if you use onNavigationStateChange on iOS it will now trigger on # changes to the url.
* Hook the `window.history` API on iOS to generate events
The underlying WKWebView doesn't seem to generate any events in response to the `window.history` API - none of the `WKNavigationDelegate` methods fire.
Given this limitation, the only way to know when the location changes via this API is to inject Javascript into the page and have it notify the native code directly when any of these functions are called.
The `setTimeout` call gives up the current tick, allowing the location to change before firing the event.
* Remove the outdated section about hash changes
Now that this bug is fixed, the workaround is no longer required.
feat(ios): Generate history API events on iOS (#1082)
BREAKING CHANGE: if you use onNavigationStateChange on iOS it will now trigger on # changes to the url.
* Hook the `window.history` API on iOS to generate events
The underlying WKWebView doesn't seem to generate any events in response to the `window.history` API - none of the `WKNavigationDelegate` methods fire.
Given this limitation, the only way to know when the location changes via this API is to inject Javascript into the page and have it notify the native code directly when any of these functions are called.
The `setTimeout` call gives up the current tick, allowing the location to change before firing the event.
* Remove the outdated section about hash changes
Now that this bug is fixed, the workaround is no longer required.
chore(docs): Steps to load local HTML files into the webview (#1008)
Fixes #746
These steps are based on my other project React native draftjs which requires loading a local HTML file. The code can be found in the following line - bc51410117/index.js (L113)