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

Fix BottomSheetBackdrop "falsey" defaults #793

Merged
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 3 additions & 2 deletions example/src/screens/advanced/BackdropExample.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ import HeaderHandle from '../../components/headerHandle';

const BackdropExample = () => {
// state
const [backdropPressBehavior, setBackdropPressBehavior] =
useState<'none' | 'close' | 'collapse'>('collapse');
const [backdropPressBehavior, setBackdropPressBehavior] = useState<
'none' | 'close' | 'collapse'
>('collapse');

// hooks
const bottomSheetRef = useRef<BottomSheet>(null);
Expand Down
17 changes: 13 additions & 4 deletions src/components/bottomSheetBackdrop/BottomSheetBackdrop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ import type { BottomSheetDefaultBackdropProps } from './types';

const BottomSheetBackdropComponent = ({
animatedIndex,
opacity = DEFAULT_OPACITY,
appearsOnIndex = DEFAULT_APPEARS_ON_INDEX,
disappearsOnIndex = DEFAULT_DISAPPEARS_ON_INDEX,
enableTouchThrough = DEFAULT_ENABLE_TOUCH_THROUGH,
opacity: userOpacity,
thecodedrift marked this conversation as resolved.
Show resolved Hide resolved
appearsOnIndex: userAppearsOnIndex,
disappearsOnIndex: userDisappearsOnIndex,
enableTouchThrough: userEnableTouchThrough,
pressBehavior = DEFAULT_PRESS_BEHAVIOR,
style,
children,
Expand All @@ -36,6 +36,15 @@ const BottomSheetBackdropComponent = ({
const { snapToIndex, close } = useBottomSheet();
//#endregion

//#region defaults
const opacity = userOpacity ?? DEFAULT_OPACITY;
const appearsOnIndex = userAppearsOnIndex ?? DEFAULT_APPEARS_ON_INDEX;
const disappearsOnIndex =
userDisappearsOnIndex ?? DEFAULT_DISAPPEARS_ON_INDEX;
const enableTouchThrough =
userEnableTouchThrough ?? DEFAULT_ENABLE_TOUCH_THROUGH;
//#endregion

//#region variables
const containerRef = useRef<Animated.View>(null);
const pointerEvents = enableTouchThrough ? 'none' : 'auto';
Expand Down
3 changes: 2 additions & 1 deletion src/components/bottomSheetBackdrop/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { ReactNode } from 'react';
import type { ViewProps } from 'react-native';
import type { BottomSheetVariables } from '../../types';

Expand Down Expand Up @@ -42,5 +43,5 @@ export interface BottomSheetDefaultBackdropProps
/**
* Child component that will be rendered on backdrop.
*/
children?: React.ReactNode | React.ReactNode[];
children?: ReactNode | ReactNode[];
}
5 changes: 3 additions & 2 deletions src/contexts/external.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { createContext } from 'react';
import type { BottomSheetMethods, BottomSheetVariables } from '../types';

export const BottomSheetContext =
createContext<(BottomSheetMethods & BottomSheetVariables) | null>(null);
export const BottomSheetContext = createContext<
(BottomSheetMethods & BottomSheetVariables) | null
>(null);

export const BottomSheetProvider = BottomSheetContext.Provider;