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

Commit

Permalink
fix: support function for headerBackground
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Oct 20, 2019
1 parent a6af39a commit 5a839e0
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions example/src/HeaderBackgrounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ function createHeaderBackgroundExample(options = {}) {
navigationOptions: {
headerTitle: 'Login Screen',
headerTintColor: '#fff',
headerBackground: (
headerBackground: () => (
<View style={{ flex: 1, backgroundColor: '#FF0066' }} />
),
},
Expand All @@ -41,7 +41,7 @@ function createHeaderBackgroundExample(options = {}) {
navigationOptions: {
headerTitle: 'Games Screen',
headerTintColor: '#fff',
headerBackground: (
headerBackground: () => (
<View style={{ flex: 1, backgroundColor: '#3388FF' }} />
),
},
Expand Down
4 changes: 2 additions & 2 deletions src/navigators/__tests__/StackNavigator.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('StackNavigator', () => {
Home: {
screen: HomeScreen,
navigationOptions: {
headerRight: <View />,
headerRight: () => <View />,
},
},
});
Expand All @@ -90,7 +90,7 @@ describe('StackNavigator', () => {

class A extends React.Component {
static navigationOptions = {
headerRight: <TestComponentWithNavigation onPress={spy} />,
headerRight: () => <TestComponentWithNavigation onPress={spy} />,
};

render() {
Expand Down
2 changes: 1 addition & 1 deletion src/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export type NavigationStackOptions = {
title?: string | null;
}) => React.ReactNode;
headerPressColorAndroid?: string;
headerBackground?: React.ReactNode;
headerBackground?: (() => React.ReactNode) | React.ReactNode;
headerTransparent?: boolean;
headerStyle?: StyleProp<ViewStyle>;
headerForceInset?: React.ComponentProps<typeof SafeAreaView>['forceInset'];
Expand Down
5 changes: 4 additions & 1 deletion src/views/Header/Header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,10 @@ class Header extends React.PureComponent<Props, State> {
return this.renderSubView(
{ ...props, style: StyleSheet.absoluteFill },
'background',
() => options.headerBackground,
() =>
typeof options.headerBackground === 'function'
? options.headerBackground()
: options.headerBackground,
this.props.backgroundInterpolator
);
};
Expand Down

0 comments on commit 5a839e0

Please sign in to comment.