Created
October 17, 2023 13:52
-
-
Save ivandotv/4ba78d55f496d30da7530f0059cd534d to your computer and use it in GitHub Desktop.
Bottom sheet component sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// create a reference to the bottom sheet | |
const bottomSheetRef = useRef<BottomSheet>(null) | |
//custom snap points | |
const snapPoints = ["30%", "60%"] | |
//track the current snap point index | |
const [currentIndex, setCurrentIndex] = useState(-1) | |
// track on which snap point index bottom sheet is currently | |
const handleSheetChanges = useCallback((index: number) => { | |
setShowBottomSheet(index > -1) | |
setCurrentIndex(index) | |
}, []) | |
// expand bottom sheet when showBottomSheet is true to the first snap point | |
useEffect(() => { | |
if (showBottomSheet) { | |
bottomSheetRef.current?.snapToIndex(0) | |
} else { | |
bottomSheetRef.current?.close() | |
} | |
}, [showBottomSheet]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment