From bda24353cfcbfb0f5925c5bb1810debd00e57ff6 Mon Sep 17 00:00:00 2001 From: Ivan Total99 Date: Fri, 28 Jul 2023 14:45:32 -0400 Subject: [PATCH] Add new functionality. 1.- Add callback onMove => return Index and height 2.- Add new method getIndex() --- src/bottomDrawer.tsx | 8 ++++++++ src/type.ts | 1 + 2 files changed, 9 insertions(+) diff --git a/src/bottomDrawer.tsx b/src/bottomDrawer.tsx index a70a111..17a1ac6 100644 --- a/src/bottomDrawer.tsx +++ b/src/bottomDrawer.tsx @@ -62,6 +62,7 @@ const BottomDrawer: ForwardRefRenderFunction< overDrag = true, safeTopOffset = defaultSafeTopOffset, onBackPress = null, + onMove = null, // enableDragWhenKeyboardOpened = false, } = props; @@ -124,6 +125,8 @@ const BottomDrawer: ForwardRefRenderFunction< } }; + const getIndex = () => {return currentIndex.current} + const handleSnapToPosition = ( position: number, config?: SnapToPositionConfig, @@ -178,10 +181,14 @@ const BottomDrawer: ForwardRefRenderFunction< animatedHeight.flattenOffset(); const {dy} = gestureState; if (dy < -safeTopOffset && checkIfAvailable(currentIndex.current + 1)) { + if(onMove) + onMove(currentIndex.current+1, snapPoints[currentIndex.current + 1]); return handleSnapToIndex(currentIndex.current + 1); } if (dy > safeTopOffset) { if (checkIfAvailable(currentIndex.current - 1)) { + if(onMove) + onMove(currentIndex.current-1, snapPoints[currentIndex.current - 1]); return handleSnapToIndex(currentIndex.current - 1); } if (closeOnDragDown) { @@ -204,6 +211,7 @@ const BottomDrawer: ForwardRefRenderFunction< snapToIndex: handleSnapToIndex, close: handleClose, isOpen: handleIsOpen, + getIndex: getIndex }; useImperativeHandle(ref, (): any => bottomSheetMethods); diff --git a/src/type.ts b/src/type.ts index f4db07f..4904224 100644 --- a/src/type.ts +++ b/src/type.ts @@ -33,6 +33,7 @@ export type BottomDrawerProps = { }; onClose?: () => void; onOpen?: () => void; + onMove?: (index: number, height: number) => void; onBackPress?: () => void; children: ReactNode; openOnMount?: boolean;