Skip to content

Instantly share code, notes, and snippets.

@harshq
Last active June 6, 2021 09:18
Show Gist options
  • Save harshq/31bc9bcbe296bbfbcba897a8e801e797 to your computer and use it in GitHub Desktop.
Save harshq/31bc9bcbe296bbfbcba897a8e801e797 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import {
Text,
View,
} from 'react-native';
import {
DrawerNavigator,
StackNavigator,
TabNavigator,
NavigationActions
} from 'react-navigation';
const DummyComp = col => () => <View style={{ flex: 1, backgroundColor: col }} />;
class CompanySelect extends Component {
static navigationOptions = ({ navigation }) => ({
title: 'Company Select',
header: null
});
resetTo(route:string):void {
const actionToDispatch = NavigationActions.reset({
index: 0,
key: null,
actions: [NavigationActions.navigate({ routeName: route })],
});
this.props.navigation.dispatch(actionToDispatch);
}
render() {
return (
<View style={{ flex: 1, backgroundColor: '#2ecc71', paddingTop: 100 }}>
<Text onPress={() => this.resetTo('Drawer')} >abc</Text>
</View>
);
}
}
class Login extends Component {
static navigationOptions = ({ navigation }) => ({
title: 'dasd',
header: null
});
resetTo(route:string):void {
const actionToDispatch = NavigationActions.reset({
index: 0,
key: null,
actions: [NavigationActions.navigate({ routeName: route })],
});
this.props.navigation.dispatch(actionToDispatch);
}
render() {
return (
<View style={{ flex: 1, backgroundColor: '#2ecc71', paddingTop: 100 }}>
<Text onPress={() => this.resetTo('CompanySelect')} >abc</Text>
</View>
);
}
}
class Foo extends Component {
render(){
return (
<View style={{flex: 1, backgroundColor: 'red'}}>
<Text onPress={()=> this.props.navigation.navigate('Bar') }>To bar</Text>
</View>
)
}
}
class Bar extends Component {
render(){
return (
<View style={{flex: 1, backgroundColor: 'blue'}}>
<Text onPress={()=> {} }>To bar</Text>
</View>
)
}
}
const StackFooBar = StackNavigator({
Foo: { screen: Foo },
Bar: { screen : Bar },
});
const TabNav = TabNavigator({
TabOne: { screen: StackFooBar },
TabTwo: { screen: DummyComp('#e67e22') }
}, {
tabBarPosition: 'bottom'
});
const DrawerNav = DrawerNavigator({
Tabs: { screen: TabNav }
});
const App = StackNavigator({
Login: { screen: Login },
CompanySelect: { screen: CompanySelect },
Drawer: { screen : DrawerNav },
},{
headerMode: 'none'
});
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment