|
@@ -1,4 +1,4 @@
|
1
|
|
-package com.infinitered.webview;
|
|
1
|
+package com.reactnativecommunity.webview;
|
2
|
2
|
|
3
|
3
|
import android.annotation.TargetApi;
|
4
|
4
|
import android.content.Context;
|
|
@@ -49,10 +49,10 @@ import com.facebook.react.uimanager.annotations.ReactProp;
|
49
|
49
|
import com.facebook.react.uimanager.events.ContentSizeChangeEvent;
|
50
|
50
|
import com.facebook.react.uimanager.events.Event;
|
51
|
51
|
import com.facebook.react.uimanager.events.EventDispatcher;
|
52
|
|
-import com.infinitered.webview.events.TopLoadingErrorEvent;
|
53
|
|
-import com.infinitered.webview.events.TopLoadingFinishEvent;
|
54
|
|
-import com.infinitered.webview.events.TopLoadingStartEvent;
|
55
|
|
-import com.infinitered.webview.events.TopMessageEvent;
|
|
52
|
+import com.reactnativecommunity.webview.events.TopLoadingErrorEvent;
|
|
53
|
+import com.reactnativecommunity.webview.events.TopLoadingFinishEvent;
|
|
54
|
+import com.reactnativecommunity.webview.events.TopLoadingStartEvent;
|
|
55
|
+import com.reactnativecommunity.webview.events.TopMessageEvent;
|
56
|
56
|
import java.io.UnsupportedEncodingException;
|
57
|
57
|
import java.util.ArrayList;
|
58
|
58
|
import java.util.HashMap;
|
|
@@ -83,8 +83,8 @@ import org.json.JSONObject;
|
83
|
83
|
* - canGoBack - boolean, whether there is anything on a history stack to go back
|
84
|
84
|
* - canGoForward - boolean, whether it is possible to request GO_FORWARD command
|
85
|
85
|
*/
|
86
|
|
-@ReactModule(name = ReactWebViewManager.REACT_CLASS)
|
87
|
|
-public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
|
86
|
+@ReactModule(name = RNCWebViewManager.REACT_CLASS)
|
|
87
|
+public class RNCWebViewManager extends SimpleViewManager<WebView> {
|
88
|
88
|
|
89
|
89
|
protected static final String REACT_CLASS = "RNCWebView";
|
90
|
90
|
|
|
@@ -108,7 +108,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
108
|
108
|
protected WebViewConfig mWebViewConfig;
|
109
|
109
|
protected @Nullable WebView.PictureListener mPictureListener;
|
110
|
110
|
|
111
|
|
- protected static class ReactWebViewClient extends WebViewClient {
|
|
111
|
+ protected static class RNCWebViewClient extends WebViewClient {
|
112
|
112
|
|
113
|
113
|
protected boolean mLastLoadFailed = false;
|
114
|
114
|
protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
|
|
@@ -119,7 +119,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
119
|
119
|
super.onPageFinished(webView, url);
|
120
|
120
|
|
121
|
121
|
if (!mLastLoadFailed) {
|
122
|
|
- ReactWebView reactWebView = (ReactWebView) webView;
|
|
122
|
+ RNCWebView reactWebView = (RNCWebView) webView;
|
123
|
123
|
reactWebView.callInjectedJavaScript();
|
124
|
124
|
reactWebView.linkBridge();
|
125
|
125
|
emitFinishEvent(webView, url);
|
|
@@ -242,15 +242,15 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
242
|
242
|
* Subclass of {@link WebView} that implements {@link LifecycleEventListener} interface in order
|
243
|
243
|
* to call {@link WebView#destroy} on activity destroy event and also to clear the client
|
244
|
244
|
*/
|
245
|
|
- protected static class ReactWebView extends WebView implements LifecycleEventListener {
|
|
245
|
+ protected static class RNCWebView extends WebView implements LifecycleEventListener {
|
246
|
246
|
protected @Nullable String injectedJS;
|
247
|
247
|
protected boolean messagingEnabled = false;
|
248
|
|
- protected @Nullable ReactWebViewClient mReactWebViewClient;
|
|
248
|
+ protected @Nullable RNCWebViewClient mRNCWebViewClient;
|
249
|
249
|
|
250
|
|
- protected class ReactWebViewBridge {
|
251
|
|
- ReactWebView mContext;
|
|
250
|
+ protected class RNCWebViewBridge {
|
|
251
|
+ RNCWebView mContext;
|
252
|
252
|
|
253
|
|
- ReactWebViewBridge(ReactWebView c) {
|
|
253
|
+ RNCWebViewBridge(RNCWebView c) {
|
254
|
254
|
mContext = c;
|
255
|
255
|
}
|
256
|
256
|
|
|
@@ -267,7 +267,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
267
|
267
|
* Reactive Native needed for access to ReactNative internal system functionality
|
268
|
268
|
*
|
269
|
269
|
*/
|
270
|
|
- public ReactWebView(ThemedReactContext reactContext) {
|
|
270
|
+ public RNCWebView(ThemedReactContext reactContext) {
|
271
|
271
|
super(reactContext);
|
272
|
272
|
}
|
273
|
273
|
|
|
@@ -289,19 +289,19 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
289
|
289
|
@Override
|
290
|
290
|
public void setWebViewClient(WebViewClient client) {
|
291
|
291
|
super.setWebViewClient(client);
|
292
|
|
- mReactWebViewClient = (ReactWebViewClient)client;
|
|
292
|
+ mRNCWebViewClient = (RNCWebViewClient)client;
|
293
|
293
|
}
|
294
|
294
|
|
295
|
|
- public @Nullable ReactWebViewClient getReactWebViewClient() {
|
296
|
|
- return mReactWebViewClient;
|
|
295
|
+ public @Nullable RNCWebViewClient getRNCWebViewClient() {
|
|
296
|
+ return mRNCWebViewClient;
|
297
|
297
|
}
|
298
|
298
|
|
299
|
299
|
public void setInjectedJavaScript(@Nullable String js) {
|
300
|
300
|
injectedJS = js;
|
301
|
301
|
}
|
302
|
302
|
|
303
|
|
- protected ReactWebViewBridge createReactWebViewBridge(ReactWebView webView) {
|
304
|
|
- return new ReactWebViewBridge(webView);
|
|
303
|
+ protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
|
|
304
|
+ return new RNCWebViewBridge(webView);
|
305
|
305
|
}
|
306
|
306
|
|
307
|
307
|
public void setMessagingEnabled(boolean enabled) {
|
|
@@ -311,7 +311,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
311
|
311
|
|
312
|
312
|
messagingEnabled = enabled;
|
313
|
313
|
if (enabled) {
|
314
|
|
- addJavascriptInterface(createReactWebViewBridge(this), BRIDGE_NAME);
|
|
314
|
+ addJavascriptInterface(createRNCWebViewBridge(this), BRIDGE_NAME);
|
315
|
315
|
linkBridge();
|
316
|
316
|
} else {
|
317
|
317
|
removeJavascriptInterface(BRIDGE_NAME);
|
|
@@ -360,14 +360,14 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
360
|
360
|
}
|
361
|
361
|
}
|
362
|
362
|
|
363
|
|
- public ReactWebViewManager() {
|
|
363
|
+ public RNCWebViewManager() {
|
364
|
364
|
mWebViewConfig = new WebViewConfig() {
|
365
|
365
|
public void configWebView(WebView webView) {
|
366
|
366
|
}
|
367
|
367
|
};
|
368
|
368
|
}
|
369
|
369
|
|
370
|
|
- public ReactWebViewManager(WebViewConfig webViewConfig) {
|
|
370
|
+ public RNCWebViewManager(WebViewConfig webViewConfig) {
|
371
|
371
|
mWebViewConfig = webViewConfig;
|
372
|
372
|
}
|
373
|
373
|
|
|
@@ -376,14 +376,14 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
376
|
376
|
return REACT_CLASS;
|
377
|
377
|
}
|
378
|
378
|
|
379
|
|
- protected ReactWebView createReactWebViewInstance(ThemedReactContext reactContext) {
|
380
|
|
- return new ReactWebView(reactContext);
|
|
379
|
+ protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
|
|
380
|
+ return new RNCWebView(reactContext);
|
381
|
381
|
}
|
382
|
382
|
|
383
|
383
|
@Override
|
384
|
384
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
385
|
385
|
protected WebView createViewInstance(ThemedReactContext reactContext) {
|
386
|
|
- ReactWebView webView = createReactWebViewInstance(reactContext);
|
|
386
|
+ RNCWebView webView = createRNCWebViewInstance(reactContext);
|
387
|
387
|
webView.setWebChromeClient(new WebChromeClient() {
|
388
|
388
|
@Override
|
389
|
389
|
public boolean onConsoleMessage(ConsoleMessage message) {
|
|
@@ -474,12 +474,12 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
474
|
474
|
|
475
|
475
|
@ReactProp(name = "injectedJavaScript")
|
476
|
476
|
public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
|
477
|
|
- ((ReactWebView) view).setInjectedJavaScript(injectedJavaScript);
|
|
477
|
+ ((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
|
478
|
478
|
}
|
479
|
479
|
|
480
|
480
|
@ReactProp(name = "messagingEnabled")
|
481
|
481
|
public void setMessagingEnabled(WebView view, boolean enabled) {
|
482
|
|
- ((ReactWebView) view).setMessagingEnabled(enabled);
|
|
482
|
+ ((RNCWebView) view).setMessagingEnabled(enabled);
|
483
|
483
|
}
|
484
|
484
|
|
485
|
485
|
@ReactProp(name = "source")
|
|
@@ -568,7 +568,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
568
|
568
|
public void setUrlPrefixesForDefaultIntent(
|
569
|
569
|
WebView view,
|
570
|
570
|
@Nullable ReadableArray urlPrefixesForDefaultIntent) {
|
571
|
|
- ReactWebViewClient client = ((ReactWebView) view).getReactWebViewClient();
|
|
571
|
+ RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
|
572
|
572
|
if (client != null && urlPrefixesForDefaultIntent != null) {
|
573
|
573
|
client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
|
574
|
574
|
}
|
|
@@ -585,7 +585,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
585
|
585
|
public void setOriginWhitelist(
|
586
|
586
|
WebView view,
|
587
|
587
|
@Nullable ReadableArray originWhitelist) {
|
588
|
|
- ReactWebViewClient client = ((ReactWebView) view).getReactWebViewClient();
|
|
588
|
+ RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
|
589
|
589
|
if (client != null && originWhitelist != null) {
|
590
|
590
|
List<Pattern> whiteList = new LinkedList<>();
|
591
|
591
|
for (int i = 0 ; i < originWhitelist.size() ; i++) {
|
|
@@ -598,7 +598,7 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
598
|
598
|
@Override
|
599
|
599
|
protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
|
600
|
600
|
// Do not register default touch emitter and let WebView implementation handle touches
|
601
|
|
- view.setWebViewClient(new ReactWebViewClient());
|
|
601
|
+ view.setWebViewClient(new RNCWebViewClient());
|
602
|
602
|
}
|
603
|
603
|
|
604
|
604
|
@Override
|
|
@@ -656,8 +656,8 @@ public class ReactWebViewManager extends SimpleViewManager<WebView> {
|
656
|
656
|
@Override
|
657
|
657
|
public void onDropViewInstance(WebView webView) {
|
658
|
658
|
super.onDropViewInstance(webView);
|
659
|
|
- ((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((ReactWebView) webView);
|
660
|
|
- ((ReactWebView) webView).cleanupCallbacksAndDestroy();
|
|
659
|
+ ((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RNCWebView) webView);
|
|
660
|
+ ((RNCWebView) webView).cleanupCallbacksAndDestroy();
|
661
|
661
|
}
|
662
|
662
|
|
663
|
663
|
protected WebView.PictureListener getPictureListener() {
|