Use `loadRequest` instead of `reload` when initial load fails

Summary:On iOS, `WebView` will get stuck when the first request fails to load. The most common case where this could happen is when a user has limited or no connectivity.

Here's a repo with a sample app that demonstrates the problem and this fix: [https://github.com/jballer/react-native-webview-reload-example](https://github.com/jballer/react-native-webview-reload-example).

**Attempted workarounds**
- `WebView.reload()` fails internally because the `UIWebView`'s `currentRequest` doesn't have its `URL` set
- Setting `WebView.source.uri` won't do anything; the JS value value is unchanged and therefore doesn't cross the native bridge.
- Unmounting and remounting the `WebView` component would lose history and context if an error occurs on a request that's not the first request.

**Test plan (manual testing)**

1. Disable network connection
1. Relaunch application or reload JS
1. Enable network connection
1. Tap "reload" button
1. Observe whether page reloads
Closes https://github.com/facebook/react-native/pull/6873

Differential Revision: D3159219

Pulled By: javache

fb-gh-sync-id: 8893dd20dc9f4a1a00d14a488ce657cc50287a29
fbshipit-source-id: 8893dd20dc9f4a1a00d14a488ce657cc50287a29
This commit is contained in:
Jonathan Ballerano 2016-04-08 17:16:33 -07:00 committed by Facebook Github Bot 6
parent 66d5529ea4
commit 9923d3fa6f
1 changed files with 7 additions and 1 deletions

View File

@ -68,7 +68,13 @@ RCT_NOT_IMPLEMENTED(- (instancetype)initWithCoder:(NSCoder *)aDecoder)
- (void)reload
{
[_webView reload];
NSURLRequest *request = [RCTConvert NSURLRequest:self.source];
if (request.URL && !_webView.request.URL.absoluteString.length) {
[_webView loadRequest:request];
}
else {
[_webView reload];
}
}
- (void)setSource:(NSDictionary *)source