Selaa lähdekoodia

RNC changes ios JS

Thibault Malbranche 6 vuotta sitten
vanhempi
commit
2dea7b53ce
2 muutettua tiedostoa jossa 21 lisäystä ja 20 poistoa
  1. 6
    6
      js/WKWebView.ios.js
  2. 15
    14
      js/WebView.ios.js

+ 6
- 6
js/WKWebView.ios.js Näytä tiedosto

@@ -15,9 +15,9 @@ import { requireNativeComponent } from 'react-native';
15 15
 
16 16
 import type {DataDetectorTypes} from './WebViewTypes';
17 17
 
18
-const RCTWKWebView = requireNativeComponent('RCTWKWebView');
18
+const RNCWKWebView = requireNativeComponent('RNCWKWebView');
19 19
 
20
-type RCTWKWebViewProps = $ReadOnly<{|
20
+type RNCWKWebViewProps = $ReadOnly<{|
21 21
   allowsInlineMediaPlayback?: ?boolean,
22 22
   mediaPlaybackRequiresUserAction?: ?boolean,
23 23
   dataDetectorTypes?:
@@ -25,21 +25,21 @@ type RCTWKWebViewProps = $ReadOnly<{|
25 25
     | $ReadOnlyArray<DataDetectorTypes>,
26 26
 |}>;
27 27
 
28
-class WKWebView extends React.Component<RCTWKWebViewProps> {
29
-  componentWillReceiveProps(nextProps: RCTWKWebViewProps) {
28
+class WKWebView extends React.Component<RNCWKWebViewProps> {
29
+  componentWillReceiveProps(nextProps: RNCWKWebViewProps) {
30 30
     this.showRedboxOnPropChanges(nextProps, 'allowsInlineMediaPlayback');
31 31
     this.showRedboxOnPropChanges(nextProps, 'mediaPlaybackRequiresUserAction');
32 32
     this.showRedboxOnPropChanges(nextProps, 'dataDetectorTypes');
33 33
   }
34 34
 
35
-  showRedboxOnPropChanges(nextProps: RCTWKWebViewProps, propName: string) {
35
+  showRedboxOnPropChanges(nextProps: RNCWKWebViewProps, propName: string) {
36 36
     if (this.props[propName] !== nextProps[propName]) {
37 37
       console.error(`Changes to property ${propName} do nothing after the initial render.`);
38 38
     }
39 39
   }
40 40
 
41 41
   render() {
42
-    return <RCTWKWebView {...this.props} />;
42
+    return <RNCWKWebView {...this.props} />;
43 43
   }
44 44
 }
45 45
 

+ 15
- 14
js/WebView.ios.js Näytä tiedosto

@@ -51,11 +51,10 @@ function processDecelerationRate(decelerationRate) {
51 51
   return decelerationRate;
52 52
 }
53 53
 
54
-const RCTUIWebViewManager = NativeModules.UIWebViewManager;
55
-const RCTWKWebViewManager = NativeModules.WKWebViewManager;
54
+const RNCUIWebViewManager = NativeModules.RNCUIWebViewManager;
55
+const RNCWKWebViewManager = NativeModules.RNCWKWebViewManager;
56 56
 
57 57
 const BGWASH = 'rgba(255,255,255,0.8)';
58
-const RCT_WEBVIEW_REF = 'webview';
59 58
 
60 59
 const WebViewState = keyMirror({
61 60
   IDLE: null,
@@ -143,6 +142,8 @@ class WebView extends React.Component<WebViewSharedProps, State> {
143 142
     startInLoadingState: true,
144 143
   };
145 144
 
145
+  webViewRef = React.createRef();
146
+
146 147
   UNSAFE_componentWillMount() {
147 148
     if (this.props.startInLoadingState) {
148 149
       this.setState({ viewState: WebViewState.LOADING });
@@ -181,7 +182,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
181 182
       );
182 183
     } else if (this.state.viewState !== WebViewState.IDLE) {
183 184
       console.error(
184
-        'RCTWebView invalid state encountered: ' + this.state.viewState,
185
+        'RNCWebView invalid state encountered: ' + this.state.viewState,
185 186
       );
186 187
     }
187 188
 
@@ -199,9 +200,9 @@ class WebView extends React.Component<WebViewSharedProps, State> {
199 200
     let viewManager = nativeConfig.viewManager;
200 201
 
201 202
     if (this.props.useWebKit) {
202
-      viewManager = viewManager || RCTWKWebViewManager;
203
+      viewManager = viewManager || RNCWKWebViewManager;
203 204
     } else {
204
-      viewManager = viewManager || RCTUIWebViewManager;
205
+      viewManager = viewManager || RNCUIWebViewManager;
205 206
     }
206 207
 
207 208
     const compiledWhitelist = [
@@ -247,14 +248,14 @@ class WebView extends React.Component<WebViewSharedProps, State> {
247 248
     let NativeWebView = nativeConfig.component;
248 249
 
249 250
     if (this.props.useWebKit) {
250
-      NativeWebView = NativeWebView || RCTWKWebView;
251
+      NativeWebView = NativeWebView || RNCWKWebView;
251 252
     } else {
252
-      NativeWebView = NativeWebView || RCTWebView;
253
+      NativeWebView = NativeWebView || RNCUIWebView;
253 254
     }
254 255
 
255 256
     const webView = (
256 257
       <NativeWebView
257
-        ref={RCT_WEBVIEW_REF}
258
+        ref={webViewRef}
258 259
         key="webViewKey"
259 260
         style={webViewStyles}
260 261
         source={resolveAssetSource(source)}
@@ -292,10 +293,10 @@ class WebView extends React.Component<WebViewSharedProps, State> {
292 293
 
293 294
   _getCommands() {
294 295
     if (!this.props.useWebKit) {
295
-      return UIManager.RCTWebView.Commands;
296
+      return UIManager.RNCUIWebView.Commands;
296 297
     }
297 298
 
298
-    return UIManager.RCTWKWebView.Commands;
299
+    return UIManager.RNCWKWebView.Commands;
299 300
   }
300 301
 
301 302
   /**
@@ -389,7 +390,7 @@ class WebView extends React.Component<WebViewSharedProps, State> {
389 390
    * Returns the native `WebView` node.
390 391
    */
391 392
   getWebViewHandle = () => {
392
-    return ReactNative.findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
393
+    return ReactNative.findNodeHandle(webViewRef.current);
393 394
   };
394 395
 
395 396
   _onLoadingStart = (event: WebViewNavigationEvent) => {
@@ -451,8 +452,8 @@ class WebView extends React.Component<WebViewSharedProps, State> {
451 452
   }
452 453
 }
453 454
 
454
-const RCTWebView = requireNativeComponent('RCTWebView');
455
-const RCTWKWebView = requireNativeComponent('RCTWKWebView');
455
+const RNCUIWebView = requireNativeComponent('RNCUIWebView');
456
+const RNCWKWebView = requireNativeComponent('RNCWKWebView');
456 457
 
457 458
 const styles = StyleSheet.create({
458 459
   container: {