Skip to content

Commit

Permalink
feat: return nearest parent header height for useHeaderHeight
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Mar 12, 2021
1 parent 2c8401d commit 24b3f73
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 4 additions & 1 deletion packages/elements/src/Screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function Screen(props: Props) {
const insets = useSafeAreaInsets();

const isParentHeaderShown = React.useContext(HeaderShownContext);
const parentHeaderHeight = React.useContext(HeaderHeightContext);

const {
header,
Expand All @@ -50,7 +51,9 @@ export default function Screen(props: Props) {
<HeaderShownContext.Provider
value={isParentHeaderShown || headerShown !== false}
>
<HeaderHeightContext.Provider value={headerShown ? headerHeight : 0}>
<HeaderHeightContext.Provider
value={headerShown ? headerHeight : parentHeaderHeight}
>
{children}
</HeaderHeightContext.Provider>
</HeaderShownContext.Provider>
Expand Down
6 changes: 5 additions & 1 deletion packages/stack/src/views/Stack/CardContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ function CardContainer({
scene,
transitionSpec,
}: Props) {
const parentHeaderHeight = React.useContext(HeaderHeightContext);

const handleOpen = () => {
const { route } = scene.descriptor;

Expand Down Expand Up @@ -263,7 +265,9 @@ function CardContainer({
<HeaderShownContext.Provider
value={isParentHeaderShown || headerShown !== false}
>
<HeaderHeightContext.Provider value={headerHeight}>
<HeaderHeightContext.Provider
value={headerShown ? headerHeight : parentHeaderHeight}
>
{renderScene({ route: scene.descriptor.route })}
</HeaderHeightContext.Provider>
</HeaderShownContext.Provider>
Expand Down

0 comments on commit 24b3f73

Please sign in to comment.