Skip to content

Commit 6264f49

Browse files
committed
fix(autoHeightBridge): improve document height measurement and Android handling
Ensure body width/html height are set before measuring, force layout using body offsetHeight as fallback, and use getBoundingClientRect (including html/body rects) for more accurate measurements. Prefer bounding rect heights on Android for better accuracy.
1 parent ebf3897 commit 6264f49

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

src/constants/autoHeightBridge.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,17 +50,34 @@ export const AUTO_HEIGHT_BRIDGE = `(() => {
5050
const measureDocumentHeight = () => {
5151
const html = document.documentElement;
5252
const body = document.body;
53+
const isAndroid = navigator.userAgent.includes('Android');
5354
5455
// Ensure body has proper styling for measurement
5556
if (body) {
5657
body.style.height = 'auto';
5758
body.style.minHeight = '100%';
59+
body.style.width = '100%';
60+
}
61+
62+
if (html) {
63+
html.style.height = 'auto';
5864
}
5965
6066
// Force layout recalculation
61-
const forceLayout = html.offsetHeight;
67+
const forceLayout = html.offsetHeight || body.offsetHeight;
68+
69+
// Use getBoundingClientRect for more accurate measurement
70+
const htmlRect = html.getBoundingClientRect();
71+
const bodyRect = body ? body.getBoundingClientRect() : { height: 0 };
72+
73+
if (isAndroid) {
74+
// On Android, prefer getBoundingClientRect for better accuracy
75+
return Math.max(htmlRect.height, bodyRect.height);
76+
}
6277
6378
return Math.max(
79+
htmlRect.height,
80+
bodyRect.height,
6481
html.scrollHeight,
6582
html.offsetHeight,
6683
body ? body.scrollHeight : 0,

0 commit comments

Comments
 (0)