@@ -140,28 +140,30 @@ class ViewabilityHelper {
140
140
return false ;
141
141
}
142
142
const itemTop = ( horizontal ? itemLayout . x : itemLayout . y ) - scrollOffset ;
143
- const itemSize = horizontal ? itemLayout . width : itemLayout . height ;
144
- const listMainSize = horizontal
145
- ? listSize . width - topViewabilityInset - bottomViewabilityInset
146
- : listSize . height - topViewabilityInset - bottomViewabilityInset ;
147
- const pixelsVisible =
148
- Math . min ( itemTop + itemSize , listMainSize + topViewabilityInset ) -
149
- Math . max ( itemTop , 0 ) ;
143
+ const itemEnd =
144
+ itemTop + ( horizontal ? itemLayout . width : itemLayout . height ) ;
145
+ const listStart = topViewabilityInset ;
146
+ const listEnd =
147
+ ( horizontal ? listSize . width : listSize . height ) - bottomViewabilityInset ;
148
+ const visibleStart = Math . max ( itemTop , listStart ) ;
149
+ const visibleEnd = Math . min ( itemEnd , listEnd ) ;
150
+ const pixelsVisible = Math . max ( 0 , visibleEnd - visibleStart ) ;
150
151
151
152
// Always consider item fully viewable if it is fully visible, regardless of the `viewAreaCoveragePercentThreshold`
152
153
// Account for floating point imprecision.
154
+ const itemSize = horizontal ? itemLayout . width : itemLayout . height ;
153
155
if ( Math . abs ( pixelsVisible - itemSize ) <= 0.001 ) {
154
156
return true ;
155
157
}
156
158
// Skip checking item if it's not visible at all
157
- if ( pixelsVisible == = 0 ) {
159
+ if ( pixelsVisible < = 0 ) {
158
160
return false ;
159
161
}
160
162
const viewAreaMode =
161
163
viewAreaCoveragePercentThreshold !== null &&
162
164
viewAreaCoveragePercentThreshold !== undefined ;
163
165
const percent = viewAreaMode
164
- ? pixelsVisible / ( listMainSize + topViewabilityInset )
166
+ ? pixelsVisible / ( listEnd - listStart )
165
167
: pixelsVisible / itemSize ;
166
168
const viewableAreaPercentThreshold = viewAreaMode
167
169
? viewAreaCoveragePercentThreshold * 0.01
0 commit comments