feat: add headerTitleAlign prop in native stack. closes #9829

This commit is contained in:
Satyajit Sahoo
2021-08-18 14:26:20 +02:00
parent ec0d113eb2
commit fe692c2f56
3 changed files with 27 additions and 9 deletions

View File

@@ -259,6 +259,13 @@ export type NativeStackNavigationOptions = {
*/
tintColor?: string;
}) => React.ReactNode);
/**
* How to align the the header title.
* Defaults to `left` on platforms other than iOS.
*
* Not supported on iOS. It's always `center` on iOS and cannot be changed.
*/
headerTitleAlign?: 'left' | 'center';
/**
* Style object for header title. Supported properties:
* - fontFamily

View File

@@ -38,6 +38,7 @@ export default function HeaderConfig({
headerBlurEffect,
headerTintColor,
headerTitle,
headerTitleAlign,
headerTitleStyle,
headerTransparent,
route,
@@ -151,21 +152,29 @@ export default function HeaderConfig({
<ScreenStackHeaderLeftView>
<View style={styles.row}>
{headerLeftElement}
{typeof headerTitle === 'function' ? (
headerTitleElement
) : (
<HeaderTitle tintColor={tintColor}>{titleText}</HeaderTitle>
)}
{headerTitleAlign !== 'center' ? (
typeof headerTitle === 'function' ? (
headerTitleElement
) : (
<HeaderTitle tintColor={tintColor}>{titleText}</HeaderTitle>
)
) : null}
</View>
</ScreenStackHeaderLeftView>
) : null}
{headerTitleAlign === 'center' ? (
<ScreenStackHeaderCenterView>
{typeof headerTitle === 'function' ? (
headerTitleElement
) : (
<HeaderTitle tintColor={tintColor}>{titleText}</HeaderTitle>
)}
</ScreenStackHeaderCenterView>
) : null}
</>
)}
{headerBackImageSource !== undefined ? (
<ScreenStackHeaderBackButtonImage
key="backImage"
source={headerBackImageSource}
/>
<ScreenStackHeaderBackButtonImage source={headerBackImageSource} />
) : null}
{headerRightElement != null ? (
<ScreenStackHeaderRightView>

View File

@@ -46,6 +46,7 @@ export default function NativeStackView({ state, descriptors }: Props) {
headerLeft,
headerRight,
headerTitle,
headerTitleAlign,
headerTitleStyle,
headerStyle,
headerShadowVisible,
@@ -117,6 +118,7 @@ export default function NativeStackView({ state, descriptors }: Props) {
headerTitle({ children, tintColor })
: headerTitle
}
headerTitleAlign={headerTitleAlign}
headerTitleStyle={headerTitleStyle}
headerStyle={[
headerTransparent