react-native-dmgapp-webview
v1.0.0
Published
react native webview support auto height
Downloads
6
Maintainers
Readme
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
})
}