Skip to content

Commit 1f0e93f

Browse files
authored
refactor: added onPress prop to backdrop component (gorhom#1029)(by @tarikpnr)
* feat: adding onPress prop to backdrop component Motivation: There might be specific scenarios where some action needs to be executed on pressing backdrop component. * fix: added backdrop onPress prop to dependency array
1 parent 1a8928f commit 1f0e93f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const BottomSheetBackdropComponent = ({
3030
disappearsOnIndex: _providedDisappearsOnIndex,
3131
enableTouchThrough: _providedEnableTouchThrough,
3232
pressBehavior = DEFAULT_PRESS_BEHAVIOR,
33+
onPress,
3334
style,
3435
children,
3536
}: BottomSheetDefaultBackdropProps) => {
@@ -54,14 +55,16 @@ const BottomSheetBackdropComponent = ({
5455

5556
//#region callbacks
5657
const handleOnPress = useCallback(() => {
58+
onPress?.();
59+
5760
if (pressBehavior === 'close') {
5861
close();
5962
} else if (pressBehavior === 'collapse') {
6063
snapToIndex(disappearsOnIndex as number);
6164
} else if (typeof pressBehavior === 'number') {
6265
snapToIndex(pressBehavior);
6366
}
64-
}, [snapToIndex, close, disappearsOnIndex, pressBehavior]);
67+
}, [snapToIndex, close, disappearsOnIndex, pressBehavior, onPress]);
6568
const handleContainerTouchability = useCallback(
6669
(shouldDisableTouchability: boolean) => {
6770
setPointerEvents(shouldDisableTouchability ? 'none' : 'auto');

src/components/bottomSheetBackdrop/types.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ export interface BottomSheetDefaultBackdropProps
4040
* @default 'close'
4141
*/
4242
pressBehavior?: BackdropPressBehavior;
43+
44+
/**
45+
* Function which will be executed on pressing backdrop component
46+
* @type {Function}
47+
*/
48+
onPress?: () => void;
4349
/**
4450
* Child component that will be rendered on backdrop.
4551
*/

0 commit comments

Comments
 (0)