mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-04-24 04:25:34 +08:00
feat: add a more explicit headerShown option
This commit is contained in:
@@ -4,7 +4,7 @@ import { createStackNavigator } from 'react-navigation-stack';
|
||||
|
||||
class Screen extends React.Component {
|
||||
static navigationOptions = {
|
||||
header: null,
|
||||
headerShown: false,
|
||||
};
|
||||
|
||||
render() {
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -70,7 +70,7 @@ export const Stack = createStackNavigator(
|
||||
{
|
||||
initialRouteName: 'Screen1',
|
||||
defaultNavigationOptions: {
|
||||
header: null,
|
||||
headerShown: false,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
@@ -31,7 +31,7 @@ class ListScreen extends React.Component<NavigationStackScreenProps> {
|
||||
|
||||
class DetailsScreen extends React.Component<NavigationStackScreenProps> {
|
||||
static navigationOptions = {
|
||||
header: null,
|
||||
headerShown: false,
|
||||
};
|
||||
|
||||
render() {
|
||||
|
||||
@@ -117,7 +117,7 @@ class DetailsScreen extends React.Component<NavigationStackScreenProps> {
|
||||
|
||||
class HeaderlessScreen extends React.Component {
|
||||
static navigationOptions = {
|
||||
header: null,
|
||||
headerShown: false,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
@@ -125,7 +125,7 @@ class DetailsScreen extends React.Component<NavigationStackScreenProps> {
|
||||
|
||||
class HeaderlessScreen extends React.Component {
|
||||
static navigationOptions = {
|
||||
header: null,
|
||||
headerShown: false,
|
||||
};
|
||||
|
||||
componentDidMount() {
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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>
|
||||
);
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user