Skip to content
This repository has been archived by the owner on Feb 8, 2020. It is now read-only.

Commit

Permalink
feat: drop header: null in favor of more explitit headerShown option
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Oct 6, 2019
1 parent 16079d1 commit ba6b6ae
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 17 deletions.
2 changes: 1 addition & 1 deletion packages/example/src/Screens/AuthFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export default function SimpleStackScreen({ navigation }: Props) {
}, []);

navigation.setOptions({
header: null,
headerShown: false,
});

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/example/src/Screens/CompatAPI.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export default function CompatStackScreen({
navigation: StackNavigationProp<{}>;
}) {
navigation.setOptions({
header: null,
headerShown: false,
});

return <CompatStack />;
Expand Down
2 changes: 1 addition & 1 deletion packages/example/src/Screens/ModalPresentationStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ type Props = {

export default function SimpleStackScreen({ navigation, options }: Props) {
navigation.setOptions({
header: null,
headerShown: false,
});

return (
Expand Down
2 changes: 1 addition & 1 deletion packages/example/src/Screens/SimpleStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type Props = {

export default function SimpleStackScreen({ navigation, options }: Props) {
navigation.setOptions({
header: null,
headerShown: false,
});

return (
Expand Down
7 changes: 6 additions & 1 deletion packages/stack/src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
*/
Expand Down
14 changes: 7 additions & 7 deletions packages/stack/src/views/Header/HeaderContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -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>
);
Expand Down
4 changes: 2 additions & 2 deletions packages/stack/src/views/Stack/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export default class Stack extends React.Component<Props, State> {
: 0;

const {
header,
headerShown,
headerTransparent,
cardTransparent,
cardShadowEnabled,
Expand Down Expand Up @@ -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}
Expand Down
6 changes: 3 additions & 3 deletions packages/stack/src/views/Stack/StackItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -114,7 +114,7 @@ export default class StackItem extends React.PureComponent<Props> {
gestureResponseDistance,
gestureVelocityImpact,
floatingHeaderHeight,
hasCustomHeader,
headerShown,
getPreviousRoute,
headerMode,
headerTransparent,
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit ba6b6ae

Please sign in to comment.