Browse Source

WIP: WebView extraction - Rename android from RNC to RCT

Jamon Holmgren 5 years ago
parent
commit
642620dd98

+ 0
- 4
README.md View File

45
 
45
 
46
 Simply install React Native WebView and then use it in place of the core WebView. Their APIs are currently identical.
46
 Simply install React Native WebView and then use it in place of the core WebView. Their APIs are currently identical.
47
 
47
 
48
-## Contributing
49
-
50
-_Guide coming soon_
51
-
52
 ### Contributor Notes
48
 ### Contributor Notes
53
 
49
 
54
 * I've removed all PropTypes for now. Instead, we'll be moving toward Flow or TypeScript at some later date
50
 * I've removed all PropTypes for now. Instead, we'll be moving toward Flow or TypeScript at some later date

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

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

android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java → android/src/main/java/com/reactnativecommunity/webview/RCTWebViewModule.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 RNCWebViewModule extends ReactContextBaseJavaModule {
9
+public class RCTWebViewModule extends ReactContextBaseJavaModule {
10
 
10
 
11
   private final ReactApplicationContext reactContext;
11
   private final ReactApplicationContext reactContext;
12
 
12
 
13
-  public RNCWebViewModule(ReactApplicationContext reactContext) {
13
+  public RCTWebViewModule(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 "RNCWebView";
20
+    return "RCTWebView";
21
   }
21
   }
22
 }
22
 }

android/src/main/java/com/reactnativecommunity/webview/RNCWebViewPackage.java → android/src/main/java/com/reactnativecommunity/webview/RCTWebViewPackage.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 RNCWebViewPackage implements ReactPackage {
13
+public class RCTWebViewPackage 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 RNCWebViewModule(reactContext));
16
+      return Arrays.<NativeModule>asList(new RCTWebViewModule(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
-        RNCWebViewManager viewManager = new RNCWebViewManager();
26
+        RCTWebViewManager viewManager = new RCTWebViewManager();
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 RNCWebViewManager}.
7
+ * implementation will have to be given as a constructor argument to {@link RCTWebViewManager}.
8
  */
8
  */
9
 public interface WebViewConfig {
9
 public interface WebViewConfig {
10
 
10
 

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

27
 
27
 
28
 const resolveAssetSource = Image.resolveAssetSource;
28
 const resolveAssetSource = Image.resolveAssetSource;
29
 
29
 
30
-const RNC_WEBVIEW_REF = 'webview';
30
+const RCT_WEBVIEW_REF = 'webview';
31
 
31
 
32
 const WebViewState = keyMirror({
32
 const WebViewState = keyMirror({
33
   IDLE: null,
33
   IDLE: null,