Auto calculating react-native webview height based on content height

<WebView
    source={{url: 'https://www.google.com'}}
    style={{
        height: webviewHeight
    }}
injectedJavaScript={'window.location.hash = 1;
             var calculator = document.createElement("div");
             calculator.id = "height-calculator";
             while (document.body.firstChild) {
                calculator.appendChild(document.body.firstChild);
             }
             document.body.appendChild(calculator);
             document.title = calculator.clientHeight;'}
    javaScriptEnabled ={true}
    scrollEnabled={false}
    onNavigationStateChange={(navStates) => {
        if (navStates.title && !isNaN(navStates.title)) {
            const htmlHeight = Number(navStates.title) //convert to number
            setWebViewHeight(htmlHeight);
            
        }
    }}
/>

Comments

Popular posts from this blog

MATLAB code for Circular Convolution using Matrix method

Positive number pipe in angular 2+