Skip to content

Commit

Permalink
fix: updated BottomSheetBackdrop "falsey" default props (#793)(by @ja…
Browse files Browse the repository at this point in the history
…kobo)

* fix: fixes BottomSheetBackdrop defaults

Coercion of 0 and false result in defaults being accidentally assigned
to the BottomSheetBackdrop's props. This fix uses the null coalesce
operator ?? to use either a user supplied value or fall back to the
built-in default.

Resolves #779

* chore: fixes detected prettier/eslint errors

Fixed errors found by running `yarn typescript` and `yarn lint` to fix
errors that could not be automatically fixed.

* refactor: applies updates from PR review
  • Loading branch information
jakobo committed Apr 22, 2022
1 parent 955b774 commit 7e00dd2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 9 deletions.
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: _providedOpacity,
appearsOnIndex: _providedAppearsOnIndex,
disappearsOnIndex: _providedDisappearsOnIndex,
enableTouchThrough: _providedEnableTouchThrough,
pressBehavior = DEFAULT_PRESS_BEHAVIOR,
style,
children,
Expand All @@ -36,6 +36,15 @@ const BottomSheetBackdropComponent = ({
const { snapToIndex, close } = useBottomSheet();
//#endregion

//#region defaults
const opacity = _providedOpacity ?? DEFAULT_OPACITY;
const appearsOnIndex = _providedAppearsOnIndex ?? DEFAULT_APPEARS_ON_INDEX;
const disappearsOnIndex =
_providedDisappearsOnIndex ?? DEFAULT_DISAPPEARS_ON_INDEX;
const enableTouchThrough =
_providedEnableTouchThrough ?? 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;

0 comments on commit 7e00dd2

Please sign in to comment.