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

Commit

Permalink
#33 hide back button if onBack is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
halilb committed Apr 18, 2017
1 parent 5030c2a commit 6409f1e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
29 changes: 19 additions & 10 deletions lib/bar/TopBar.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,33 @@ export default class TopBar extends React.Component {
displayed: false,
title: '',
backTitle: 'Back',
backImage: require('../../Assets/angle-left.png'),
};

constructor(props) {
super(props);
renderBackButton() {
const { onBack, backImage } = this.props;

// do not display back button if there isn't a press handler
if (onBack) {
return (
<TouchableOpacity style={styles.backContainer} onPress={onBack}>
<Image source={backImage} />
{Platform.OS === 'ios' &&
<Text style={[styles.text, styles.backText]}>
{this.props.backTitle}
</Text>}
</TouchableOpacity>
);
}

return null;
}

render() {
const {
displayed,
title,
height,
onBack,
} = this.props;

return (
Expand All @@ -44,13 +59,7 @@ export default class TopBar extends React.Component {
displayed={displayed}
height={height}
>
<TouchableOpacity style={styles.backContainer} onPress={onBack}>
<Image source={this.props.backImage || require('../../Assets/angle-left.png')} />
{
Platform.OS === 'ios' &&
<Text style={[styles.text, styles.backText]}>{this.props.backTitle}</Text>
}
</TouchableOpacity>
{this.renderBackButton()}
<Text style={styles.text}>{title}</Text>
</BarContainer>
);
Expand Down
6 changes: 3 additions & 3 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ export default class PhotoBrowser extends React.Component {
useCircleProgress: PropTypes.bool,

/*
* Called when done or back button is tapped
* Called when done or back button is tapped.
* Back button will not be displayed if this is null.
*/
onBack: PropTypes.func,

Expand Down Expand Up @@ -108,7 +109,6 @@ export default class PhotoBrowser extends React.Component {
displaySelectionButtons: false,
useCircleProgress: false,
onSelectionChanged: () => {},
onBack: () => {},
displayTopBar: true,
onPhotoLongPress: () => {},
delayPhotoLongPress: 1000,
Expand Down Expand Up @@ -273,7 +273,7 @@ export default class PhotoBrowser extends React.Component {
/>
);
}

const TopBarComponent = this.props.topBarComponent || TopBar;

return (
Expand Down

0 comments on commit 6409f1e

Please sign in to comment.