Selaa lähdekoodia

Forwarding ref to WebView

iou90 4 vuotta sitten
vanhempi
commit
24af8f85af
1 muutettua tiedostoa jossa 2 lisäystä ja 11 poistoa
  1. 2
    11
      autoHeightWebView/index.js

+ 2
- 11
autoHeightWebView/index.js Näytä tiedosto

@@ -1,6 +1,6 @@
1 1
 'use strict';
2 2
 
3
-import React, { useState, useEffect, useRef, useImperativeHandle, forwardRef } from 'react';
3
+import React, { useState, useEffect, forwardRef } from 'react';
4 4
 
5 5
 import { StyleSheet, Platform, ViewPropTypes } from 'react-native';
6 6
 
@@ -14,15 +14,6 @@ const AutoHeightWebView = React.memo(
14 14
   forwardRef((props, ref) => {
15 15
     const { style, onMessage, onSizeUpdated, scrollEnabledWithZoomedin, scrollEnabled } = props;
16 16
 
17
-    let webView = useRef();
18
-    useImperativeHandle(ref, () => ({
19
-      stopLoading: () => webView.current.stopLoading(),
20
-      goForward: () => webView.current.goForward(),
21
-      goBack: () => webView.current.goBack(),
22
-      reload: () => webView.current.reload(),
23
-      injectJavaScript: script => webView.current.injectJavaScript(script)
24
-    }));
25
-
26 17
     const [size, setSize] = useState({
27 18
       height: style && style.height ? style.height : 0,
28 19
       width: getWidth(style)
@@ -69,7 +60,7 @@ const AutoHeightWebView = React.memo(
69 60
     return (
70 61
       <WebView
71 62
         {...props}
72
-        ref={webView}
63
+        ref={ref}
73 64
         onMessage={handleMessage}
74 65
         style={[
75 66
           styles.webView,