From f30a8773084bbeff1555d583420b745c43ff06ab Mon Sep 17 00:00:00 2001 From: iou90 Date: Mon, 9 Nov 2020 18:56:03 +0800 Subject: [PATCH] Using getBoundingClientRect to sum top & height to solve content cut off when using margin issue: https://github.com/iou90/react-native-autoheight-webview/issues/179 --- autoHeightWebView/utils.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/autoHeightWebView/utils.js b/autoHeightWebView/utils.js index bf5b1bb..a1dc651 100644 --- a/autoHeightWebView/utils.js +++ b/autoHeightWebView/utils.js @@ -37,8 +37,15 @@ const updateSizeWithMessage = (element, scalesPageToFit) => } clearTimeout(checkPostMessageTimeout); - height = ${element}.offsetHeight || document.documentElement.offsetHeight; - width = ${element}.offsetWidth || document.documentElement.offsetWidth; + var result = ${element}.getBoundingClientRect() + height = result.height + result.top; + if(!height) { + height = document.documentElement.offsetHeight + } + width = result.width; + if(!width) { + width = document.documentElement.offsetWidth + } window.ReactNativeWebView.postMessage(JSON.stringify({ width: Math.min(width, screen.width), height: height * usingScale }));