Skip to content

Instantly share code, notes, and snippets.

@jloiola
Forked from mmazzarolo/NavBar.android.js
Created September 20, 2016 05:52
Show Gist options
  • Save jloiola/1bf14b347b847a0d78420c107293bd13 to your computer and use it in GitHub Desktop.
Save jloiola/1bf14b347b847a0d78420c107293bd13 to your computer and use it in GitHub Desktop.
React-Native toolbar on Navigation-Experimental (for both Android and iOS)
import React, { Component } from 'react'
import { StyleSheet } from 'react-native'
import Icon from 'react-native-vector-icons/Ionicons'
export default class NavBar extends Component {
static propTypes = {
title: React.PropTypes.string,
onLeftPress: React.PropTypes.func,
showDrawer: React.PropTypes.bool
}
render () {
const { title, onLeftPress, showDrawer } = this.props
return (
<Icon.ToolbarAndroid
navIconName={showDrawer ? 'md-menu' : 'md-arrow-back'}
onIconClicked={onLeftPress}
style={styles.toolbar}
titleColor={'white'}
title={title}
/>
)
}
}
const styles = StyleSheet.create({
toolbar: {
backgroundColor: 'blusteel',
height: 54,
position: 'absolute',
top: 0,
left: 0,
width: Dimensions.get('window').width
}
})
import React, { Component, PropTypes } from 'react'
import { NavigationExperimental, StyleSheet, TouchableOpacity } from 'react-native'
import Icon from 'react-native-vector-icons/Ionicons'
const { Header } = NavigationExperimental
export default class NavigationHeader extends Component {
static propTypes = {
title: PropTypes.string,
onLeftPress: PropTypes.func,
showDrawer: PropTypes.bool
}
_renderTitleComponent = () => {
const { title } = this.props
return (
<Header.Title textStyle={styles.titleText}>
{title}
</Header.Title>
)
}
_renderLeftComponent = () => {
const { onLeftPress, showDrawer } = this.props
return (
<TouchableView onPress={onLeftPress} style={styles.leftButton}>
<Icon name={showDrawer ? 'ios-menu' : 'ios-arrow-back'} size={18} color={'white'} />
</TouchableView>
)
}
render () {
return (
<Header
{...this.props}
style={styles.container}
renderTitleComponent={this._renderTitleComponent}
renderLeftComponent={this._renderLeftComponent}
/>
)
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'bluesteel'
},
titleText: {
color: 'white'
},
leftButton: {
padding: 14
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment