Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add navigationBarTitleImage prop #1634

Closed
wants to merge 4 commits into from
Closed
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
34 changes: 32 additions & 2 deletions src/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ const styles = StyleSheet.create({
width: 180,
alignSelf: 'center',
},
titleImage: {
width: 180,
alignSelf: 'center'
},
titleWrapper: {
marginTop: 10,
position: 'absolute',
Expand Down Expand Up @@ -164,6 +168,9 @@ const propTypes = {
position: PropTypes.object,
navigationBarStyle: View.propTypes.style,
navigationBarBackgroundImage: Image.propTypes.source,
navigationBarBackgroundImageStyle: Image.propTypes.style,
navigationBarTitleImage: Image.propTypes.source,
navigationBarTitleImageStyle: Image.propTypes.style,
renderTitle: PropTypes.any,
};

Expand All @@ -186,6 +193,7 @@ class NavBar extends React.Component {
this.renderBackButton = this.renderBackButton.bind(this);
this.renderLeftButton = this.renderLeftButton.bind(this);
this.renderTitle = this.renderTitle.bind(this);
this.renderImageTitle = this.renderImageTitle.bind(this);
}

renderBackButton() {
Expand Down Expand Up @@ -451,6 +459,24 @@ class NavBar extends React.Component {
);
}

renderImageTitle() {
const navigationBarTitleImage = this.props.navigationBarTitleImage ||
state.navigationBarTitleImage;
const navigationBarTitleImageStyle = this.props.navigationBarTitleImageStyle ||
state.navigationBarTitleImageStyle;
return (
<Animated.View
style={[
styles.titleWrapper,
this.props.titleWrapperStyle,
]}
>
<Animated.Image style={[styles.titleImage, navigationBarTitleImageStyle]} source={navigationBarTitleImage}>
</Animated.Image>
</Animated.View>
)
}

render() {
let state = this.props.navigationState;
let selected = state.children[state.index];
Expand Down Expand Up @@ -482,9 +508,13 @@ class NavBar extends React.Component {
this.props.renderTitle;
const navigationBarBackgroundImage = this.props.navigationBarBackgroundImage ||
state.navigationBarBackgroundImage;
const navigationBarBackgroundImageStyle = this.props.navigationBarBackgroundImageStyle ||
state.navigationBarBackgroundImageStyle;
const navigationBarTitleImage = this.props.navigationBarTitleImage ||
state.navigationBarTitleImage;
const contents = (
<View>
{renderTitle ? renderTitle(navProps) : state.children.map(this.renderTitle, this)}
{navigationBarTitleImage ? this.renderImageTitle() : (renderTitle ? renderTitle(navProps) : state.children.map(this.renderTitle, this))}
{renderBackButton(navProps) || renderLeftButton(navProps)}
{renderRightButton(navProps)}
</View>
Expand All @@ -499,7 +529,7 @@ class NavBar extends React.Component {
]}
>
{navigationBarBackgroundImage ? (
<Image source={navigationBarBackgroundImage}>
<Image style={navigationBarBackgroundImageStyle} source={navigationBarBackgroundImage}>
{contents}
</Image>
) : contents}
Expand Down