Skip to content

Commit

Permalink
refactor: added onPress prop to backdrop component (#1029)(by @tarikpnr)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tarikfp committed Sep 17, 2022
1 parent 1a8928f commit 1f0e93f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
Expand Up @@ -30,6 +30,7 @@ const BottomSheetBackdropComponent = ({
disappearsOnIndex: _providedDisappearsOnIndex,
enableTouchThrough: _providedEnableTouchThrough,
pressBehavior = DEFAULT_PRESS_BEHAVIOR,
onPress,
style,
children,
}: BottomSheetDefaultBackdropProps) => {
Expand All @@ -54,14 +55,16 @@ const BottomSheetBackdropComponent = ({

//#region callbacks
const handleOnPress = useCallback(() => {
onPress?.();

if (pressBehavior === 'close') {
close();
} else if (pressBehavior === 'collapse') {
snapToIndex(disappearsOnIndex as number);
} else if (typeof pressBehavior === 'number') {
snapToIndex(pressBehavior);
}
}, [snapToIndex, close, disappearsOnIndex, pressBehavior]);
}, [snapToIndex, close, disappearsOnIndex, pressBehavior, onPress]);
const handleContainerTouchability = useCallback(
(shouldDisableTouchability: boolean) => {
setPointerEvents(shouldDisableTouchability ? 'none' : 'auto');
Expand Down
6 changes: 6 additions & 0 deletions src/components/bottomSheetBackdrop/types.d.ts
Expand Up @@ -40,6 +40,12 @@ export interface BottomSheetDefaultBackdropProps
* @default 'close'
*/
pressBehavior?: BackdropPressBehavior;

/**
* Function which will be executed on pressing backdrop component
* @type {Function}
*/
onPress?: () => void;
/**
* Child component that will be rendered on backdrop.
*/
Expand Down

0 comments on commit 1f0e93f

Please sign in to comment.