Skip to content

Commit

Permalink
Merge pull request #3 from GantMan/custom_drawer
Browse files Browse the repository at this point in the history
add custom container and logout
  • Loading branch information
GantMan authored Aug 28, 2017
2 parents 66d94e5 + 0494811 commit 2fb97fb
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
66 changes: 66 additions & 0 deletions Containers/DrawerContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import React from 'react'
import { StyleSheet, Text, View, Image } from 'react-native'
import { NavigationActions } from 'react-navigation'

export default class DrawerContainer extends React.Component {

logout = () => {
// This will reset back to loginStack
// https://github.com/react-community/react-navigation/issues/1127
const actionToDispatch = NavigationActions.reset({
index: 0,
key: null, // black magic
actions: [NavigationActions.navigate({ routeName: 'loginStack' })]
})
this.props.navigation.dispatch(actionToDispatch)
}

render() {
const { navigation } = this.props
return (
<View style={styles.container}>
<Text
onPress={() => navigation.navigate('screen1')}
style={styles.uglyDrawerItem}>
Screen 1
</Text>
<Text
onPress={() => navigation.navigate('screen2')}
style={styles.uglyDrawerItem}>
Screen 2
</Text>
<Text
onPress={() => navigation.navigate('screen3')}
style={styles.uglyDrawerItem}>
Screen 3
</Text>
<Text
onPress={this.logout}
style={styles.uglyDrawerItem}>
Log Out
</Text>
</View>
)
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#ccc',
paddingTop: 40,
paddingHorizontal: 20
},
uglyDrawerItem: {
fontSize: 20,
color: 'blue',
padding: 15,
margin: 5,
borderRadius: 10,
borderColor: 'blue',
borderWidth: 1,
textAlign: 'center',
backgroundColor: 'white',
overflow: 'hidden'
}
})
4 changes: 3 additions & 1 deletion Navigation/AppNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import ForgottenPasswordScreen from '../Containers/ForgottenPasswordScreen'
import Screen1 from '../Containers/Screen1'
import Screen2 from '../Containers/Screen2'
import Screen3 from '../Containers/Screen3'
import DrawerContainer from '../Containers/DrawerContainer'

// https://github.com/react-community/react-navigation/issues/1254
const noTransitionConfig = () => ({
Expand All @@ -23,7 +24,8 @@ const DrawerStack = DrawerNavigator({
screen2: { screen: Screen2 },
screen3: { screen: Screen3 },
}, {
gesturesEnabled: false
gesturesEnabled: false,
contentComponent: (props) => <DrawerContainer {...props} />
})

const DrawerNavigation = StackNavigator({
Expand Down

0 comments on commit 2fb97fb

Please sign in to comment.