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:
@@ -83,7 +83,12 @@ export function InterestTabs({
|
|||||||
function handleTabLayout(index: number, x: number, width: number) {
|
function handleTabLayout(index: number, x: number, width: number) {
|
||||||
if (!tabOffsets.length) {
|
if (!tabOffsets.length) {
|
||||||
pendingTabOffsets.current[index] = {x, width}
|
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)
|
setTabOffsets(pendingTabOffsets.current)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,7 +210,7 @@ export function InterestTabs({
|
|||||||
showsHorizontalScrollIndicator={false}
|
showsHorizontalScrollIndicator={false}
|
||||||
decelerationRate="fast"
|
decelerationRate="fast"
|
||||||
snapToOffsets={
|
snapToOffsets={
|
||||||
tabOffsets.length === interests.length
|
tabOffsets.filter(o => !!o).length === interests.length
|
||||||
? tabOffsets.map(o => o.x - tokens.space.xl)
|
? tabOffsets.map(o => o.x - tokens.space.xl)
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user