1.0.0 • Published 7 years ago

react-native-dmgapp-webview v1.0.0

Weekly downloads
2
License
MIT
Repository
-
Last release
7 years ago

react-native-dmgapp-webview

Add autoHeight prop to WebView

Usage

npm install --save react-native-dmgapp-webview
or
yarn add react-native-dmgapp-webview
  import DMGAPPWebView from 'react-native-dmgapp-webview'
  
  class SimpleApp extends React.Component {
    render () {
      return (
        <DMGAPPWebView
          ...
          autoHeight={true}
        />
      )
    }
  }

How to work

use injectedJavaScript inject code

  var isComplete = function() {
    if (document.readyState === "complete" && document.documentElement.offsetWidth > 0) {
      setTimeout(function(){
        window.postMessage(document.documentElement.offsetHeight);
      }, 100);
    } else {
      setTimeout(function(){
        isComplete();
      }, 100);
    }
  };
  
  isComplete();

when onMessage will refresh WebView height

  onMessage = (event) => {
    const webHeight = parseInt(event.nativeEvent.data)
    this.setState({
      webHeight
    })
  }