feat: drop header: null in favor of more explitit headerShown option

This commit is contained in:
satyajit.happy
2019-10-06 15:53:18 +02:00
parent 16079d1050
commit ba6b6ae025
8 changed files with 22 additions and 17 deletions

View File

@@ -241,7 +241,12 @@ export type StackNavigationOptions = StackHeaderOptions &
* Function that given `HeaderProps` returns a React Element to display as a header.
* Setting to `null` hides header.
*/
header?: null | ((props: StackHeaderProps) => React.ReactNode);
header?: (props: StackHeaderProps) => React.ReactNode;
/**
* Whether to show the header. The header is shown by default unless `headerMode` was set to `none`.
* Setting this to `false` hides the header.
*/
headerShown?: boolean;
/**
* Whether a shadow is visible for the card during transitions. Defaults to `true`.
*/

View File

@@ -77,11 +77,11 @@ export default function HeaderContainer({
const isHeaderStatic =
mode === 'float'
? (previousScene &&
previousScene.descriptor.options.header === null &&
previousScene.descriptor.options.headerShown === false &&
// We still need to animate when coming back from next scene
// A hacky way to check this is if the next scene exists
!nextScene) ||
(nextScene && nextScene.descriptor.options.header === null)
(nextScene && nextScene.descriptor.options.headerShown === false)
: false;
const props = {
@@ -121,13 +121,13 @@ export default function HeaderContainer({
: null
}
>
{options.header !== undefined ? (
options.header === null ? null : (
{options.headerShown !== false ? (
options.header !== undefined ? (
options.header(props)
) : (
<Header {...props} />
)
) : (
<Header {...props} />
)}
) : null}
</View>
</NavigationContext.Provider>
);

View File

@@ -353,7 +353,7 @@ export default class Stack extends React.Component<Props, State> {
: 0;
const {
header,
headerShown,
headerTransparent,
cardTransparent,
cardShadowEnabled,
@@ -430,9 +430,9 @@ export default class Stack extends React.Component<Props, State> {
onPageChangeCancel={onPageChangeCancel}
gestureResponseDistance={gestureResponseDistance}
floatingHeaderHeight={floatingHeaderHeights[route.key]}
hasCustomHeader={header === null}
getPreviousRoute={getPreviousRoute}
headerMode={headerMode}
headerShown={headerShown}
headerTransparent={headerTransparent}
renderHeader={renderHeader}
renderScene={renderScene}

View File

@@ -53,9 +53,9 @@ type Props = TransitionPreset & {
};
gestureVelocityImpact?: number;
headerMode: StackHeaderMode;
headerShown?: boolean;
headerTransparent?: boolean;
floatingHeaderHeight: number;
hasCustomHeader: boolean;
};
export default class StackItem extends React.PureComponent<Props> {
@@ -114,7 +114,7 @@ export default class StackItem extends React.PureComponent<Props> {
gestureResponseDistance,
gestureVelocityImpact,
floatingHeaderHeight,
hasCustomHeader,
headerShown,
getPreviousRoute,
headerMode,
headerTransparent,
@@ -153,7 +153,7 @@ export default class StackItem extends React.PureComponent<Props> {
importantForAccessibility={focused ? 'auto' : 'no-hide-descendants'}
pointerEvents="box-none"
containerStyle={
headerMode === 'float' && !headerTransparent && !hasCustomHeader
headerMode === 'float' && !headerTransparent && headerShown !== false
? { marginTop: floatingHeaderHeight }
: null
}