From df9d1c1a4b83c2ab49aa046b364fa08675f52e02 Mon Sep 17 00:00:00 2001 From: JulienIzz Date: Thu, 21 Mar 2024 15:00:42 +0100 Subject: [PATCH] fix: prevent setting virtualized list size to zero Can happen when using a tab navigator for example, page is still mounted so onlayout will be triggered, but size will be set to 0 --- .../components/virtualizedList/VirtualizedListWithSize.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedListWithSize.tsx b/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedListWithSize.tsx index 6b491f62..16eb09a8 100644 --- a/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedListWithSize.tsx +++ b/packages/lib/src/spatial-navigation/components/virtualizedList/VirtualizedListWithSize.tsx @@ -24,8 +24,10 @@ export const VirtualizedListWithSize = typedMemo( onLayout={(event) => { if (!hasAlreadyRendered) { const sizeKey = isVertical ? 'height' : 'width'; - setListSizeInPx(event.nativeEvent.layout[sizeKey]); - setHasAlreadyRendered(true); + if (event.nativeEvent.layout[sizeKey] !== 0) { + setListSizeInPx(event.nativeEvent.layout[sizeKey]); + setHasAlreadyRendered(true); + } } }} testID={props.testID ? props.testID + '-size-giver' : undefined}