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

Commit

Permalink
feat: add a more explicit headerShown option
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Oct 6, 2019
1 parent 8d3e614 commit 0375864
Show file tree
Hide file tree
Showing 10 changed files with 28 additions and 19 deletions.
2 changes: 1 addition & 1 deletion example/src/FullScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createStackNavigator } from 'react-navigation-stack';

class Screen extends React.Component {
static navigationOptions = {
header: null,
headerShown: false,
};

render() {
Expand Down
2 changes: 1 addition & 1 deletion example/src/HeaderPreset.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ class ScreenWithLongTitle extends React.Component<NavigationStackScreenProps> {

class ScreenWithNoHeader extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
header: null,
title: 'No Header',
headerShown: false,
};

render() {
Expand Down
2 changes: 1 addition & 1 deletion example/src/ImmediateTransition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const Stack = createStackNavigator(
{
initialRouteName: 'Screen1',
defaultNavigationOptions: {
header: null,
headerShown: false,
},
}
);
Expand Down
2 changes: 1 addition & 1 deletion example/src/ModalPresentation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class ListScreen extends React.Component<NavigationStackScreenProps> {

class DetailsScreen extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
header: null,
headerShown: false,
};

render() {
Expand Down
2 changes: 1 addition & 1 deletion example/src/RevealStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class DetailsScreen extends React.Component<NavigationStackScreenProps> {

class HeaderlessScreen extends React.Component {
static navigationOptions = {
header: null,
headerShown: false,
};

componentDidMount() {
Expand Down
2 changes: 1 addition & 1 deletion example/src/SimpleStack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class DetailsScreen extends React.Component<NavigationStackScreenProps> {

class HeaderlessScreen extends React.Component {
static navigationOptions = {
header: null,
headerShown: false,
};

componentDidMount() {
Expand Down
1 change: 1 addition & 0 deletions src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ export type NavigationStackOptions = HeaderOptions &
Partial<TransitionPreset> & {
title?: string;
header?: React.ReactNode | ((props: HeaderProps) => React.ReactNode);
headerShown?: boolean;
cardShadowEnabled?: boolean;
cardOverlayEnabled?: boolean;
cardTransparent?: boolean;
Expand Down
25 changes: 16 additions & 9 deletions src/views/Header/HeaderContainer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ export default function HeaderContainer({
const isHeaderStatic =
mode === 'float'
? (previousScene &&
previousScene.descriptor.options.header === null &&
(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.header === null ||
nextScene.descriptor.options.headerShown === false))
: false;

const props = {
Expand Down Expand Up @@ -113,13 +116,17 @@ export default function HeaderContainer({
: null
}
>
{options.header !== undefined ? (
typeof options.header === 'function' ? (
options.header(props)
) : null
) : (
<Header {...props} />
)}
{options.headerShown !== false ? (
options.header !== undefined ? (
typeof options.header === 'function' ? (
options.header(props)
) : (
options.header
)
) : (
<Header {...props} />
)
) : null}
</View>
</NavigationContext.Provider>
);
Expand Down
3 changes: 2 additions & 1 deletion src/views/Stack/Stack.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,7 @@ export default class Stack extends React.Component<Props, State> {

const {
header,
headerShown,
headerTransparent,
cardTransparent,
cardShadowEnabled,
Expand Down Expand Up @@ -419,7 +420,7 @@ export default class Stack extends React.Component<Props, State> {
onPageChangeConfirm={onPageChangeConfirm}
onPageChangeCancel={onPageChangeCancel}
floatingHeaderHeight={floatingHeaderHeights[route.key]}
hasCustomHeader={header === null}
headerShown={header === null || headerShown === false}
getPreviousRoute={getPreviousRoute}
headerMode={headerMode}
headerTransparent={headerTransparent}
Expand Down
6 changes: 3 additions & 3 deletions src/views/Stack/StackItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ type Props = TransitionPreset & {
headerMode: HeaderMode;
headerTransparent?: boolean;
floatingHeaderHeight: number;
hasCustomHeader: boolean;
headerShown: boolean;
gestureVelocityImpact?: number;
};

Expand Down Expand Up @@ -111,7 +111,7 @@ export default class StackItem extends React.PureComponent<Props> {
onPageChangeCancel,
gestureResponseDistance,
floatingHeaderHeight,
hasCustomHeader,
headerShown,
getPreviousRoute,
headerMode,
headerTransparent,
Expand Down Expand Up @@ -149,7 +149,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
? { marginTop: floatingHeaderHeight }
: null
}
Expand Down

0 comments on commit 0375864

Please sign in to comment.