Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@GollyJer
Last active February 24, 2017 18:33
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 GollyJer/966cc925cb2fc62a91caa360167db175 to your computer and use it in GitHub Desktop.
Save GollyJer/966cc925cb2fc62a91caa360167db175 to your computer and use it in GitHub Desktop.
Android Style Drawer Navigation example using reactnavigation.org and Exponent-js
import Exponent from 'exponent';
import React from 'react';
import {
Button,
Platform,
StatusBar,
StyleSheet,
Text,
TouchableHighlight,
View,
} from 'react-native';
import {
DrawerNavigator,
StackNavigator,
TabNavigator,
} from 'react-navigation';
import { MaterialCommunityIcons as Icon } from '@exponent/vector-icons';
/*
STYLING
*/
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
})
/*
COMPONENTS
*/
const App = () => (
<View style={{ flex: 1, backgroundColor: "#2B6DB5" }}>
{Platform.OS === 'ios' && <StatusBar barStyle="default" />}
{Platform.OS === 'android' && <View style={{ paddingTop: Exponent.Constants.statusBarHeight }} />}
<AppNavigation />
</View>
)
const MenuButton = ({ navigate }) => (
<TouchableHighlight onPress={() => { navigate('DrawerOpen') }}>
<Icon
name="menu"
size={24}
style={{ padding: 16, backgroundColor: "white" }}
/>
</TouchableHighlight >
)
const leftHeaderMenu = (navigation) => (
{ left: <MenuButton navigate={navigation.navigate} /> }
)
/*
SCREENS
*/
const LogInScreen = ({ navigation }) => (
<View style={styles.container} >
<Button title="Click Here to Log In" onPress={() => { navigation.navigate('LeftDrawer') }} />
</View>
)
const BasicScreen = ({ navigation }) => (
<View style={styles.container} >
<Text>I am Basic Screen</Text>
</View>
)
BasicScreen.navigationOptions = {
title: "Basic Screen",
header: leftHeaderMenu,
}
const Tab1Screen = () => (
<View style={styles.container} >
<Text>I fill up Tab 1, son!!</Text>
</View>
)
const Tab2Screen = () => (
<View style={styles.container} >
<Text>I fill up Tab 2, boo!!</Text>
</View>
)
/*
ROUTES
*/
const TabsNavigation = (
TabNavigator({
'Tab 1, Son!': { screen: Tab1Screen },
'Tab 2, Boo!': { screen: Tab2Screen },
})
)
TabsNavigation.navigationOptions = {
title: "Tabs Screen",
header: leftHeaderMenu,
}
const LeftDrawerNavigation = (
DrawerNavigator({
'Item1': { screen: StackNavigator({ 'Item1': { screen: BasicScreen } }) },
'Item2': { screen: StackNavigator({ 'Item2': { screen: TabsNavigation } }) },
})
)
const AppNavigation = (
StackNavigator({
'LogIn': { screen: LogInScreen },
'LeftDrawer': { screen: LeftDrawerNavigation },
}, {
headerMode: 'none'
}
)
)
Exponent.registerRootComponent(App)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment