Skip to content

Instantly share code, notes, and snippets.

@dk0r
Last active August 28, 2017 18:23
Show Gist options
  • Save dk0r/8916d8b946642ae8c8be63212f61b3da to your computer and use it in GitHub Desktop.
Save dk0r/8916d8b946642ae8c8be63212f61b3da to your computer and use it in GitHub Desktop.
Receiving error that `this.props.drawer` is undefined: http://i.imgur.com/uEtsvEH.png
import { TabNavigator } from 'react-navigation'
export const Tabs = TabNavigator(
{
Home: {
screen: Container,
navigationOptions: {
tabBarLabel: 'Home',
tabBarIcon: ({ tintColor }) =>
<Icon name="ios-home" size={28} color={tintColor} />
}
}
},
{
tabBarPosition: 'bottom',
//swipeEnabled: false,
tabBarOptions: {
showIcon: true,
showLabel: false,
activeTintColor: '#fff8e6',
style: {
backgroundColor: 'black'
},
tabStyle: {
height: dims.navBarHeight //Tested that minimum height for navBar is 24
},
indicatorStyle: {
backgroundColor: '#ffc423'
}
}
}
)
export default class Container extends Component {
render() {
openDrawer = () = > {
this.drawer.openDrawer()
alert('Drawer opened!!')
}
return (
<DrawerLayout
//Remeber that ref receives the <DrawerLayout> component as it's input
//more details @ https://facebook.github.io/react/docs/refs-and-the-dom.html#adding-a-ref-to-a-dom-element
ref={e => (this.drawer = e)}
drawerWidth={300}
drawerPosition={DrawerLayout.positions.Left}
//Below renders the content contained within the sliding drawer
renderNavigationView={() =>
<DrawerContent {...this.props} />}
drawerLockMode={'locked-closed'}
>
{/* This is the main screen (containing the button to open the drawer) */}
<Home openDrawer={this.openDrawer} />
</DrawerLayout>
)
}
}
export default class Home extends Component {
render() {
return (
<DrawerButton {...this.props} size={100} />
)
}
}
export default class DrawerButton extends Component {
render() {
return (
<TouchableOpacity
onPress={() => alert(`${this.props.openDrawer}`)}
>
<Icon name="md-menu" size={this.props.size} />
</TouchableOpacity>
)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment