Skip to content

Commit

Permalink
fix: make unstable_sheetFooter usable with react-navigation v7 (#2504)
Browse files Browse the repository at this point in the history
## Description

Associated PR:

* react-navigation/react-navigation#12258

The footer is currently broken, as in the effect of recent refactors it
erroneously ended up being rendered as child as `ScreenStackItem`, thus
due to internal implementation it is rendered under
`ScreenContentWrapper`. However, it has to be rendered as direct child
of `Screen` component (the same as `HeaderConfig`).
 
Under usual circumstances this would be a breaking change, however the
prop is marked as `unstable`, therefore I'm proceeding.

## Changes

`unstable_sheetFooter` is now rendered by `ScreenStackItem`.

## Test code and steps to reproduce

`Test1649`

## Checklist

- [ ] Ensured that CI passes
  • Loading branch information
kkafar authored Nov 14, 2024
1 parent 7549b19 commit 1351473
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/components/ScreenFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,12 @@ function ScreenFooter(props: ViewProps) {
return <ScreenFooterNativeComponent {...props} />;
}

type FooterProps = {
children?: React.ReactNode;
};

export function FooterComponent({ children }: FooterProps) {
return <ScreenFooter collapsable={false}>{children}</ScreenFooter>;
}

export default ScreenFooter;
7 changes: 7 additions & 0 deletions src/components/ScreenStackItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { ScreenStackHeaderConfig } from './ScreenStackHeaderConfig';
import Screen from './Screen';
import ScreenStack from './ScreenStack';
import { RNSScreensRefContext } from '../contexts';
import { FooterComponent } from './ScreenFooter';

type Props = Omit<
ScreenProps,
Expand All @@ -33,6 +34,8 @@ function ScreenStackItem(
contentStyle,
style,
screenId,
// eslint-disable-next-line camelcase
unstable_sheetFooter,
...rest
}: Props,
ref: React.ForwardedRef<View>,
Expand Down Expand Up @@ -86,6 +89,10 @@ function ScreenStackItem(
* for detailed explanation.
*/}
<ScreenStackHeaderConfig {...headerConfig} />
{/* eslint-disable-next-line camelcase */}
{stackPresentation === 'formSheet' && unstable_sheetFooter && (
<FooterComponent>{unstable_sheetFooter()}</FooterComponent>
)}
</>
);

Expand Down

0 comments on commit 1351473

Please sign in to comment.