|
@@ -43,6 +43,9 @@ import androidx.annotation.Nullable;
|
43
|
43
|
import androidx.annotation.RequiresApi;
|
44
|
44
|
import androidx.core.content.ContextCompat;
|
45
|
45
|
import androidx.core.util.Pair;
|
|
46
|
+import androidx.webkit.WebViewAssetLoader;
|
|
47
|
+import androidx.webkit.WebViewAssetLoader.ResourcesPathHandler;
|
|
48
|
+import androidx.webkit.WebViewAssetLoader.AssetsPathHandler;
|
46
|
49
|
|
47
|
50
|
import com.facebook.common.logging.FLog;
|
48
|
51
|
import com.facebook.react.views.scroll.ScrollEvent;
|
|
@@ -149,6 +152,8 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
149
|
152
|
protected @Nullable String mUserAgent = null;
|
150
|
153
|
protected @Nullable String mUserAgentWithApplicationName = null;
|
151
|
154
|
|
|
155
|
+ private static WebViewAssetLoader assetLoader;
|
|
156
|
+
|
152
|
157
|
public RNCWebViewManager() {
|
153
|
158
|
mWebViewConfig = new WebViewConfig() {
|
154
|
159
|
public void configWebView(WebView webView) {
|
|
@@ -196,6 +201,13 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
196
|
201
|
}
|
197
|
202
|
setMixedContentMode(webView, "never");
|
198
|
203
|
|
|
204
|
+ if (assetLoader == null) {
|
|
205
|
+ assetLoader = new WebViewAssetLoader.Builder()
|
|
206
|
+ .addPathHandler("/assets/", new AssetsPathHandler(reactContext))
|
|
207
|
+ .addPathHandler("/res/", new ResourcesPathHandler(reactContext))
|
|
208
|
+ .build();
|
|
209
|
+ }
|
|
210
|
+
|
199
|
211
|
// Fixes broken full-screen modals/galleries due to body height being 0.
|
200
|
212
|
webView.setLayoutParams(
|
201
|
213
|
new LayoutParams(LayoutParams.MATCH_PARENT,
|
|
@@ -778,6 +790,12 @@ public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
778
|
790
|
protected RNCWebView.ProgressChangedFilter progressChangedFilter = null;
|
779
|
791
|
protected @Nullable String ignoreErrFailedForThisURL = null;
|
780
|
792
|
|
|
793
|
+ @Override
|
|
794
|
+ public WebResourceResponse shouldInterceptRequest(WebView view,
|
|
795
|
+ WebResourceRequest request) {
|
|
796
|
+ return assetLoader.shouldInterceptRequest(request.getUrl());
|
|
797
|
+ }
|
|
798
|
+
|
781
|
799
|
public void setIgnoreErrFailedForThisURL(@Nullable String url) {
|
782
|
800
|
ignoreErrFailedForThisURL = url;
|
783
|
801
|
}
|