Browse Source

RNC changes ios JS

Thibault Malbranche 6 years ago
parent
commit
2dea7b53ce
2 changed files with 21 additions and 20 deletions
  1. 6
    6
      js/WKWebView.ios.js
  2. 15
    14
      js/WebView.ios.js

+ 6
- 6
js/WKWebView.ios.js View File

15
 
15
 
16
 import type {DataDetectorTypes} from './WebViewTypes';
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
   allowsInlineMediaPlayback?: ?boolean,
21
   allowsInlineMediaPlayback?: ?boolean,
22
   mediaPlaybackRequiresUserAction?: ?boolean,
22
   mediaPlaybackRequiresUserAction?: ?boolean,
23
   dataDetectorTypes?:
23
   dataDetectorTypes?:
25
     | $ReadOnlyArray<DataDetectorTypes>,
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
     this.showRedboxOnPropChanges(nextProps, 'allowsInlineMediaPlayback');
30
     this.showRedboxOnPropChanges(nextProps, 'allowsInlineMediaPlayback');
31
     this.showRedboxOnPropChanges(nextProps, 'mediaPlaybackRequiresUserAction');
31
     this.showRedboxOnPropChanges(nextProps, 'mediaPlaybackRequiresUserAction');
32
     this.showRedboxOnPropChanges(nextProps, 'dataDetectorTypes');
32
     this.showRedboxOnPropChanges(nextProps, 'dataDetectorTypes');
33
   }
33
   }
34
 
34
 
35
-  showRedboxOnPropChanges(nextProps: RCTWKWebViewProps, propName: string) {
35
+  showRedboxOnPropChanges(nextProps: RNCWKWebViewProps, propName: string) {
36
     if (this.props[propName] !== nextProps[propName]) {
36
     if (this.props[propName] !== nextProps[propName]) {
37
       console.error(`Changes to property ${propName} do nothing after the initial render.`);
37
       console.error(`Changes to property ${propName} do nothing after the initial render.`);
38
     }
38
     }
39
   }
39
   }
40
 
40
 
41
   render() {
41
   render() {
42
-    return <RCTWKWebView {...this.props} />;
42
+    return <RNCWKWebView {...this.props} />;
43
   }
43
   }
44
 }
44
 }
45
 
45
 

+ 15
- 14
js/WebView.ios.js View File

51
   return decelerationRate;
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
 const BGWASH = 'rgba(255,255,255,0.8)';
57
 const BGWASH = 'rgba(255,255,255,0.8)';
58
-const RCT_WEBVIEW_REF = 'webview';
59
 
58
 
60
 const WebViewState = keyMirror({
59
 const WebViewState = keyMirror({
61
   IDLE: null,
60
   IDLE: null,
143
     startInLoadingState: true,
142
     startInLoadingState: true,
144
   };
143
   };
145
 
144
 
145
+  webViewRef = React.createRef();
146
+
146
   UNSAFE_componentWillMount() {
147
   UNSAFE_componentWillMount() {
147
     if (this.props.startInLoadingState) {
148
     if (this.props.startInLoadingState) {
148
       this.setState({ viewState: WebViewState.LOADING });
149
       this.setState({ viewState: WebViewState.LOADING });
181
       );
182
       );
182
     } else if (this.state.viewState !== WebViewState.IDLE) {
183
     } else if (this.state.viewState !== WebViewState.IDLE) {
183
       console.error(
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
     let viewManager = nativeConfig.viewManager;
200
     let viewManager = nativeConfig.viewManager;
200
 
201
 
201
     if (this.props.useWebKit) {
202
     if (this.props.useWebKit) {
202
-      viewManager = viewManager || RCTWKWebViewManager;
203
+      viewManager = viewManager || RNCWKWebViewManager;
203
     } else {
204
     } else {
204
-      viewManager = viewManager || RCTUIWebViewManager;
205
+      viewManager = viewManager || RNCUIWebViewManager;
205
     }
206
     }
206
 
207
 
207
     const compiledWhitelist = [
208
     const compiledWhitelist = [
247
     let NativeWebView = nativeConfig.component;
248
     let NativeWebView = nativeConfig.component;
248
 
249
 
249
     if (this.props.useWebKit) {
250
     if (this.props.useWebKit) {
250
-      NativeWebView = NativeWebView || RCTWKWebView;
251
+      NativeWebView = NativeWebView || RNCWKWebView;
251
     } else {
252
     } else {
252
-      NativeWebView = NativeWebView || RCTWebView;
253
+      NativeWebView = NativeWebView || RNCUIWebView;
253
     }
254
     }
254
 
255
 
255
     const webView = (
256
     const webView = (
256
       <NativeWebView
257
       <NativeWebView
257
-        ref={RCT_WEBVIEW_REF}
258
+        ref={webViewRef}
258
         key="webViewKey"
259
         key="webViewKey"
259
         style={webViewStyles}
260
         style={webViewStyles}
260
         source={resolveAssetSource(source)}
261
         source={resolveAssetSource(source)}
292
 
293
 
293
   _getCommands() {
294
   _getCommands() {
294
     if (!this.props.useWebKit) {
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
    * Returns the native `WebView` node.
390
    * Returns the native `WebView` node.
390
    */
391
    */
391
   getWebViewHandle = () => {
392
   getWebViewHandle = () => {
392
-    return ReactNative.findNodeHandle(this.refs[RCT_WEBVIEW_REF]);
393
+    return ReactNative.findNodeHandle(webViewRef.current);
393
   };
394
   };
394
 
395
 
395
   _onLoadingStart = (event: WebViewNavigationEvent) => {
396
   _onLoadingStart = (event: WebViewNavigationEvent) => {
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
 const styles = StyleSheet.create({
458
 const styles = StyleSheet.create({
458
   container: {
459
   container: {