@exodus/react-native-webview 11.26.1-exodus.9 → 13.16.0-exodus.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +36 -63
- package/android/build.gradle +83 -110
- package/android/gradle.properties +3 -4
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/AndroidManifestNew.xml +26 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCBasicAuthCredential.java +11 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebChromeClient.java +407 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebView.java +468 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewClient.java +330 -0
- package/android/src/main/java/com/reactnativecommunity/webview/{WebViewConfig.java → RNCWebViewConfig.java} +3 -4
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewFileProvider.java +1 -1
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManagerImpl.kt +746 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewMessagingModule.kt +9 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModuleImpl.java +554 -0
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewPackage.java +57 -12
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewWrapper.kt +39 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/SubResourceErrorEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopCustomMenuSelectionEvent.kt +24 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopHttpErrorEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopNewWindowEvent.kt +25 -0
- package/android/src/main/java/com/reactnativecommunity/webview/events/TopRenderProcessGoneEvent.kt +25 -0
- package/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewManager.java +570 -0
- package/android/src/newarch/com/reactnativecommunity/webview/RNCWebViewModule.java +57 -0
- package/android/src/oldarch/com/reactnativecommunity/webview/RNCWebViewManager.java +341 -0
- package/android/src/oldarch/com/reactnativecommunity/webview/RNCWebViewModule.java +59 -0
- package/apple/RCTConvert+WKDataDetectorTypes.h +11 -0
- package/apple/RCTConvert+WKDataDetectorTypes.m +27 -0
- package/apple/RNCWebView.h +26 -100
- package/apple/RNCWebView.mm +555 -0
- package/apple/RNCWebViewDecisionManager.h +20 -0
- package/apple/RNCWebViewDecisionManager.m +47 -0
- package/apple/RNCWebViewImpl.h +164 -0
- package/apple/{RNCWebView.m → RNCWebViewImpl.m} +802 -225
- package/apple/RNCWebViewManager.h +4 -8
- package/apple/RNCWebViewManager.mm +221 -0
- package/apple/RNCWebViewModule.h +23 -0
- package/apple/RNCWebViewModule.mm +34 -0
- package/index.d.ts +2 -3
- package/lib/NativeRNCWebViewModule.d.ts +8 -0
- package/lib/NativeRNCWebViewModule.js +1 -0
- package/lib/RNCWebViewNativeComponent.d.ts +245 -0
- package/lib/RNCWebViewNativeComponent.js +1 -0
- package/lib/WebView.android.d.ts +0 -1
- package/lib/WebView.android.js +1 -135
- package/lib/WebView.d.ts +2 -3
- package/lib/WebView.ios.d.ts +0 -1
- package/lib/WebView.ios.js +1 -114
- package/lib/WebView.js +1 -11
- package/lib/WebView.macos.d.ts +6 -0
- package/lib/WebView.macos.js +1 -0
- package/lib/WebView.styles.d.ts +37 -11
- package/lib/WebView.styles.js +1 -33
- package/lib/WebView.windows.d.ts +17 -0
- package/lib/WebView.windows.js +1 -0
- package/lib/WebViewNativeComponent.macos.d.ts +3 -0
- package/lib/WebViewNativeComponent.macos.js +1 -0
- package/lib/WebViewNativeComponent.windows.d.ts +3 -0
- package/lib/WebViewNativeComponent.windows.js +1 -0
- package/lib/WebViewShared.d.ts +30 -9
- package/lib/WebViewShared.js +1 -174
- package/lib/WebViewTypes.d.ts +514 -98
- package/lib/WebViewTypes.js +1 -6
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/validation.d.ts +3 -0
- package/lib/validation.js +1 -0
- package/package.json +57 -33
- package/react-native-webview.podspec +32 -5
- package/react-native.config.js +22 -18
- package/src/NativeRNCWebViewModule.ts +13 -0
- package/src/RNCWebViewNativeComponent.ts +348 -0
- package/src/WebView.android.tsx +345 -0
- package/src/WebView.ios.tsx +341 -0
- package/src/WebView.macos.tsx +252 -0
- package/src/WebView.styles.ts +41 -0
- package/src/WebView.tsx +25 -0
- package/src/WebView.windows.tsx +217 -0
- package/src/WebViewNativeComponent.macos.ts +7 -0
- package/src/WebViewNativeComponent.windows.ts +8 -0
- package/src/WebViewShared.tsx +476 -0
- package/src/WebViewTypes.ts +1402 -0
- package/src/__tests__/WebViewShared-test.js +323 -0
- package/src/__tests__/__snapshots__/WebViewShared-test.js.snap +8 -0
- package/src/__tests__/validation-test.js +38 -0
- package/src/index.ts +4 -0
- package/src/validation.ts +20 -0
- package/android/.editorconfig +0 -6
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java +0 -1408
- package/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java +0 -506
- package/apple/RNCWebViewManager.m +0 -278
- package/lib/WebViewNativeComponent.android.d.ts +0 -4
- package/lib/WebViewNativeComponent.android.js +0 -3
- package/lib/WebViewNativeComponent.ios.d.ts +0 -4
- package/lib/WebViewNativeComponent.ios.js +0 -3
|
@@ -0,0 +1,330 @@
|
|
|
1
|
+
package com.reactnativecommunity.webview;
|
|
2
|
+
|
|
3
|
+
import android.annotation.TargetApi;
|
|
4
|
+
import android.graphics.Bitmap;
|
|
5
|
+
import android.net.http.SslError;
|
|
6
|
+
import android.os.Build;
|
|
7
|
+
import android.os.SystemClock;
|
|
8
|
+
import android.util.Log;
|
|
9
|
+
import android.webkit.HttpAuthHandler;
|
|
10
|
+
import android.webkit.RenderProcessGoneDetail;
|
|
11
|
+
import android.webkit.SslErrorHandler;
|
|
12
|
+
import android.webkit.WebResourceRequest;
|
|
13
|
+
import android.webkit.WebResourceResponse;
|
|
14
|
+
import android.webkit.WebView;
|
|
15
|
+
import android.webkit.WebViewClient;
|
|
16
|
+
|
|
17
|
+
import androidx.annotation.Nullable;
|
|
18
|
+
import androidx.annotation.RequiresApi;
|
|
19
|
+
import androidx.core.util.Pair;
|
|
20
|
+
|
|
21
|
+
import com.facebook.common.logging.FLog;
|
|
22
|
+
import com.facebook.react.bridge.Arguments;
|
|
23
|
+
import com.facebook.react.bridge.ReactContext;
|
|
24
|
+
import com.facebook.react.bridge.ReadableArray;
|
|
25
|
+
import com.facebook.react.bridge.WritableMap;
|
|
26
|
+
import com.facebook.react.uimanager.ThemedReactContext;
|
|
27
|
+
import com.facebook.react.uimanager.UIManagerHelper;
|
|
28
|
+
import com.reactnativecommunity.webview.events.SubResourceErrorEvent;
|
|
29
|
+
import com.reactnativecommunity.webview.events.TopHttpErrorEvent;
|
|
30
|
+
import com.reactnativecommunity.webview.events.TopLoadingErrorEvent;
|
|
31
|
+
import com.reactnativecommunity.webview.events.TopLoadingFinishEvent;
|
|
32
|
+
import com.reactnativecommunity.webview.events.TopLoadingStartEvent;
|
|
33
|
+
import com.reactnativecommunity.webview.events.TopRenderProcessGoneEvent;
|
|
34
|
+
import com.reactnativecommunity.webview.events.TopShouldStartLoadWithRequestEvent;
|
|
35
|
+
import android.webkit.CookieManager;
|
|
36
|
+
import android.webkit.CookieSyncManager;
|
|
37
|
+
|
|
38
|
+
import java.util.concurrent.atomic.AtomicReference;
|
|
39
|
+
|
|
40
|
+
public class RNCWebViewClient extends WebViewClient {
|
|
41
|
+
private static String TAG = "RNCWebViewClient";
|
|
42
|
+
protected static final int SHOULD_OVERRIDE_URL_LOADING_TIMEOUT = 250;
|
|
43
|
+
|
|
44
|
+
protected boolean mLastLoadFailed = false;
|
|
45
|
+
protected RNCWebView.ProgressChangedFilter progressChangedFilter = null;
|
|
46
|
+
protected @Nullable RNCBasicAuthCredential basicAuthCredential = null;
|
|
47
|
+
|
|
48
|
+
public void setBasicAuthCredential(@Nullable RNCBasicAuthCredential credential) {
|
|
49
|
+
basicAuthCredential = credential;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
@Override
|
|
53
|
+
public void onPageFinished(WebView webView, String url) {
|
|
54
|
+
super.onPageFinished(webView, url);
|
|
55
|
+
String cookies = CookieManager.getInstance().getCookie(url);
|
|
56
|
+
if (cookies != null) {
|
|
57
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
|
58
|
+
CookieManager.getInstance().flush();
|
|
59
|
+
}else {
|
|
60
|
+
CookieSyncManager.getInstance().sync();
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!mLastLoadFailed) {
|
|
65
|
+
RNCWebView reactWebView = (RNCWebView) webView;
|
|
66
|
+
|
|
67
|
+
reactWebView.callInjectedJavaScript();
|
|
68
|
+
|
|
69
|
+
emitFinishEvent(webView, url);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Override
|
|
74
|
+
public void doUpdateVisitedHistory (WebView webView, String url, boolean isReload) {
|
|
75
|
+
super.doUpdateVisitedHistory(webView, url, isReload);
|
|
76
|
+
|
|
77
|
+
((RNCWebView) webView).dispatchEvent(
|
|
78
|
+
webView,
|
|
79
|
+
new TopLoadingStartEvent(
|
|
80
|
+
RNCWebViewWrapper.getReactTagFromWebView(webView),
|
|
81
|
+
createWebViewEvent(webView, url)));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Override
|
|
85
|
+
public void onPageStarted(WebView webView, String url, Bitmap favicon) {
|
|
86
|
+
super.onPageStarted(webView, url, favicon);
|
|
87
|
+
mLastLoadFailed = false;
|
|
88
|
+
|
|
89
|
+
RNCWebView reactWebView = (RNCWebView) webView;
|
|
90
|
+
reactWebView.callInjectedJavaScriptBeforeContentLoaded();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@Override
|
|
94
|
+
public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
95
|
+
final RNCWebView rncWebView = (RNCWebView) view;
|
|
96
|
+
final boolean isJsDebugging = rncWebView.getReactApplicationContext().getJavaScriptContextHolder().get() == 0;
|
|
97
|
+
|
|
98
|
+
if (!isJsDebugging && rncWebView.mMessagingJSModule != null) {
|
|
99
|
+
final Pair<Double, AtomicReference<RNCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState>> lock = RNCWebViewModuleImpl.shouldOverrideUrlLoadingLock.getNewLock();
|
|
100
|
+
final double lockIdentifier = lock.first;
|
|
101
|
+
final AtomicReference<RNCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState> lockObject = lock.second;
|
|
102
|
+
|
|
103
|
+
final WritableMap event = createWebViewEvent(view, url);
|
|
104
|
+
event.putDouble("lockIdentifier", lockIdentifier);
|
|
105
|
+
rncWebView.dispatchDirectShouldStartLoadWithRequest(event);
|
|
106
|
+
|
|
107
|
+
try {
|
|
108
|
+
assert lockObject != null;
|
|
109
|
+
synchronized (lockObject) {
|
|
110
|
+
final long startTime = SystemClock.elapsedRealtime();
|
|
111
|
+
while (lockObject.get() == RNCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.UNDECIDED) {
|
|
112
|
+
if (SystemClock.elapsedRealtime() - startTime > SHOULD_OVERRIDE_URL_LOADING_TIMEOUT) {
|
|
113
|
+
FLog.w(TAG, "Did not receive response to shouldOverrideUrlLoading in time, defaulting to allow loading.");
|
|
114
|
+
RNCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
lockObject.wait(SHOULD_OVERRIDE_URL_LOADING_TIMEOUT);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
} catch (InterruptedException e) {
|
|
121
|
+
FLog.e(TAG, "shouldOverrideUrlLoading was interrupted while waiting for result.", e);
|
|
122
|
+
RNCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
final boolean shouldOverride = lockObject.get() == RNCWebViewModuleImpl.ShouldOverrideUrlLoadingLock.ShouldOverrideCallbackState.SHOULD_OVERRIDE;
|
|
127
|
+
RNCWebViewModuleImpl.shouldOverrideUrlLoadingLock.removeLock(lockIdentifier);
|
|
128
|
+
|
|
129
|
+
return shouldOverride;
|
|
130
|
+
} else {
|
|
131
|
+
FLog.w(TAG, "Couldn't use blocking synchronous call for onShouldStartLoadWithRequest due to debugging or missing Catalyst instance, falling back to old event-and-load.");
|
|
132
|
+
progressChangedFilter.setWaitingForCommandLoadUrl(true);
|
|
133
|
+
|
|
134
|
+
int reactTag = RNCWebViewWrapper.getReactTagFromWebView(view);
|
|
135
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) view.getContext(), reactTag).dispatchEvent(new TopShouldStartLoadWithRequestEvent(
|
|
136
|
+
reactTag,
|
|
137
|
+
createWebViewEvent(view, url)));
|
|
138
|
+
return true;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@TargetApi(Build.VERSION_CODES.N)
|
|
143
|
+
@Override
|
|
144
|
+
public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) {
|
|
145
|
+
final String url = request.getUrl().toString();
|
|
146
|
+
return this.shouldOverrideUrlLoading(view, url);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
@Override
|
|
150
|
+
public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) {
|
|
151
|
+
if (basicAuthCredential != null) {
|
|
152
|
+
handler.proceed(basicAuthCredential.username, basicAuthCredential.password);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
super.onReceivedHttpAuthRequest(view, handler, host, realm);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
@Override
|
|
159
|
+
public void onReceivedSslError(final WebView webView, final SslErrorHandler handler, final SslError error) {
|
|
160
|
+
// onReceivedSslError is called for most requests, per Android docs: https://developer.android.com/reference/android/webkit/WebViewClient#onReceivedSslError(android.webkit.WebView,%2520android.webkit.SslErrorHandler,%2520android.net.http.SslError)
|
|
161
|
+
// WebView.getUrl() will return the top-level window URL.
|
|
162
|
+
// If a top-level navigation triggers this error handler, the top-level URL will be the failing URL (not the URL of the currently-rendered page).
|
|
163
|
+
// This is desired behavior. We later use these values to determine whether the request is a top-level navigation or a subresource request.
|
|
164
|
+
String topWindowUrl = webView.getUrl();
|
|
165
|
+
String failingUrl = error.getUrl();
|
|
166
|
+
|
|
167
|
+
// Cancel request after obtaining top-level URL.
|
|
168
|
+
// If request is cancelled before obtaining top-level URL, undesired behavior may occur.
|
|
169
|
+
// Undesired behavior: Return value of WebView.getUrl() may be the current URL instead of the failing URL.
|
|
170
|
+
handler.cancel();
|
|
171
|
+
|
|
172
|
+
int code = error.getPrimaryError();
|
|
173
|
+
String description = "";
|
|
174
|
+
String descriptionPrefix = "SSL error: ";
|
|
175
|
+
|
|
176
|
+
// https://developer.android.com/reference/android/net/http/SslError.html
|
|
177
|
+
switch (code) {
|
|
178
|
+
case SslError.SSL_DATE_INVALID:
|
|
179
|
+
description = "The date of the certificate is invalid";
|
|
180
|
+
break;
|
|
181
|
+
case SslError.SSL_EXPIRED:
|
|
182
|
+
description = "The certificate has expired";
|
|
183
|
+
break;
|
|
184
|
+
case SslError.SSL_IDMISMATCH:
|
|
185
|
+
description = "Hostname mismatch";
|
|
186
|
+
break;
|
|
187
|
+
case SslError.SSL_INVALID:
|
|
188
|
+
description = "A generic error occurred";
|
|
189
|
+
break;
|
|
190
|
+
case SslError.SSL_NOTYETVALID:
|
|
191
|
+
description = "The certificate is not yet valid";
|
|
192
|
+
break;
|
|
193
|
+
case SslError.SSL_UNTRUSTED:
|
|
194
|
+
description = "The certificate authority is not trusted";
|
|
195
|
+
break;
|
|
196
|
+
default:
|
|
197
|
+
description = "Unknown SSL Error";
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
description = descriptionPrefix + description;
|
|
202
|
+
|
|
203
|
+
if (!topWindowUrl.equalsIgnoreCase(failingUrl)) {
|
|
204
|
+
// If error is not due to top-level navigation, then do not call onReceivedError()
|
|
205
|
+
Log.w(TAG, "Resource blocked from loading due to SSL error. Blocked URL: "+failingUrl);
|
|
206
|
+
this.onReceivedSubResourceSslError(
|
|
207
|
+
webView,
|
|
208
|
+
code,
|
|
209
|
+
description,
|
|
210
|
+
failingUrl
|
|
211
|
+
);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
this.onReceivedError(
|
|
216
|
+
webView,
|
|
217
|
+
code,
|
|
218
|
+
description,
|
|
219
|
+
failingUrl
|
|
220
|
+
);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
public void onReceivedSubResourceSslError(
|
|
224
|
+
WebView webView,
|
|
225
|
+
int errorCode,
|
|
226
|
+
String description,
|
|
227
|
+
String failingUrl) {
|
|
228
|
+
|
|
229
|
+
WritableMap eventData = createWebViewEvent(webView, failingUrl);
|
|
230
|
+
eventData.putDouble("code", errorCode);
|
|
231
|
+
eventData.putString("description", description);
|
|
232
|
+
|
|
233
|
+
int reactTag = RNCWebViewWrapper.getReactTagFromWebView(webView);
|
|
234
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new SubResourceErrorEvent(reactTag, eventData));
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
@Override
|
|
238
|
+
public void onReceivedError(
|
|
239
|
+
WebView webView,
|
|
240
|
+
int errorCode,
|
|
241
|
+
String description,
|
|
242
|
+
String failingUrl) {
|
|
243
|
+
|
|
244
|
+
super.onReceivedError(webView, errorCode, description, failingUrl);
|
|
245
|
+
mLastLoadFailed = true;
|
|
246
|
+
|
|
247
|
+
// In case of an error JS side expect to get a finish event first, and then get an error event
|
|
248
|
+
// Android WebView does it in the opposite way, so we need to simulate that behavior
|
|
249
|
+
emitFinishEvent(webView, failingUrl);
|
|
250
|
+
|
|
251
|
+
WritableMap eventData = createWebViewEvent(webView, failingUrl);
|
|
252
|
+
eventData.putDouble("code", errorCode);
|
|
253
|
+
eventData.putString("description", description);
|
|
254
|
+
|
|
255
|
+
int reactTag = RNCWebViewWrapper.getReactTagFromWebView(webView);
|
|
256
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingErrorEvent(reactTag, eventData));
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
@RequiresApi(api = Build.VERSION_CODES.M)
|
|
260
|
+
@Override
|
|
261
|
+
public void onReceivedHttpError(
|
|
262
|
+
WebView webView,
|
|
263
|
+
WebResourceRequest request,
|
|
264
|
+
WebResourceResponse errorResponse) {
|
|
265
|
+
super.onReceivedHttpError(webView, request, errorResponse);
|
|
266
|
+
|
|
267
|
+
if (request.isForMainFrame()) {
|
|
268
|
+
WritableMap eventData = createWebViewEvent(webView, request.getUrl().toString());
|
|
269
|
+
eventData.putInt("statusCode", errorResponse.getStatusCode());
|
|
270
|
+
eventData.putString("description", errorResponse.getReasonPhrase());
|
|
271
|
+
|
|
272
|
+
int reactTag = RNCWebViewWrapper.getReactTagFromWebView(webView);
|
|
273
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopHttpErrorEvent(reactTag, eventData));
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
@TargetApi(Build.VERSION_CODES.O)
|
|
278
|
+
@Override
|
|
279
|
+
public boolean onRenderProcessGone(WebView webView, RenderProcessGoneDetail detail) {
|
|
280
|
+
// WebViewClient.onRenderProcessGone was added in O.
|
|
281
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
|
282
|
+
return false;
|
|
283
|
+
}
|
|
284
|
+
super.onRenderProcessGone(webView, detail);
|
|
285
|
+
|
|
286
|
+
if(detail.didCrash()){
|
|
287
|
+
Log.e(TAG, "The WebView rendering process crashed.");
|
|
288
|
+
}
|
|
289
|
+
else{
|
|
290
|
+
Log.w(TAG, "The WebView rendering process was killed by the system.");
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
// if webView is null, we cannot return any event
|
|
294
|
+
// since the view is already dead/disposed
|
|
295
|
+
// still prevent the app crash by returning true.
|
|
296
|
+
if(webView == null){
|
|
297
|
+
return true;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
WritableMap event = createWebViewEvent(webView, webView.getUrl());
|
|
301
|
+
event.putBoolean("didCrash", detail.didCrash());
|
|
302
|
+
int reactTag = RNCWebViewWrapper.getReactTagFromWebView(webView);
|
|
303
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopRenderProcessGoneEvent(reactTag, event));
|
|
304
|
+
|
|
305
|
+
// returning false would crash the app.
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
protected void emitFinishEvent(WebView webView, String url) {
|
|
310
|
+
int reactTag = RNCWebViewWrapper.getReactTagFromWebView(webView);
|
|
311
|
+
UIManagerHelper.getEventDispatcherForReactTag((ReactContext) webView.getContext(), reactTag).dispatchEvent(new TopLoadingFinishEvent(reactTag, createWebViewEvent(webView, url)));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
protected WritableMap createWebViewEvent(WebView webView, String url) {
|
|
315
|
+
WritableMap event = Arguments.createMap();
|
|
316
|
+
event.putDouble("target", RNCWebViewWrapper.getReactTagFromWebView(webView));
|
|
317
|
+
// Don't use webView.getUrl() here, the URL isn't updated to the new value yet in callbacks
|
|
318
|
+
// like onPageFinished
|
|
319
|
+
event.putString("url", url);
|
|
320
|
+
event.putBoolean("loading", !mLastLoadFailed && webView.getProgress() != 100);
|
|
321
|
+
event.putString("title", webView.getTitle());
|
|
322
|
+
event.putBoolean("canGoBack", webView.canGoBack());
|
|
323
|
+
event.putBoolean("canGoForward", webView.canGoForward());
|
|
324
|
+
return event;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
public void setProgressChangedFilter(RNCWebView.ProgressChangedFilter filter) {
|
|
328
|
+
progressChangedFilter = filter;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
@@ -6,7 +6,6 @@ import android.webkit.WebView;
|
|
|
6
6
|
* Implement this interface in order to config your {@link WebView}. An instance of that
|
|
7
7
|
* implementation will have to be given as a constructor argument to {@link RNCWebViewManager}.
|
|
8
8
|
*/
|
|
9
|
-
public interface
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
9
|
+
public interface RNCWebViewConfig {
|
|
10
|
+
void configWebView(WebView webView);
|
|
11
|
+
}
|