Skip to content

Commit

Permalink
feat: implement callbacks functions to bottomsheet component
Browse files Browse the repository at this point in the history
  • Loading branch information
sourfanta authored and stanleyugwu committed Nov 8, 2023
1 parent 22b93e8 commit 002b762
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/components/bottomSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const BottomSheet = forwardRef<BottomSheetMethods, BottomSheetProps>(
closeDuration = DEFAULT_CLOSE_ANIMATION_DURATION,
customEasingFunction,
android_closeOnBackPress = true,
onClose,
onOpen,
},
ref
) => {
Expand Down Expand Up @@ -314,6 +316,10 @@ const BottomSheet = forwardRef<BottomSheetMethods, BottomSheetProps>(
Animators.animateHeight(convertedHeight, openDuration).start();
}
setSheetOpen(true);

if (onOpen) {
onOpen();
}
};

const closeBottomSheet = () => {
Expand All @@ -334,6 +340,10 @@ const BottomSheet = forwardRef<BottomSheetMethods, BottomSheetProps>(
setSheetOpen(false);
removeKeyboardListeners();
Keyboard.dismiss();

if (onClose) {
onClose();
}
};

const containerViewLayoutHandler = (event: LayoutChangeEvent) => {
Expand Down
30 changes: 30 additions & 0 deletions src/components/bottomSheet/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,36 @@ interface BottomSheetProps {
* @default {true}
*/
android_closeOnBackPress?: boolean;

/**
* Сallback function that is called when the bottom sheet starts to close
*
* @example
* <BottomSheet
* onClose={() => {
* console.log('Bottom Sheet closing.');
* }}
* />
*
* @type {Function}
* @default undefined
*/
onClose?: Function;

/**
* Сallback function that is called when the bottom sheet starts to open
*
* @example
* <BottomSheet
* onOpen={() => {
* console.log('Bottom Sheet opening.');
* }}
* />
*
* @type {Function}
* @default undefined
*/
onOpen?: Function;
}

export {
Expand Down

0 comments on commit 002b762

Please sign in to comment.