Browse Source

fix(iOS/android getViewManagerConfig): Fix crash with react-native < 0.58

Thibault Malbranche 5 years ago
parent
commit
263fc5ec3c
2 changed files with 17 additions and 3 deletions
  1. 8
    1
      js/WebView.android.js
  2. 9
    2
      js/WebView.ios.js

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

@@ -194,7 +194,14 @@ class WebView extends React.Component<WebViewSharedProps, State> {
194 194
     );
195 195
   }
196 196
 
197
-  getCommands = () => UIManager.getViewManagerConfig('RNCWebView').Commands;
197
+  getViewManagerConfig = viewManagerName => {
198
+    if (!UIManager.getViewManagerConfig) {
199
+      return UIManager[viewManagerName];
200
+    }
201
+    return UIManager.getViewManagerConfig(viewManagerName);
202
+  };
203
+
204
+  getCommands = () => this.getViewManagerConfig('RNCWebView').Commands;
198 205
 
199 206
   goForward = () => {
200 207
     UIManager.dispatchViewManagerCommand(

+ 9
- 2
js/WebView.ios.js View File

@@ -296,10 +296,17 @@ class WebView extends React.Component<WebViewSharedProps, State> {
296 296
     );
297 297
   }
298 298
 
299
+  _getViewManagerConfig = viewManagerName => {
300
+    if (!UIManager.getViewManagerConfig) {
301
+      return UIManager[viewManagerName];
302
+    }
303
+    return UIManager.getViewManagerConfig(viewManagerName);
304
+  };
305
+
299 306
   _getCommands = () =>
300 307
     !this.props.useWebKit
301
-      ? UIManager.getViewManagerConfig('RNCUIWebView').Commands
302
-      : UIManager.getViewManagerConfig('RNCWKWebView').Commands;
308
+      ? this._getViewManagerConfig('RNCUIWebView').Commands
309
+      : this._getViewManagerConfig('RNCWKWebView').Commands;
303 310
 
304 311
   /**
305 312
    * Go forward one page in the web view's history.