Skip to content

Commit fd060a3

Browse files
committed
make body component configurable
1 parent b77060b commit fd060a3

3 files changed

Lines changed: 18 additions & 8 deletions

File tree

src/components/bottomSheet/BottomSheet.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
164164
backgroundComponent,
165165
renderFooter,
166166
children,
167+
BodyComponent,
167168

168169
// accessibility
169170
accessible: _providedAccessible = DEFAULT_ACCESSIBLE,
@@ -213,7 +214,9 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
213214
_providedHandleHeight ?? INITIAL_HANDLE_HEIGHT
214215
);
215216
const animatedFooterHeight = useSharedValue(0);
216-
const animatedContentHeight = useSharedValue(_providedContentHeight ?? INITIAL_CONTAINER_HEIGHT);
217+
const animatedContentHeight = useSharedValue(
218+
_providedContentHeight ?? INITIAL_CONTAINER_HEIGHT
219+
);
217220
const [animatedSnapPoints, animatedDynamicSnapPointIndex] =
218221
useAnimatedSnapPoints(
219222
_providedSnapPoints,
@@ -1798,7 +1801,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
17981801
detached={detached}
17991802
style={_providedContainerStyle}
18001803
>
1801-
<BottomSheetBody style={style}>
1804+
<BottomSheetBody style={style} BodyComponent={BodyComponent}>
18021805
{backgroundComponent === null ? null : (
18031806
<BottomSheetBackgroundContainer
18041807
key="BottomSheetBackgroundContainer"

src/components/bottomSheet/BottomSheetBody.tsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
1-
import React, { memo, useMemo } from 'react';
1+
import React, { type ComponentProps, memo, useMemo } from 'react';
22
import { Platform } from 'react-native';
33
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
44
import { useBottomSheetInternal } from '../../hooks';
55
import type { BottomSheetProps } from '../bottomSheet/types';
66
import { styles } from './styles';
77

8-
type BottomSheetBodyProps = {
8+
export type BottomSheetBodyProps = {
99
style?: BottomSheetProps['style'];
1010
children?: React.ReactNode;
11+
BodyComponent?: React.ComponentType<ComponentProps<typeof Animated.View>>;
1112
};
1213

13-
function BottomSheetBodyComponent({ style, children }: BottomSheetBodyProps) {
14+
function BottomSheetBodyComponent({
15+
style,
16+
children,
17+
BodyComponent = Animated.View,
18+
}: BottomSheetBodyProps) {
1419
//#region hooks
1520
const { animatedIndex, animatedPosition } = useBottomSheetInternal();
1621
//#endregion
@@ -34,9 +39,9 @@ function BottomSheetBodyComponent({ style, children }: BottomSheetBodyProps) {
3439
//#endregion
3540

3641
return (
37-
<Animated.View style={containerStyle} collapsable={true}>
42+
<BodyComponent style={containerStyle} collapsable={true}>
3843
{children}
39-
</Animated.View>
44+
</BodyComponent>
4045
);
4146
}
4247

src/components/bottomSheet/types.d.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ import type { BottomSheetBackdropProps } from '../bottomSheetBackdrop';
2323
import type { BottomSheetBackgroundProps } from '../bottomSheetBackground';
2424
import type { BottomSheetFooterProps } from '../bottomSheetFooter';
2525
import type { BottomSheetHandleProps } from '../bottomSheetHandle';
26+
import type { BottomSheetBodyProps } from './BottomSheetBody';
2627

2728
export interface BottomSheetProps
2829
extends BottomSheetAnimationConfigs,
2930
Partial<BottomSheetGestureProps>,
30-
Omit<NullableAccessibilityProps, 'accessibilityHint'> {
31+
Omit<NullableAccessibilityProps, 'accessibilityHint'>,
32+
Pick<BottomSheetBodyProps, 'BodyComponent'> {
3133
//#region configuration
3234
/**
3335
* Initial snap point index, provide `-1` to initiate bottom sheet in closed state.

0 commit comments

Comments
 (0)