I'm working on a React Native app that uses a WebView as the app's main screen.
When the app comes from the background to the foreground the WebView reloads. How can I stop this reloading?
This answer suggests loading the WebView in ViewDidLoad()
rather than in ViewDidAppear()
or ViewWillAppear()
. Is this a real solution and how can I confirm, or change, how the WebView is loaded by React Native?
As a hacky solution I'm using onNavigationStateChange
to save the current URL in AsyncStorage
and then load this URL when the app comes to the foreground. This solution isn't great because it:
- Breaks the browser history, affecting javascript back buttons
- Doesn't remember form state
- Might send the user to a page they can't directly access, resulting in them being sent to a 404
So I'd much prefer a solution that stops the reloading, at least for situations when the app is only momentarily in the background.