Browse Source

Forwarding ref to WebView

iou90 4 years ago
parent
commit
24af8f85af
1 changed files with 2 additions and 11 deletions
  1. 2
    11
      autoHeightWebView/index.js

+ 2
- 11
autoHeightWebView/index.js View File

@@ -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,