From c37ecd52443b3fa90b22d547adae41476ab45204 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Barbet?= Date: Sat, 25 Apr 2020 13:55:19 +0000 Subject: [PATCH] fix: alwaysOpen and ajustToContentHeight #172 --- src/index.tsx | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/index.tsx b/src/index.tsx index da6fa32d..98d1b26f 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -135,6 +135,7 @@ const ModalizeBase = ( const adjustValue = adjustToContentHeight ? undefined : endHeight; const snaps = snapPoint ? [0, endHeight - snapPoint, endHeight] : [0, endHeight]; + const [modalHeightValue, setModalHeightValue] = useState(adjustValue); const [lastSnap, setLastSnap] = useState(snapPoint ? endHeight - snapPoint : 0); const [isVisible, setIsVisible] = useState(false); const [showContent, setShowContent] = useState(true); @@ -150,7 +151,8 @@ const ModalizeBase = ( const beginScrollY = useRef(new Animated.Value(0)).current; const dragY = useRef(new Animated.Value(0)).current; const translateY = useRef(new Animated.Value(screenHeight)).current; - const reverseBeginScrollY = useRef(Animated.multiply(new Animated.Value(-1), beginScrollY)).current; // prettier-ignore + const reverseBeginScrollY = useRef(Animated.multiply(new Animated.Value(-1), beginScrollY)) + .current; const modal = useRef(null); const modalChildren = useRef(null); @@ -167,7 +169,6 @@ const ModalizeBase = ( const dragValue = Animated.add(Animated.multiply(dragY, cancelTranslateY), diffClamp); const value = Animated.add(Animated.multiply(translateY, cancelTranslateY), dragValue); - let modalHeightValue: number | undefined = adjustValue; let willCloseModalize = false; beginScrollY.addListener(({ value }) => setBeginScrollYValue(value)); @@ -351,7 +352,7 @@ const ModalizeBase = ( }), ); - modalHeightValue = value; + setModalHeightValue(value); }; const handleContentViewLayout = ({ nativeEvent }: LayoutChangeEvent): void => { @@ -359,6 +360,12 @@ const ModalizeBase = ( onLayout(nativeEvent); } + if (alwaysOpen && adjustToContentHeight) { + const { height } = nativeEvent.layout; + + return setModalHeightValue(height); + } + if (!adjustToContentHeight) { return; } @@ -747,7 +754,7 @@ const ModalizeBase = ( })); useEffect(() => { - if (alwaysOpen && modalHeightValue) { + if (alwaysOpen && (modalHeightValue || adjustToContentHeight)) { handleAnimateOpen(alwaysOpen); } }, [alwaysOpen, modalHeightValue]); @@ -779,7 +786,7 @@ const ModalizeBase = ( useEffect(() => { const value = adjustToContentHeight ? undefined : endHeight; - modalHeightValue = value; + setModalHeightValue(value); }, [adjustToContentHeight]); useEffect(() => {