From 7bd56ec3abb95d19670b7feb0f99c4cc03f3fbda Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Tue, 27 Apr 2021 10:56:23 -0300 Subject: [PATCH] fix: re-add useMemo for snap points --- src/components/BottomSheet.tsx | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/components/BottomSheet.tsx b/src/components/BottomSheet.tsx index d720bc36..e176fb6a 100644 --- a/src/components/BottomSheet.tsx +++ b/src/components/BottomSheet.tsx @@ -342,13 +342,14 @@ export const BottomSheet: React.FC = ({ setListHeight(e.nativeEvent.layout.height); }; - const contentHeight = titleHeight + listHeight; - const maxLimit = 0.85 * screenHeight; - let snapPoints = [1]; - - if (contentHeight > 0) { - snapPoints = contentHeight < maxLimit ? [contentHeight] : [maxLimit]; - } + const snapPoints = useMemo(() => { + const contentHeight = titleHeight + listHeight; + const maxLimit = 0.85 * screenHeight; + if (contentHeight === 0) { + return [1]; + } + return contentHeight < maxLimit ? [contentHeight] : [maxLimit]; + }, [listHeight, titleHeight, screenHeight]); const expandSection = (sectionKey: string) => { const animations: Animated.CompositeAnimation[] = [];