mirror of
https://github.com/status-im/react-native-webview.git
synced 2026-08-31 11:41:08 +00:00
feat(new prop): onHttpError callback (#885)
This commit is contained in:
committed by
Thibault Malbranche
parent
33f1ee384f
commit
552472c414
@@ -32,6 +32,7 @@ import android.webkit.URLUtil;
|
||||
import android.webkit.ValueCallback;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
@@ -58,6 +59,7 @@ import com.facebook.react.uimanager.events.ContentSizeChangeEvent;
|
||||
import com.facebook.react.uimanager.events.Event;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
import com.reactnativecommunity.webview.events.TopLoadingErrorEvent;
|
||||
import com.reactnativecommunity.webview.events.TopHttpErrorEvent;
|
||||
import com.reactnativecommunity.webview.events.TopLoadingFinishEvent;
|
||||
import com.reactnativecommunity.webview.events.TopLoadingProgressEvent;
|
||||
import com.reactnativecommunity.webview.events.TopLoadingStartEvent;
|
||||
@@ -512,6 +514,7 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
export.put(TopLoadingProgressEvent.EVENT_NAME, MapBuilder.of("registrationName", "onLoadingProgress"));
|
||||
export.put(TopShouldStartLoadWithRequestEvent.EVENT_NAME, MapBuilder.of("registrationName", "onShouldStartLoadWithRequest"));
|
||||
export.put(ScrollEventType.getJSEventName(ScrollEventType.SCROLL), MapBuilder.of("registrationName", "onScroll"));
|
||||
export.put(TopHttpErrorEvent.EVENT_NAME, MapBuilder.of("registrationName", "onHttpError"));
|
||||
return export;
|
||||
}
|
||||
|
||||
@@ -725,6 +728,25 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
||||
new TopLoadingErrorEvent(webView.getId(), eventData));
|
||||
}
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
public void onReceivedHttpError(
|
||||
WebView webView,
|
||||
WebResourceRequest request,
|
||||
WebResourceResponse errorResponse) {
|
||||
super.onReceivedHttpError(webView, request, errorResponse);
|
||||
|
||||
if (request.isForMainFrame()) {
|
||||
WritableMap eventData = createWebViewEvent(webView, request.getUrl().toString());
|
||||
eventData.putInt("statusCode", errorResponse.getStatusCode());
|
||||
eventData.putString("description", errorResponse.getReasonPhrase());
|
||||
|
||||
dispatchEvent(
|
||||
webView,
|
||||
new TopHttpErrorEvent(webView.getId(), eventData));
|
||||
}
|
||||
}
|
||||
|
||||
protected void emitFinishEvent(WebView webView, String url) {
|
||||
dispatchEvent(
|
||||
webView,
|
||||
|
||||
Reference in New Issue
Block a user