Skip to content

Commit

Permalink
convert footer component to render function
Browse files Browse the repository at this point in the history
  • Loading branch information
meishuu authored and yayvery committed Feb 24, 2024
1 parent 9e46a09 commit c6e661e
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 12 deletions.
8 changes: 3 additions & 5 deletions src/components/bottomSheet/BottomSheet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
handleComponent,
backdropComponent,
backgroundComponent,
footerComponent,
renderFooter,
children: Content,

// accessibility
Expand Down Expand Up @@ -1659,10 +1659,8 @@ const BottomSheetComponent = forwardRef<BottomSheet, BottomSheetProps>(
>
{typeof Content === 'function' ? <Content /> : Content}

{footerComponent && (
<BottomSheetFooterContainer
footerComponent={footerComponent}
/>
{renderFooter && (
<BottomSheetFooterContainer renderFooter={renderFooter} />
)}
</BottomSheetDraggableView>
</Animated.View>
Expand Down
6 changes: 3 additions & 3 deletions src/components/bottomSheet/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,11 @@ export interface BottomSheetProps
*/
backgroundComponent?: React.FC<BottomSheetBackgroundProps> | null;
/**
* Component to be placed as a footer.
* Function to render as the footer.
* @see {BottomSheetFooterProps}
* @type React.FC\<BottomSheetFooterProps\>
* @type (props: BottomSheetFooterProps) => React.ReactElement | null;
*/
footerComponent?: React.FC<BottomSheetFooterProps>;
renderFooter?: (props: BottomSheetFooterProps) => React.ReactElement | null;
/**
* A scrollable node or normal view.
* @type (() => React.ReactElement) | React.ReactNode[] | React.ReactNode
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import React, { memo } from 'react';
import { memo } from 'react';
import { useDerivedValue } from 'react-native-reanimated';
import { useBottomSheetInternal } from '../../hooks';
import { KEYBOARD_STATE } from '../../constants';
import type { BottomSheetFooterContainerProps } from './types';

const BottomSheetFooterContainerComponent = ({
footerComponent: FooterComponent,
renderFooter,
}: BottomSheetFooterContainerProps) => {
//#region hooks
const {
Expand Down Expand Up @@ -46,7 +46,7 @@ const BottomSheetFooterContainerComponent = ({
]);
//#endregion

return <FooterComponent animatedFooterPosition={animatedFooterPosition} />;
return renderFooter({ animatedFooterPosition });
};

const BottomSheetFooterContainer = memo(BottomSheetFooterContainerComponent);
Expand Down
2 changes: 1 addition & 1 deletion src/components/bottomSheetFooterContainer/types.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { BottomSheetProps } from '../bottomSheet';

export interface BottomSheetFooterContainerProps
extends Required<Pick<BottomSheetProps, 'footerComponent'>> {}
extends Required<Pick<BottomSheetProps, 'renderFooter'>> {}

0 comments on commit c6e661e

Please sign in to comment.