Skip to content

Instantly share code, notes, and snippets.

@ivandotv
Created October 17, 2023 13:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivandotv/4ba78d55f496d30da7530f0059cd534d to your computer and use it in GitHub Desktop.
Save ivandotv/4ba78d55f496d30da7530f0059cd534d to your computer and use it in GitHub Desktop.
Bottom sheet component sample
// 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