mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-11 22:40:37 +08:00
Implemented stopLoading
Summary:**Motivation:** In my app, I'm using a WebView that loads content from my mobile site. What I want to do is when a user presses a link on the loaded page, I want to stop the WebView's request, hijack the URL and open the URL in a new WebView, pushed to the top of the navigator stack. To me, this gives the overall app a more native feel, instead of implementing a rudimentary navbar on the main WebView to go back. **Attempted Workarounds:** I've attempted to get similar functionality by capturing the onNavigationStateChange event in the WebView, and then within calling goBack + pushing the new view to the navigator stack. From a functionality standpoint, this works. However, from a UI standpoint, the user can clearly see the webview change states to a new page + go back before having the new view pushed on top of their nav stack. Closes https://github.com/facebook/react-native/pull/6886 Differential Revision: D3212447 Pulled By: mkonicek fb-gh-sync-id: 05911e583d9ba54ddbd54a772153c80ed227731e fbshipit-source-id: 05911e583d9ba54ddbd54a772153c80ed227731e
This commit is contained in:
committed by
Facebook Github Bot 0
parent
32a89493fb
commit
774296b263
@@ -75,6 +75,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
||||
public static final int COMMAND_GO_BACK = 1;
|
||||
public static final int COMMAND_GO_FORWARD = 2;
|
||||
public static final int COMMAND_RELOAD = 3;
|
||||
public static final int COMMAND_STOP_LOADING = 4;
|
||||
|
||||
// Use `webView.loadUrl("about:blank")` to reliably reset the view
|
||||
// state and release page resources (including any running JavaScript).
|
||||
@@ -350,7 +351,8 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
||||
return MapBuilder.of(
|
||||
"goBack", COMMAND_GO_BACK,
|
||||
"goForward", COMMAND_GO_FORWARD,
|
||||
"reload", COMMAND_RELOAD);
|
||||
"reload", COMMAND_RELOAD,
|
||||
"stopLoading", COMMAND_STOP_LOADING);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -365,6 +367,9 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
||||
case COMMAND_RELOAD:
|
||||
root.reload();
|
||||
break;
|
||||
case COMMAND_STOP_LOADING:
|
||||
root.stopLoading();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user