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

Allow styling navbar background image #1259

Closed
wants to merge 1 commit 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
30 changes: 27 additions & 3 deletions src/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,15 @@ import {
Text,
TouchableOpacity,
View,
Dimensions
} from 'react-native';
import Actions from './Actions';
import _drawerImage from './menu_burger.png';
import _backButtonImage from './back_chevron.png';

const IOS_DEFAULT_HEIGHT = 64;
const ANDROID_DEFAULT_HEIGHT = 54;

const styles = StyleSheet.create({
title: {
textAlign: 'center',
Expand Down Expand Up @@ -67,10 +71,10 @@ const styles = StyleSheet.create({
top: 0,
...Platform.select({
ios: {
height: 64,
height: IOS_DEFAULT_HEIGHT,
},
android: {
height: 54,
height: ANDROID_DEFAULT_HEIGHT,
},
}),
right: 0,
Expand Down Expand Up @@ -170,6 +174,7 @@ const propTypes = {
position: PropTypes.object,
navigationBarStyle: View.propTypes.style,
navigationBarBackgroundImage: Image.propTypes.source,
navigationBarBackgroundImageStyle: Image.propTypes.style,
renderTitle: PropTypes.any,
};

Expand Down Expand Up @@ -488,6 +493,25 @@ class NavBar extends React.Component {
this.props.renderTitle;
const navigationBarBackgroundImage = this.props.navigationBarBackgroundImage ||
state.navigationBarBackgroundImage;

// by default, we want the background image to stretch over the whole navbar
// Note that if you change the overall navbar height, you'll have to change the background height too
const navigationBarBackgroundImageStyle = [
{ ...Platform.select({
ios: {
height: IOS_DEFAULT_HEIGHT,
},
android: {
height: ANDROID_DEFAULT_HEIGHT,
},
}),
width: Dimensions.get('window').width
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you really need to use Dimensions here? Looks like this will break when the device screen rotate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right. Let me close this PR for now and come back with a better version that eliminates this dependency and covers all the scenarios.

Thanks for the reminder to never do late night PRs again. :-)

},
this.props.navigationBarBackgroundImageStyle ||
state.navigationBarBackgroundImageStyle ||
selected.navigationBarBackgroundImageStyle ||
{}];

const contents = (
<View>
{renderTitle ? renderTitle(navProps) : state.children.map(this.renderTitle, this)}
Expand All @@ -505,7 +529,7 @@ class NavBar extends React.Component {
]}
>
{navigationBarBackgroundImage ? (
<Image source={navigationBarBackgroundImage}>
<Image source={navigationBarBackgroundImage} style={navigationBarBackgroundImageStyle}>
{contents}
</Image>
) : contents}
Expand Down