Skip to content

Instantly share code, notes, and snippets.

@burgalon
Created April 28, 2016 10:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save burgalon/20e4154886d46a50bbfee732eaf7b913 to your computer and use it in GitHub Desktop.
Save burgalon/20e4154886d46a50bbfee732eaf7b913 to your computer and use it in GitHub Desktop.
use ToolbarAndroid with react-native-router-flux
export default class App extends React.Component {
render() {
return <Router>
<Scene key="root" navBar={Platform.OS=='ios' ? NavBar : NavBarAndroid}>
<Scene key="home" component={HomeScreen} ... />
</Scene>
</Router>
}
}
class NavBarAndroid extends React.Component {
onActionSelected = (i) => {
if(i==0) this.props.onRight(this.props)
else if(i==1) this.props.onLeft(this.props)
}
render() {
let {getTitle, rightTitle, leftTitle} = this.props
let actions = []
let titles = [rightTitle, leftTitle]
titles.forEach(title => {
if(title && title.props && title.props.name){
actions.push({iconName: title.props.name, title: title.props.name, show: 'always'})
} else if(title) {
actions.push({title, show: 'always'})
}
})
return <ToolbarAndroid
navIcon={require('./Icon-40.png')}
style={styles.header}
title={getTitle(this.props)}
actions={actions}
onIconClicked={() => Actions.pop()}
onActionSelected={this.onActionSelected}
/>
}
}
const styles = StyleSheet.create({
header: {
backgroundColor: '#2196F3',
paddingTop: 0,
top: 0,
height: 64,
right: 0,
left: 0,
borderBottomWidth: 0.5,
borderBottomColor: '#828287',
position: 'absolute',
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment