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

Feature/override images #411

Merged
merged 3 commits into from
Mar 28, 2016
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class App extends React.Component {
| titleStyle | Text style | | optional style override for the title element |
| leftTitle | string | | optional string to display on the left if the previous route does not provide `renderBackButton` prop. `renderBackButton` > `leftTitle` > <previous route's `title`> |
| renderLeftButton | Closure | | optional closure to render the left title / buttons element |
| drawerImage | Image | `'./menu_burger.png'` | Simple way to override the drawerImage in the navBar |
| backButtonImage | Image | `'./back_chevron.png'` | Simple way to override the back button in the navBar |
| renderBackButton | Closure | | optional closure to render back text or button if this route happens to be the previous route |
| leftButtonStyle | View style | | optional style override for the container of left title / buttons |
| leftButtonTextStyle | Text style | | optional style override for the left title element |
Expand Down
44 changes: 26 additions & 18 deletions src/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,33 @@ export default class NavBar extends React.Component {
}

_renderBackButton() {
if (this.props.navigationState.index === 0) {
if(!!this.context.drawer && typeof this.context.drawer.toggle === 'function'){
return (
<TouchableOpacity style={[styles.backButton, this.props.navigationState.leftButtonStyle]} onPress={() => {
var drawer = this.context.drawer;
drawer.toggle();
}}>
<Image source={require('./menu_burger.png')} style={[styles.backButtonImage, this.props.navigationState.barButtonIconStyle]}/>
</TouchableOpacity>
);
}else{
return null;
}
}
return (
<TouchableOpacity style={[styles.backButton, this.props.navigationState.leftButtonStyle]} onPress={Actions.pop}>
<Image source={require('./back_chevron.png')} style={[styles.backButtonImage, this.props.navigationState.barButtonIconStyle]}/>
let backButtonImage;

if (this.props.navigationState.index === 0) {
if(!!this.context.drawer && typeof this.context.drawer.toggle === 'function'){

backButtonImage = this.props.navigationState.drawerImage || require('./menu_burger.png');

return (
<TouchableOpacity style={[styles.backButton, this.props.navigationState.leftButtonStyle]} onPress={() => {
var drawer = this.context.drawer;
drawer.toggle();
}}>
<Image source={backButtonImage} style={[styles.backButtonImage, this.props.navigationState.barButtonIconStyle]}/>
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider renaming backButtonImage to buttonImage, as it is used for both drawerImage and backButtonImage. For readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@Froelund Fair enough. See: #420

</TouchableOpacity>
);
);
}else{
return null;
}
}

backButtonImage = this.props.navigationState.backButtonImage || require('./back_chevron.png');

return (
<TouchableOpacity style={[styles.backButton, this.props.navigationState.leftButtonStyle]} onPress={Actions.pop}>
<Image source={backButtonImage} style={[styles.backButtonImage, this.props.navigationState.barButtonIconStyle]}/>
</TouchableOpacity>
);
}

_renderRightButton() {
Expand Down