Przeglądaj źródła

Merge pull request #51 from react-native-community/renaming/rct-rnc-android

(Contains #50) Renaming rct rnc android to stay consistent with iOS
Thibault Malbranche 6 lat temu
rodzic
commit
82b142b25b
No account linked to committer's email address

android/src/main/java/com/reactnativecommunity/webview/RCTWebViewManager.java → android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java Wyświetl plik

@@ -84,10 +84,10 @@ import org.json.JSONObject;
84 84
  *  - canGoBack - boolean, whether there is anything on a history stack to go back
85 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 92
   protected static final String HTML_ENCODING = "UTF-8";
93 93
   protected static final String HTML_MIME_TYPE = "text/html";
@@ -109,7 +109,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
109 109
   protected WebViewConfig mWebViewConfig;
110 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 114
     protected boolean mLastLoadFailed = false;
115 115
     protected @Nullable ReadableArray mUrlPrefixesForDefaultIntent;
@@ -120,7 +120,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
120 120
       super.onPageFinished(webView, url);
121 121
 
122 122
       if (!mLastLoadFailed) {
123
-        RCTWebView reactWebView = (RCTWebView) webView;
123
+        RNCWebView reactWebView = (RNCWebView) webView;
124 124
         reactWebView.callInjectedJavaScript();
125 125
         reactWebView.linkBridge();
126 126
         emitFinishEvent(webView, url);
@@ -243,15 +243,15 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
243 243
    * Subclass of {@link WebView} that implements {@link LifecycleEventListener} interface in order
244 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 247
     protected @Nullable String injectedJS;
248 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 255
         mContext = c;
256 256
       }
257 257
 
@@ -268,7 +268,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
268 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 272
       super(reactContext);
273 273
     }
274 274
 
@@ -290,19 +290,19 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
290 290
     @Override
291 291
     public void setWebViewClient(WebViewClient client) {
292 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 300
     public void setInjectedJavaScript(@Nullable String js) {
301 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 308
     public void setMessagingEnabled(boolean enabled) {
@@ -312,7 +312,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
312 312
 
313 313
       messagingEnabled = enabled;
314 314
       if (enabled) {
315
-        addJavascriptInterface(createRCTWebViewBridge(this), BRIDGE_NAME);
315
+        addJavascriptInterface(createRNCWebViewBridge(this), BRIDGE_NAME);
316 316
         linkBridge();
317 317
       } else {
318 318
         removeJavascriptInterface(BRIDGE_NAME);
@@ -375,14 +375,14 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
375 375
     }
376 376
   }
377 377
 
378
-  public RCTWebViewManager() {
378
+  public RNCWebViewManager() {
379 379
     mWebViewConfig = new WebViewConfig() {
380 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 386
     mWebViewConfig = webViewConfig;
387 387
   }
388 388
 
@@ -391,14 +391,14 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
391 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 398
   @Override
399 399
   @TargetApi(Build.VERSION_CODES.LOLLIPOP)
400 400
   protected WebView createViewInstance(ThemedReactContext reactContext) {
401
-    RCTWebView webView = createRCTWebViewInstance(reactContext);
401
+    RNCWebView webView = createRNCWebViewInstance(reactContext);
402 402
     webView.setWebChromeClient(new WebChromeClient() {
403 403
       @Override
404 404
       public boolean onConsoleMessage(ConsoleMessage message) {
@@ -489,12 +489,12 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
489 489
 
490 490
   @ReactProp(name = "injectedJavaScript")
491 491
   public void setInjectedJavaScript(WebView view, @Nullable String injectedJavaScript) {
492
-    ((RCTWebView) view).setInjectedJavaScript(injectedJavaScript);
492
+    ((RNCWebView) view).setInjectedJavaScript(injectedJavaScript);
493 493
   }
494 494
 
495 495
   @ReactProp(name = "messagingEnabled")
496 496
   public void setMessagingEnabled(WebView view, boolean enabled) {
497
-    ((RCTWebView) view).setMessagingEnabled(enabled);
497
+    ((RNCWebView) view).setMessagingEnabled(enabled);
498 498
   }
499 499
 
500 500
   @ReactProp(name = "source")
@@ -583,7 +583,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
583 583
   public void setUrlPrefixesForDefaultIntent(
584 584
       WebView view,
585 585
       @Nullable ReadableArray urlPrefixesForDefaultIntent) {
586
-    RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
586
+    RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
587 587
     if (client != null && urlPrefixesForDefaultIntent != null) {
588 588
       client.setUrlPrefixesForDefaultIntent(urlPrefixesForDefaultIntent);
589 589
     }
@@ -607,7 +607,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
607 607
   public void setOriginWhitelist(
608 608
     WebView view,
609 609
     @Nullable ReadableArray originWhitelist) {
610
-    RCTWebViewClient client = ((RCTWebView) view).getRCTWebViewClient();
610
+    RNCWebViewClient client = ((RNCWebView) view).getRNCWebViewClient();
611 611
     if (client != null && originWhitelist != null) {
612 612
       List<Pattern> whiteList = new LinkedList<>();
613 613
       for (int i = 0 ; i < originWhitelist.size() ; i++) {
@@ -620,7 +620,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
620 620
   @Override
621 621
   protected void addEventEmitters(ThemedReactContext reactContext, WebView view) {
622 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 626
   @Override
@@ -652,7 +652,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
652 652
         break;
653 653
       case COMMAND_POST_MESSAGE:
654 654
         try {
655
-          RCTWebView reactWebView = (RCTWebView) root;
655
+          RNCWebView reactWebView = (RNCWebView) root;
656 656
           JSONObject eventInitDict = new JSONObject();
657 657
           eventInitDict.put("data", args.getString(0));
658 658
           reactWebView.evaluateJavascriptWithFallback("(function () {" +
@@ -671,7 +671,7 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
671 671
         }
672 672
         break;
673 673
       case COMMAND_INJECT_JAVASCRIPT:
674
-        RCTWebView reactWebView = (RCTWebView) root;
674
+        RNCWebView reactWebView = (RNCWebView) root;
675 675
         reactWebView.evaluateJavascriptWithFallback(args.getString(0));
676 676
         break;
677 677
     }
@@ -680,8 +680,8 @@ public class RCTWebViewManager extends SimpleViewManager<WebView> {
680 680
   @Override
681 681
   public void onDropViewInstance(WebView webView) {
682 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 687
   protected WebView.PictureListener getPictureListener() {

android/src/main/java/com/reactnativecommunity/webview/RCTWebViewModule.java → android/src/main/java/com/reactnativecommunity/webview/RNCWebViewModule.java Wyświetl plik

@@ -6,17 +6,17 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
6 6
 import com.facebook.react.bridge.ReactMethod;
7 7
 import com.facebook.react.bridge.Callback;
8 8
 
9
-public class RCTWebViewModule extends ReactContextBaseJavaModule {
9
+public class RNCWebViewModule extends ReactContextBaseJavaModule {
10 10
 
11 11
   private final ReactApplicationContext reactContext;
12 12
 
13
-  public RCTWebViewModule(ReactApplicationContext reactContext) {
13
+  public RNCWebViewModule(ReactApplicationContext reactContext) {
14 14
     super(reactContext);
15 15
     this.reactContext = reactContext;
16 16
   }
17 17
 
18 18
   @Override
19 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 Wyświetl plik

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

+ 1
- 1
android/src/main/java/com/reactnativecommunity/webview/WebViewConfig.java Wyświetl plik

@@ -4,7 +4,7 @@ import android.webkit.WebView;
4 4
 
5 5
 /**
6 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 9
 public interface WebViewConfig {
10 10
 

+ 13
- 13
js/WebView.android.js Wyświetl plik

@@ -39,8 +39,6 @@ import type {
39 39
 
40 40
 const resolveAssetSource = Image.resolveAssetSource;
41 41
 
42
-const RCT_WEBVIEW_REF = 'webview';
43
-
44 42
 const WebViewState = keyMirror({
45 43
   IDLE: null,
46 44
   LOADING: null,
@@ -78,6 +76,8 @@ class WebView extends React.Component<WebViewSharedProps, State> {
78 76
     startInLoadingState: true,
79 77
   };
80 78
 
79
+  webViewRef = React.createRef();
80
+
81 81
   UNSAFE_componentWillMount() {
82 82
     if (this.props.startInLoadingState) {
83 83
       this.setState({ viewState: WebViewState.LOADING });
@@ -101,7 +101,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
101 101
         );
102 102
     } else if (this.state.viewState !== WebViewState.IDLE) {
103 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,11 +135,11 @@ class WebView extends React.Component<WebViewSharedProps, State> {
135 135
       WebViewShared.originWhitelistToRegex,
136 136
     );
137 137
 
138
-    let NativeWebView = nativeConfig.component || RCTWebView;
138
+    let NativeWebView = nativeConfig.component || RNCWebView;
139 139
 
140 140
     const webView = (
141 141
       <NativeWebView
142
-        ref={RCT_WEBVIEW_REF}
142
+        ref={this.webViewRef}
143 143
         key="webViewKey"
144 144
         style={webViewStyles}
145 145
         source={resolveAssetSource(source)}
@@ -187,7 +187,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
187 187
   goForward = () => {
188 188
     UIManager.dispatchViewManagerCommand(
189 189
       this.getWebViewHandle(),
190
-      UIManager.RCTWebView.Commands.goForward,
190
+      UIManager.RNCWebView.Commands.goForward,
191 191
       null,
192 192
     );
193 193
   };
@@ -195,7 +195,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
195 195
   goBack = () => {
196 196
     UIManager.dispatchViewManagerCommand(
197 197
       this.getWebViewHandle(),
198
-      UIManager.RCTWebView.Commands.goBack,
198
+      UIManager.RNCWebView.Commands.goBack,
199 199
       null,
200 200
     );
201 201
   };
@@ -206,7 +206,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
206 206
     });
207 207
     UIManager.dispatchViewManagerCommand(
208 208
       this.getWebViewHandle(),
209
-      UIManager.RCTWebView.Commands.reload,
209
+      UIManager.RNCWebView.Commands.reload,
210 210
       null,
211 211
     );
212 212
   };
@@ -214,7 +214,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
214 214
   stopLoading = () => {
215 215
     UIManager.dispatchViewManagerCommand(
216 216
       this.getWebViewHandle(),
217
-      UIManager.RCTWebView.Commands.stopLoading,
217
+      UIManager.RNCWebView.Commands.stopLoading,
218 218
       null,
219 219
     );
220 220
   };
@@ -222,7 +222,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
222 222
   postMessage = (data: string) => {
223 223
     UIManager.dispatchViewManagerCommand(
224 224
       this.getWebViewHandle(),
225
-      UIManager.RCTWebView.Commands.postMessage,
225
+      UIManager.RNCWebView.Commands.postMessage,
226 226
       [String(data)],
227 227
     );
228 228
   };
@@ -236,7 +236,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
236 236
   injectJavaScript = (data: string) => {
237 237
     UIManager.dispatchViewManagerCommand(
238 238
       this.getWebViewHandle(),
239
-      UIManager.RCTWebView.Commands.injectJavaScript,
239
+      UIManager.RNCWebView.Commands.injectJavaScript,
240 240
       [data],
241 241
     );
242 242
   };
@@ -252,7 +252,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
252 252
   };
253 253
 
254 254
   getWebViewHandle = () => {
255
-    return ReactNative.findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
255
+    return ReactNative.findNodeHandle(this.webViewRef.current);
256 256
   };
257 257
 
258 258
   onLoadingStart = (event: WebViewNavigationEvent) => {
@@ -290,7 +290,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
290 290
   };
291 291
 }
292 292
 
293
-const RCTWebView = requireNativeComponent('RCTWebView');
293
+const RNCWebView = requireNativeComponent('RNCWebView');
294 294
 
295 295
 const styles = StyleSheet.create({
296 296
   container: {