Skip to content

Commit

Permalink
Add props to headerLeft and headerRight (#500)
Browse files Browse the repository at this point in the history
This PR will allow users to custom headerRight and headerLeft components using user's theme color.
For example, if I want a custom settings icon in headerRight to navigate to my settings page, I will be able to retrieve color from my custom theme. It's already available in ReactNavigation.

colors.primary is used by the back button so it makes sense to use it for headerRight, headerLeft and headerCenter.
  • Loading branch information
AzzouQ committed May 22, 2020
1 parent a8747b1 commit 867b1f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
6 changes: 3 additions & 3 deletions native-stack/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,15 @@ export type NativeStackNavigationOptions = {
/**
* Function which returns a React Element to display on the right side of the header.
*/
headerRight?: () => React.ReactNode;
headerRight?: (props: { tintColor?: string }) => React.ReactNode;
/**
* Function which returns a React Element to display on the left side of the header.
*/
headerLeft?: () => React.ReactNode;
headerLeft?: (props: { tintColor?: string }) => React.ReactNode;
/**
* Function which returns a React Element to display in the center of the header.
*/
headerCenter?: () => React.ReactNode;
headerCenter?: (props: { tintColor?: string }) => React.ReactNode;
/**
* Tint color for the header. Changes the color of back button and title.
*/
Expand Down
10 changes: 7 additions & 3 deletions native-stack/views/HeaderConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,21 @@ export default function HeaderConfig(props: Props) {
}
largeTitleBackgroundColor={headerLargeStyle.backgroundColor}>
{headerRight !== undefined ? (
<ScreenStackHeaderRightView>{headerRight()}</ScreenStackHeaderRightView>
<ScreenStackHeaderRightView>
{headerRight({ tintColor: headerTintColor ?? colors.primary })}
</ScreenStackHeaderRightView>
) : null}
{backButtonImage !== undefined ? (
<ScreenStackHeaderBackButtonImage key="backImage" source={backButtonImage} />
) : null}
{headerLeft !== undefined ? (
<ScreenStackHeaderLeftView>{headerLeft()}</ScreenStackHeaderLeftView>
<ScreenStackHeaderLeftView>
{headerLeft({ tintColor: headerTintColor ?? colors.primary })}
</ScreenStackHeaderLeftView>
) : null}
{headerCenter !== undefined ? (
<ScreenStackHeaderCenterView>
{headerCenter()}
{headerCenter({ tintColor: headerTintColor ?? colors.primary })}
</ScreenStackHeaderCenterView>
) : null}
</ScreenStackHeaderConfig>
Expand Down

0 comments on commit 867b1f2

Please sign in to comment.