Skip to content

Commit

Permalink
feat(native-stack): expose custom header height (#10113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Titozzz committed Jan 26, 2022
1 parent 9087439 commit e93b2e9
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions packages/native-stack/src/views/NativeStackView.native.tsx
Expand Up @@ -13,7 +13,7 @@ import {
useTheme,
} from '@react-navigation/native';
import * as React from 'react';
import { Platform, PlatformIOSStatic, StyleSheet } from 'react-native';
import { Platform, PlatformIOSStatic, StyleSheet, View } from 'react-native';
import {
useSafeAreaFrame,
useSafeAreaInsets,
Expand Down Expand Up @@ -166,11 +166,16 @@ const SceneView = ({

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

const defaultHeaderHeight = getDefaultHeaderHeight(
useSafeAreaFrame(),
false,
insets.top
);
const [customHeaderHeight, setCustomHeaderHeight] =
React.useState(defaultHeaderHeight);

const headerHeight = header ? customHeaderHeight : defaultHeaderHeight;

return (
<Screen
Expand Down Expand Up @@ -205,20 +210,25 @@ const SceneView = ({
}
>
{header !== undefined && headerShown !== false ? (
// TODO: expose custom header height
header({
back: previousDescriptor
? {
title: getHeaderTitle(
previousDescriptor.options,
previousDescriptor.route.name
),
}
: undefined,
options,
route,
navigation,
})
<View
onLayout={(e) => {
setCustomHeaderHeight(e.nativeEvent.layout.height);
}}
>
{header({
back: previousDescriptor
? {
title: getHeaderTitle(
previousDescriptor.options,
previousDescriptor.route.name
),
}
: undefined,
options,
route,
navigation,
})}
</View>
) : (
<HeaderConfig
{...options}
Expand Down

0 comments on commit e93b2e9

Please sign in to comment.