diff --git a/src/components/bottomSheet/BottomSheet.tsx b/src/components/bottomSheet/BottomSheet.tsx index 21bbb62b..c8615fe9 100644 --- a/src/components/bottomSheet/BottomSheet.tsx +++ b/src/components/bottomSheet/BottomSheet.tsx @@ -44,7 +44,10 @@ import { useStableCallback, useScrollable, } from '../../utilities'; -import { BottomSheetInternalProvider } from '../../context'; +import { + BottomSheetInternalProvider, + BottomSheetProvider, +} from '../../context'; import { DEFAULT_ANIMATION_EASING, DEFAULT_ANIMATION_DURATION, @@ -79,6 +82,7 @@ const BottomSheetComponent = forwardRef( onChange: _onChange, // components handleComponent: HandleComponent = Handle, + backgroundComponent: BackgroundComponent = null, children, }, ref @@ -245,6 +249,13 @@ const BottomSheetComponent = forwardRef( // eslint-disable-next-line react-hooks/exhaustive-deps [] ); + const contextVariables = useMemo( + () => ({ + snapTo: handleOnSnapTo, + close: handleClose, + }), + [handleOnSnapTo, handleClose] + ); //#endregion //#region effects @@ -309,24 +320,29 @@ const BottomSheetComponent = forwardRef( {...tapGestureHandler} > - - - - - + {BackgroundComponent && ( + + )} + + + + + + - - - {children} - - + + + {children} + + + diff --git a/src/components/bottomSheet/styles.ts b/src/components/bottomSheet/styles.ts index 08def398..4c160109 100644 --- a/src/components/bottomSheet/styles.ts +++ b/src/components/bottomSheet/styles.ts @@ -9,7 +9,6 @@ export const styles = StyleSheet.create({ }, contentContainer: { flex: 1, - backgroundColor: 'black', }, debug: { position: 'absolute', diff --git a/src/components/bottomSheet/types.d.ts b/src/components/bottomSheet/types.d.ts index e8b7a797..a80cf46c 100644 --- a/src/components/bottomSheet/types.d.ts +++ b/src/components/bottomSheet/types.d.ts @@ -1,6 +1,7 @@ import type React from 'react'; import type Animated from 'react-native-reanimated'; import type { BottomSheetHandleProps } from '../handle'; +import type { ViewProps } from 'react-native'; export interface BottomSheetProps extends BottomSheetAnimationConfigs { /** @@ -38,6 +39,11 @@ export interface BottomSheetProps extends BottomSheetAnimationConfigs { * @type React.FC\ */ handleComponent?: React.FC; + /** + * Component to be placed as a background. + * @type React.FC + */ + backgroundComponent?: React.FC; /** * Callback when sheet position changed to a provided point. * @type (index: number) => void; diff --git a/src/context.ts b/src/context.ts index 6dd5235a..df6ed191 100644 --- a/src/context.ts +++ b/src/context.ts @@ -21,3 +21,13 @@ export const BottomSheetInternalContext = createContext< >(); export const BottomSheetInternalProvider = BottomSheetInternalContext.Provider; + +export interface BottomSheetContextType { + snapTo: (index: number) => void; + close: () => void; +} + +// @ts-ignore +export const BottomSheetContext = createContext(); + +export const BottomSheetProvider = BottomSheetContext.Provider; diff --git a/src/hooks.ts b/src/hooks.ts index 794f092b..187d4ae0 100644 --- a/src/hooks.ts +++ b/src/hooks.ts @@ -1,6 +1,10 @@ import { useContext } from 'react'; -import { BottomSheetInternalContext } from './context'; +import { BottomSheetInternalContext, BottomSheetContext } from './context'; export const useBottomSheetInternal = () => { return useContext(BottomSheetInternalContext); }; + +export const useBottomSheet = () => { + return useContext(BottomSheetContext); +}; diff --git a/src/index.ts b/src/index.ts index a7aaf3c7..3c6ddf7e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -13,3 +13,5 @@ export const { } = BottomSheetTouchable; export type { BottomSheetHandleProps } from './components/handle'; + +export { useBottomSheet } from './hooks';