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
 'use strict';
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
 import { StyleSheet, Platform, ViewPropTypes } from 'react-native';
5
 import { StyleSheet, Platform, ViewPropTypes } from 'react-native';
6
 
6
 
14
   forwardRef((props, ref) => {
14
   forwardRef((props, ref) => {
15
     const { style, onMessage, onSizeUpdated, scrollEnabledWithZoomedin, scrollEnabled } = props;
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
     const [size, setSize] = useState({
17
     const [size, setSize] = useState({
27
       height: style && style.height ? style.height : 0,
18
       height: style && style.height ? style.height : 0,
28
       width: getWidth(style)
19
       width: getWidth(style)
69
     return (
60
     return (
70
       <WebView
61
       <WebView
71
         {...props}
62
         {...props}
72
-        ref={webView}
63
+        ref={ref}
73
         onMessage={handleMessage}
64
         onMessage={handleMessage}
74
         style={[
65
         style={[
75
           styles.webView,
66
           styles.webView,