Skip to content
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 @@ -114,6 +114,8 @@ class App extends React.Component {
| 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 |
| backTitle | string | | optional string to display with back button |
| backButtonTextStyle | Text style | | optional style override for the back title element |
| 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
57 changes: 31 additions & 26 deletions src/NavBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,33 +78,31 @@ export default class NavBar extends React.Component {
}

_renderBackButton() {
let buttonImage;

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

buttonImage = this.props.navigationState.drawerImage || require('./menu_burger.png');
const drawer = this.context.drawer;
const state = this.props.navigationState;
const childState = state.children[state.index];
let buttonImage = state.backButtonImage || require('./back_chevron.png');
let onPress = Actions.pop;

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

buttonImage = this.props.navigationState.backButtonImage || require('./back_chevron.png');
let text = childState.backTitle ? <Text style={[styles.barBackButtonText, childState.backButtonTextStyle]}>
{childState.backTitle}
</Text> : null;

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

_renderRightButton() {
Expand Down Expand Up @@ -202,12 +200,13 @@ const styles = StyleSheet.create({
position: 'absolute',
},
backButton: {
width: 29,
width: 100,
height: 37,
position: 'absolute',
bottom: 4,
left: 2,
padding: 8,
flexDirection: 'row',
},
rightButton: {
width: 100,
Expand All @@ -227,12 +226,18 @@ const styles = StyleSheet.create({
},
barRightButtonText: {
color: 'rgb(0, 122, 255)',
textAlign:'right',
textAlign: 'right',
fontSize: 17,
},
barBackButtonText: {
color: 'rgb(0, 122, 255)',
textAlign: 'left',
fontSize: 17,
paddingLeft: 6,
},
barLeftButtonText: {
color: 'rgb(0, 122, 255)',
textAlign:'left',
textAlign: 'left',
fontSize: 17,
},
backButtonImage: {
Expand Down