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

Commit 5a839e0

Browse files
committed
fix: support function for headerBackground
1 parent a6af39a commit 5a839e0

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

example/src/HeaderBackgrounds.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function createHeaderBackgroundExample(options = {}) {
2121
navigationOptions: {
2222
headerTitle: 'Login Screen',
2323
headerTintColor: '#fff',
24-
headerBackground: (
24+
headerBackground: () => (
2525
<View style={{ flex: 1, backgroundColor: '#FF0066' }} />
2626
),
2727
},
@@ -41,7 +41,7 @@ function createHeaderBackgroundExample(options = {}) {
4141
navigationOptions: {
4242
headerTitle: 'Games Screen',
4343
headerTintColor: '#fff',
44-
headerBackground: (
44+
headerBackground: () => (
4545
<View style={{ flex: 1, backgroundColor: '#3388FF' }} />
4646
),
4747
},

src/navigators/__tests__/StackNavigator.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('StackNavigator', () => {
6464
Home: {
6565
screen: HomeScreen,
6666
navigationOptions: {
67-
headerRight: <View />,
67+
headerRight: () => <View />,
6868
},
6969
},
7070
});
@@ -90,7 +90,7 @@ describe('StackNavigator', () => {
9090

9191
class A extends React.Component {
9292
static navigationOptions = {
93-
headerRight: <TestComponentWithNavigation onPress={spy} />,
93+
headerRight: () => <TestComponentWithNavigation onPress={spy} />,
9494
};
9595

9696
render() {

src/types.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export type NavigationStackOptions = {
122122
title?: string | null;
123123
}) => React.ReactNode;
124124
headerPressColorAndroid?: string;
125-
headerBackground?: React.ReactNode;
125+
headerBackground?: (() => React.ReactNode) | React.ReactNode;
126126
headerTransparent?: boolean;
127127
headerStyle?: StyleProp<ViewStyle>;
128128
headerForceInset?: React.ComponentProps<typeof SafeAreaView>['forceInset'];

src/views/Header/Header.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,10 @@ class Header extends React.PureComponent<Props, State> {
440440
return this.renderSubView(
441441
{ ...props, style: StyleSheet.absoluteFill },
442442
'background',
443-
() => options.headerBackground,
443+
() =>
444+
typeof options.headerBackground === 'function'
445+
? options.headerBackground()
446+
: options.headerBackground,
444447
this.props.backgroundInterpolator
445448
);
446449
};

0 commit comments

Comments
 (0)