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

Make NavigationBar.Title more extendable #421

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 41 additions & 10 deletions src/ExNavigationBar.js
Original file line number Diff line number Diff line change
@@ -37,40 +37,69 @@ class ExNavigationBarTitle extends PureComponent {
const { children, style, textStyle, tintColor } = this.props;

return (
<View style={[titleStyles.title, style]}>
<Text numberOfLines={1} style={[
titleStyles.titleText,
tintColor ? {color: tintColor} : null,
textStyle,
]}>
<ExNavigationBarTitleContainer style={style}>
<ExNavigationBarTitleText style={textStyle} tintColor={tintColor}>
{children}
</Text>
</ExNavigationBarTitleText>
</ExNavigationBarTitleContainer>
);
}
}

class ExNavigationBarTitleContainer extends PureComponent {
render() {
const { children, style, ...props } = this.props;

return (
<View {...props} style={[titleStyles.title, style]}>
{children}
</View>
);
}
}

class ExNavigationBarTitleText extends PureComponent {
render() {
const { children, style, tintColor } = this.props;

return (
<Text numberOfLines={1} style={[
titleStyles.titleText,
tintColor ? {color: tintColor} : null,
style,
]}>
{children}
</Text>
);
}
}

const titleStyles = StyleSheet.create({
title: {
flex: 1,
flexDirection: 'row',
alignItems: 'center',
marginHorizontal: 16,
...Platform.select({
ios: {
justifyContent: 'center',
},
android: {
justifyContent: 'flex-start',
},
}),
},

titleText: {
flex: 1,
color: 'rgba(0, 0, 0, .9)',
...Platform.select({
ios: {
fontSize: 17,
fontWeight: '500',
textAlign: 'center',
},
android: {
fontSize: 20,
// fontFamily: 'sans-serif-medium',
textAlign: 'left',
},
}),
},
@@ -384,6 +413,8 @@ ExNavigationBar.DEFAULT_BACKGROUND_COLOR = BACKGROUND_COLOR;
ExNavigationBar.DEFAULT_BORDER_BOTTOM_COLOR = BORDER_BOTTOM_COLOR;
ExNavigationBar.DEFAULT_BORDER_BOTTOM_WIDTH = BORDER_BOTTOM_WIDTH;
ExNavigationBar.Title = ExNavigationBarTitle;
ExNavigationBar.TitleContainer = ExNavigationBarTitleContainer;
ExNavigationBar.TitleText = ExNavigationBarTitleText;
ExNavigationBar.BackButton = ExNavigationBarBackButton;
ExNavigationBar.MenuButton = ExNavigationBarMenuButton;