iou90 / react-native-autoheight-webview

An auto height webview for React Native
ISC License
492 stars 162 forks source link

Why Use getBoundingClientRect to Get Height Instead of offsetHeight #267

Open 425765923 opened 4 weeks ago

425765923 commented 4 weeks ago

Platform targeting (iOS/Android) IOS Additional context

In utils.js, the default method used to get the web height is getBoundingClientRect, and a timer is set to ensure that the height is correct before stopping further adjustments. However, getBoundingClientRect returns the height relative to the viewport, so if scrolling occurs during the timer interval, it could lead to incorrect height calculations.

So, why not directly use height = ${element}.offsetHeight to ensure that the correct web height is obtained every time?

image