From 9923d3fa6f9d691557ce561327f0cc039179f0c2 Mon Sep 17 00:00:00 2001 From: Jonathan Ballerano Date: Fri, 8 Apr 2016 17:16:33 -0700 Subject: [PATCH] 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 --- React/Views/RCTWebView.m | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/React/Views/RCTWebView.m b/React/Views/RCTWebView.m index 48307674f..3e6c16928 100644 --- a/React/Views/RCTWebView.m +++ b/React/Views/RCTWebView.m @@ -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