Skip to content

Commit

Permalink
Using getBoundingClientRect to sum top & height to solve content cut …
Browse files Browse the repository at this point in the history
…off when using margin issue: #179
  • Loading branch information
iou90 committed Nov 9, 2020
1 parent ceead0e commit f30a877
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions autoHeightWebView/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
Expand Down

0 comments on commit f30a877

Please sign in to comment.