Prevent sparse arrays in snapToOffsets (#9329)

* prevent sparse arrays in snapToOffsets

* wait, sparse arrays don't work like that

* more readable check even if it's technically useless

* make the second check actually work
This commit is contained in:
Samuel Newman
2025-11-04 19:08:43 +02:00
parent 0d1060419f
commit a232372ce7
+7 -2
View File
@@ -83,7 +83,12 @@ export function InterestTabs({
function handleTabLayout(index: number, x: number, width: number) {
if (!tabOffsets.length) {
pendingTabOffsets.current[index] = {x, width}
if (pendingTabOffsets.current.length === interests.length) {
// not only do we check if the length is equal to the number of interests,
// but we also need to ensure that the array isn't sparse. `.filter()`
// removes any empty slots from the array
if (
pendingTabOffsets.current.filter(o => !!o).length === interests.length
) {
setTabOffsets(pendingTabOffsets.current)
}
}
@@ -205,7 +210,7 @@ export function InterestTabs({
showsHorizontalScrollIndicator={false}
decelerationRate="fast"
snapToOffsets={
tabOffsets.length === interests.length
tabOffsets.filter(o => !!o).length === interests.length
? tabOffsets.map(o => o.x - tokens.space.xl)
: undefined
}