Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement callbacks functions to bottomsheet component #5

Merged
merged 1 commit into from
Nov 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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