Browse Source

Renamed RNC on android too to stay consistent with iOS

Thibault Malbranche 6 years ago
parent
commit
fcc35cec09

android/src/main/java/com/reactnativecommunity/webview/RCTWebViewManager.java → android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java View File

84
  *  - canGoBack - boolean, whether there is anything on a history stack to go back
84
  *  - canGoBack - boolean, whether there is anything on a history stack to go back
85
  *  - canGoForward - boolean, whether it is possible to request GO_FORWARD command
85
  *  - canGoForward - boolean, whether it is possible to request GO_FORWARD command
86
  */
86
  */
87
-@ReactModule(name = RCTWebViewManager.REACT_CLASS)
88
-public class RCTWebViewManager extends SimpleViewManager<WebView> {
87
+@ReactModule(name = RNCWebViewManager.REACT_CLASS)
88
+public class RNCWebViewManager extends SimpleViewManager<WebView> {
89
 
89
 
90
-  protected static final String REACT_CLASS = "RCTWebView";
90
+  protected static final String REACT_CLASS = "RNCWebView";
91
 
91
 
92
   protected static final String HTML_ENCODING = "UTF-8";
92
   protected static final String HTML_ENCODING = "UTF-8";
93
   protected static final String HTML_MIME_TYPE = "text/html";
93
   protected static final String HTML_MIME_TYPE = "text/html";
109
   protected WebViewConfig mWebViewConfig;
109
   protected WebViewConfig mWebViewConfig;
110
   protected @Nullable WebView.PictureListener mPictureListener;
110
   protected @Nullable WebView.PictureListener mPictureListener;
111
 
111
 
112
-  protected static class RCTWebViewClient extends WebViewClient {
112
+  protected static class RNCWebViewClient extends WebViewClient {
113
 
113
 
114
     protected boolean mLastLoadFailed = false;
114
     protected boolean mLastLoadFailed = false;
115
     protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
115
     protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
120
       super.onPageFinished(webView, url);
120
       super.onPageFinished(webView, url);
121
 
121
 
122
       if (!mLastLoadFailed) {
122
       if (!mLastLoadFailed) {
123
-        RCTWebView reactWebView = (RCTWebView) webView;
123
+        RNCWebView reactWebView = (RNCWebView) webView;
124
         reactWebView.callInjectedJavaScript();
124
         reactWebView.callInjectedJavaScript();
125
         reactWebView.linkBridge();
125
         reactWebView.linkBridge();
126
         emitFinishEvent(webView, url);
126
         emitFinishEvent(webView, url);
243
    * Subclass of {@link WebView} that implements {@link LifecycleEventListener} interface in order
243
    * Subclass of {@link WebView} that implements {@link LifecycleEventListener} interface in order
244
    * to call {@link WebView#destroy} on activity destroy event and also to clear the client
244
    * to call {@link WebView#destroy} on activity destroy event and also to clear the client
245
    */
245
    */
246
-  protected static class RCTWebView extends WebView implements LifecycleEventListener {
246
+  protected static class RNCWebView extends WebView implements LifecycleEventListener {
247
     protected @Nullable String injectedJS;
247
     protected @Nullable String injectedJS;
248
     protected boolean messagingEnabled = false;
248
     protected boolean messagingEnabled = false;
249
-    protected @Nullable RCTWebViewClient mRCTWebViewClient;
249
+    protected @Nullable RNCWebViewClient mRNCWebViewClient;
250
 
250
 
251
-    protected class RCTWebViewBridge {
252
-      RCTWebView mContext;
251
+    protected class RNCWebViewBridge {
252
+      RNCWebView mContext;
253
 
253
 
254
-      RCTWebViewBridge(RCTWebView c) {
254
+      RNCWebViewBridge(RNCWebView c) {
255
         mContext = c;
255
         mContext = c;
256
       }
256
       }
257
 
257
 
268
      * Reactive Native needed for access to ReactNative internal system functionality
268
      * Reactive Native needed for access to ReactNative internal system functionality
269
      *
269
      *
270
      */
270
      */
271
-    public RCTWebView(ThemedReactContext reactContext) {
271
+    public RNCWebView(ThemedReactContext reactContext) {
272
       super(reactContext);
272
       super(reactContext);
273
     }
273
     }
274
 
274
 
290
     @Override
290
     @Override
291
     public void setWebViewClient(WebViewClient client) {
291
     public void setWebViewClient(WebViewClient client) {
292
       super.setWebViewClient(client);
292
       super.setWebViewClient(client);
293
-      mRCTWebViewClient = (RCTWebViewClient)client;
293
+      mRNCWebViewClient = (RNCWebViewClient)client;
294
     }
294
     }
295
 
295
 
296
-    public @Nullable RCTWebViewClient getRCTWebViewClient() {
297
-      return mRCTWebViewClient;
296
+    public @Nullable RNCWebViewClient getRNCWebViewClient() {
297
+      return mRNCWebViewClient;
298
     }
298
     }
299
 
299
 
300
     public void setInjectedJavaScript(@Nullable String js) {
300
     public void setInjectedJavaScript(@Nullable String js) {
301
       injectedJS = js;
301
       injectedJS = js;
302
     }
302
     }
303
 
303
 
304
-    protected RCTWebViewBridge createRCTWebViewBridge(RCTWebView webView) {
305
-      return new RCTWebViewBridge(webView);
304
+    protected RNCWebViewBridge createRNCWebViewBridge(RNCWebView webView) {
305
+      return new RNCWebViewBridge(webView);
306
     }
306
     }
307
 
307
 
308
     public void setMessagingEnabled(boolean enabled) {
308
     public void setMessagingEnabled(boolean enabled) {
312
 
312
 
313
       messagingEnabled = enabled;
313
       messagingEnabled = enabled;
314
       if (enabled) {
314
       if (enabled) {
315
-        addJavascriptInterface(createRCTWebViewBridge(this), BRIDGE_NAME);
315
+        addJavascriptInterface(createRNCWebViewBridge(this), BRIDGE_NAME);
316
         linkBridge();
316
         linkBridge();
317
       } else {
317
       } else {
318
         removeJavascriptInterface(BRIDGE_NAME);
318
         removeJavascriptInterface(BRIDGE_NAME);
375
     }
375
     }
376
   }
376
   }
377
 
377
 
378
-  public RCTWebViewManager() {
378
+  public RNCWebViewManager() {
379
     mWebViewConfig = new WebViewConfig() {
379
     mWebViewConfig = new WebViewConfig() {
380
       public void configWebView(WebView webView) {
380
       public void configWebView(WebView webView) {
381
       }
381
       }
382
     };
382
     };
383
   }
383
   }
384
 
384
 
385
-  public RCTWebViewManager(WebViewConfig webViewConfig) {
385
+  public RNCWebViewManager(WebViewConfig webViewConfig) {
386
     mWebViewConfig = webViewConfig;
386
     mWebViewConfig = webViewConfig;
387
   }
387
   }
388
 
388
 
391
     return REACT_CLASS;
391
     return REACT_CLASS;
392
   }
392
   }
393
 
393
 
394
-  protected RCTWebView createRCTWebViewInstance(ThemedReactContext reactContext) {
395
-    return new RCTWebView(reactContext);
394
+  protected RNCWebView createRNCWebViewInstance(ThemedReactContext reactContext) {
395
+    return new RNCWebView(reactContext);
396
   }
396
   }
397
 
397
 
398
   @Override
398
   @Override
399
   @TargetApi(Build.VERSION_CODES.LOLLIPOP)
399
   @TargetApi(Build.VERSION_CODES.LOLLIPOP)
400
   protected WebView createViewInstance(ThemedReactContext reactContext) {
400
   protected WebView createViewInstance(ThemedReactContext reactContext) {
401
-    RCTWebView webView = createRCTWebViewInstance(reactContext);
401
+    RNCWebView webView = createRNCWebViewInstance(reactContext);
402
     webView.setWebChromeClient(new WebChromeClient() {
402
     webView.setWebChromeClient(new WebChromeClient() {
403
       @Override
403
       @Override
404
       public boolean onConsoleMessage(ConsoleMessage message) {
404
       public boolean onConsoleMessage(ConsoleMessage message) {
489
 
489
 
490
   @ReactProp(name = "injectedJavaScript")
490
   @ReactProp(name = "injectedJavaScript")
491
   public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
491
   public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
492
-    ((RCTWebView) view).setInjectedJavaScript(injectedJavaScript);
492
+    ((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
493
   }
493
   }
494
 
494
 
495
   @ReactProp(name = "messagingEnabled")
495
   @ReactProp(name = "messagingEnabled")
496
   public void setMessagingEnabled(WebView view, boolean enabled) {
496
   public void setMessagingEnabled(WebView view, boolean enabled) {
497
-    ((RCTWebView) view).setMessagingEnabled(enabled);
497
+    ((RNCWebView) view).setMessagingEnabled(enabled);
498
   }
498
   }
499
 
499
 
500
   @ReactProp(name = "source")
500
   @ReactProp(name = "source")
583
   public void setUrlPrefixesForDefaultIntent(
583
   public void setUrlPrefixesForDefaultIntent(
584
       WebView view,
584
       WebView view,
585
       @Nullable ReadableArray urlPrefixesForDefaultIntent) {
585
       @Nullable ReadableArray urlPrefixesForDefaultIntent) {
586
-    RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
586
+    RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
587
     if (client != null && urlPrefixesForDefaultIntent != null) {
587
     if (client != null && urlPrefixesForDefaultIntent != null) {
588
       client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
588
       client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
589
     }
589
     }
607
   public void setOriginWhitelist(
607
   public void setOriginWhitelist(
608
     WebView view,
608
     WebView view,
609
     @Nullable ReadableArray originWhitelist) {
609
     @Nullable ReadableArray originWhitelist) {
610
-    RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
610
+    RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
611
     if (client != null && originWhitelist != null) {
611
     if (client != null && originWhitelist != null) {
612
       List<Pattern> whiteList = new LinkedList<>();
612
       List<Pattern> whiteList = new LinkedList<>();
613
       for (int i = 0 ; i < originWhitelist.size() ; i++) {
613
       for (int i = 0 ; i < originWhitelist.size() ; i++) {
620
   @Override
620
   @Override
621
   protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
621
   protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
622
     // Do not register default touch emitter and let WebView implementation handle touches
622
     // Do not register default touch emitter and let WebView implementation handle touches
623
-    view.setWebViewClient(new RCTWebViewClient());
623
+    view.setWebViewClient(new RNCWebViewClient());
624
   }
624
   }
625
 
625
 
626
   @Override
626
   @Override
652
         break;
652
         break;
653
       case COMMAND_POST_MESSAGE:
653
       case COMMAND_POST_MESSAGE:
654
         try {
654
         try {
655
-          RCTWebView reactWebView = (RCTWebView) root;
655
+          RNCWebView reactWebView = (RNCWebView) root;
656
           JSONObject eventInitDict = new JSONObject();
656
           JSONObject eventInitDict = new JSONObject();
657
           eventInitDict.put("data", args.getString(0));
657
           eventInitDict.put("data", args.getString(0));
658
           reactWebView.evaluateJavascriptWithFallback("(function () {" +
658
           reactWebView.evaluateJavascriptWithFallback("(function () {" +
671
         }
671
         }
672
         break;
672
         break;
673
       case COMMAND_INJECT_JAVASCRIPT:
673
       case COMMAND_INJECT_JAVASCRIPT:
674
-        RCTWebView reactWebView = (RCTWebView) root;
674
+        RNCWebView reactWebView = (RNCWebView) root;
675
         reactWebView.evaluateJavascriptWithFallback(args.getString(0));
675
         reactWebView.evaluateJavascriptWithFallback(args.getString(0));
676
         break;
676
         break;
677
     }
677
     }
680
   @Override
680
   @Override
681
   public void onDropViewInstance(WebView webView) {
681
   public void onDropViewInstance(WebView webView) {
682
     super.onDropViewInstance(webView);
682
     super.onDropViewInstance(webView);
683
-    ((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RCTWebView) webView);
684
-    ((RCTWebView) webView).cleanupCallbacksAndDestroy();
683
+    ((ThemedReactContext) webView.getContext()).removeLifecycleEventListener((RNCWebView) webView);
684
+    ((RNCWebView) webView).cleanupCallbacksAndDestroy();
685
   }
685
   }
686
 
686
 
687
   protected WebView.PictureListener getPictureListener() {
687
   protected WebView.PictureListener getPictureListener() {

android/src/main/java/com/reactnativecommunity/webview/RCTWebViewModule.java → android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java View File

6
 import com.facebook.react.bridge.ReactMethod;
6
 import com.facebook.react.bridge.ReactMethod;
7
 import com.facebook.react.bridge.Callback;
7
 import com.facebook.react.bridge.Callback;
8
 
8
 
9
-public class RCTWebViewModule extends ReactContextBaseJavaModule {
9
+public class RNCWebViewModule extends ReactContextBaseJavaModule {
10
 
10
 
11
   private final ReactApplicationContext reactContext;
11
   private final ReactApplicationContext reactContext;
12
 
12
 
13
-  public RCTWebViewModule(ReactApplicationContext reactContext) {
13
+  public RNCWebViewModule(ReactApplicationContext reactContext) {
14
     super(reactContext);
14
     super(reactContext);
15
     this.reactContext = reactContext;
15
     this.reactContext = reactContext;
16
   }
16
   }
17
 
17
 
18
   @Override
18
   @Override
19
   public String getName() {
19
   public String getName() {
20
-    return "RCTWebView";
20
+    return "RNCWebView";
21
   }
21
   }
22
 }
22
 }

android/src/main/java/com/reactnativecommunity/webview/RCTWebViewPackage.java → android/src/main/java/com/reactnativecommunity/webview/RNCWebViewPackage.java View File

10
 import com.facebook.react.bridge.ReactApplicationContext;
10
 import com.facebook.react.bridge.ReactApplicationContext;
11
 import com.facebook.react.uimanager.ViewManager;
11
 import com.facebook.react.uimanager.ViewManager;
12
 import com.facebook.react.bridge.JavaScriptModule;
12
 import com.facebook.react.bridge.JavaScriptModule;
13
-public class RCTWebViewPackage implements ReactPackage {
13
+public class RNCWebViewPackage implements ReactPackage {
14
     @Override
14
     @Override
15
     public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
15
     public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
16
-      return Arrays.<NativeModule>asList(new RCTWebViewModule(reactContext));
16
+      return Arrays.<NativeModule>asList(new RNCWebViewModule(reactContext));
17
     }
17
     }
18
 
18
 
19
     // Deprecated from RN 0.47
19
     // Deprecated from RN 0.47
23
 
23
 
24
     @Override
24
     @Override
25
     public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
25
     public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
26
-        RCTWebViewManager viewManager = new RCTWebViewManager();
26
+        RNCWebViewManager viewManager = new RNCWebViewManager();
27
         return Arrays.<ViewManager>asList(viewManager);
27
         return Arrays.<ViewManager>asList(viewManager);
28
     }
28
     }
29
 }
29
 }

+ 1
- 1
android/src/main/java/com/reactnativecommunity/webview/WebViewConfig.java View File

4
 
4
 
5
 /**
5
 /**
6
  * Implement this interface in order to config your {@link WebView}. An instance of that
6
  * Implement this interface in order to config your {@link WebView}. An instance of that
7
- * implementation will have to be given as a constructor argument to {@link RCTWebViewManager}.
7
+ * implementation will have to be given as a constructor argument to {@link RNCWebViewManager}.
8
  */
8
  */
9
 public interface WebViewConfig {
9
 public interface WebViewConfig {
10
 
10
 

+ 9
- 9
js/WebView.android.js View File

101
         );
101
         );
102
     } else if (this.state.viewState !== WebViewState.IDLE) {
102
     } else if (this.state.viewState !== WebViewState.IDLE) {
103
       console.error(
103
       console.error(
104
-        'RCTWebView invalid state encountered: ' + this.state.viewState,
104
+        'RNCWebView invalid state encountered: ' + this.state.viewState,
105
       );
105
       );
106
     }
106
     }
107
 
107
 
135
       WebViewShared.originWhitelistToRegex,
135
       WebViewShared.originWhitelistToRegex,
136
     );
136
     );
137
 
137
 
138
-    let NativeWebView = nativeConfig.component || RCTWebView;
138
+    let NativeWebView = nativeConfig.component || RNCWebView;
139
 
139
 
140
     const webView = (
140
     const webView = (
141
       <NativeWebView
141
       <NativeWebView
187
   goForward = () => {
187
   goForward = () => {
188
     UIManager.dispatchViewManagerCommand(
188
     UIManager.dispatchViewManagerCommand(
189
       this.getWebViewHandle(),
189
       this.getWebViewHandle(),
190
-      UIManager.RCTWebView.Commands.goForward,
190
+      UIManager.RNCWebView.Commands.goForward,
191
       null,
191
       null,
192
     );
192
     );
193
   };
193
   };
195
   goBack = () => {
195
   goBack = () => {
196
     UIManager.dispatchViewManagerCommand(
196
     UIManager.dispatchViewManagerCommand(
197
       this.getWebViewHandle(),
197
       this.getWebViewHandle(),
198
-      UIManager.RCTWebView.Commands.goBack,
198
+      UIManager.RNCWebView.Commands.goBack,
199
       null,
199
       null,
200
     );
200
     );
201
   };
201
   };
206
     });
206
     });
207
     UIManager.dispatchViewManagerCommand(
207
     UIManager.dispatchViewManagerCommand(
208
       this.getWebViewHandle(),
208
       this.getWebViewHandle(),
209
-      UIManager.RCTWebView.Commands.reload,
209
+      UIManager.RNCWebView.Commands.reload,
210
       null,
210
       null,
211
     );
211
     );
212
   };
212
   };
214
   stopLoading = () => {
214
   stopLoading = () => {
215
     UIManager.dispatchViewManagerCommand(
215
     UIManager.dispatchViewManagerCommand(
216
       this.getWebViewHandle(),
216
       this.getWebViewHandle(),
217
-      UIManager.RCTWebView.Commands.stopLoading,
217
+      UIManager.RNCWebView.Commands.stopLoading,
218
       null,
218
       null,
219
     );
219
     );
220
   };
220
   };
222
   postMessage = (data: string) => {
222
   postMessage = (data: string) => {
223
     UIManager.dispatchViewManagerCommand(
223
     UIManager.dispatchViewManagerCommand(
224
       this.getWebViewHandle(),
224
       this.getWebViewHandle(),
225
-      UIManager.RCTWebView.Commands.postMessage,
225
+      UIManager.RNCWebView.Commands.postMessage,
226
       [String(data)],
226
       [String(data)],
227
     );
227
     );
228
   };
228
   };
236
   injectJavaScript = (data: string) => {
236
   injectJavaScript = (data: string) => {
237
     UIManager.dispatchViewManagerCommand(
237
     UIManager.dispatchViewManagerCommand(
238
       this.getWebViewHandle(),
238
       this.getWebViewHandle(),
239
-      UIManager.RCTWebView.Commands.injectJavaScript,
239
+      UIManager.RNCWebView.Commands.injectJavaScript,
240
       [data],
240
       [data],
241
     );
241
     );
242
   };
242
   };
290
   };
290
   };
291
 }
291
 }
292
 
292
 
293
-const RCTWebView = requireNativeComponent('RCTWebView');
293
+const RNCWebView = requireNativeComponent('RNCWebView');
294
 
294
 
295
 const styles = StyleSheet.create({
295
 const styles = StyleSheet.create({
296
   container: {
296
   container: {