feat: add a more explicit headerShown option

This commit is contained in:
satyajit.happy
2019-10-06 15:37:08 +02:00
parent 28353f4b79
commit 8f83f58913
10 changed files with 28 additions and 19 deletions

View File

@@ -4,7 +4,7 @@ import { createStackNavigator } from 'react-navigation-stack';
class Screen extends React.Component {
static navigationOptions = {
header: null,
headerShown: false,
};
render() {

View File

@@ -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() {

View File

@@ -70,7 +70,7 @@ export const Stack = createStackNavigator(
{
initialRouteName: 'Screen1',
defaultNavigationOptions: {
header: null,
headerShown: false,
},
}
);

View File

@@ -31,7 +31,7 @@ class ListScreen extends React.Component<NavigationStackScreenProps> {
class DetailsScreen extends React.Component<NavigationStackScreenProps> {
static navigationOptions = {
header: null,
headerShown: false,
};
render() {

View File

@@ -117,7 +117,7 @@ class DetailsScreen extends React.Component<NavigationStackScreenProps> {
class HeaderlessScreen extends React.Component {
static navigationOptions = {
header: null,
headerShown: false,
};
componentDidMount() {

View File

@@ -125,7 +125,7 @@ class DetailsScreen extends React.Component<NavigationStackScreenProps> {
class HeaderlessScreen extends React.Component {
static navigationOptions = {
header: null,
headerShown: false,
};
componentDidMount() {

View File

@@ -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;

View File

@@ -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 = {
@@ -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>
);

View File

@@ -346,6 +346,7 @@ export default class Stack extends React.Component<Props, State> {
const {
header,
headerShown,
headerTransparent,
cardTransparent,
cardShadowEnabled,
@@ -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}

View File

@@ -53,7 +53,7 @@ type Props = TransitionPreset & {
headerMode: HeaderMode;
headerTransparent?: boolean;
floatingHeaderHeight: number;
hasCustomHeader: boolean;
headerShown: boolean;
gestureVelocityImpact?: number;
};
@@ -111,7 +111,7 @@ export default class StackItem extends React.PureComponent<Props> {
onPageChangeCancel,
gestureResponseDistance,
floatingHeaderHeight,
hasCustomHeader,
headerShown,
getPreviousRoute,
headerMode,
headerTransparent,
@@ -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
}