Без опису

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import React, { Component } from 'react';
  2. import firebase from 'firebase'
  3. import thunk from 'redux-thunk';
  4. import { NavigationContainer } from '@react-navigation/native';
  5. import { createStackNavigator } from '@react-navigation/stack';
  6. import { createDrawerNavigator } from '@react-navigation/drawer';
  7. import { Provider } from 'react-redux';
  8. import { createStore, applyMiddleware } from 'redux';
  9. import AvailabilityScreen from './screens/AvailabilityScreen';
  10. import MailScreen from './screens/MailScreen';
  11. //import RegisterScreen from './screens/RegisterScreen';
  12. import RegisterScreen from './screens/auth/RegisterScreen';
  13. //import LoginScreen from './screens/LoginScreen';
  14. import LoginScreen from './screens/auth/LoginScreen';
  15. import HomeScreen from './screens/HomeScreen';
  16. //import Loading from './components/Loading';
  17. import Loading from './screens/main/Loading';
  18. import { firebaseConfig } from './config/firebaseConfig';
  19. import rootReducer from './redux/reducers'
  20. if (firebase.apps.length === 0) {
  21. firebase.initializeApp(firebaseConfig)
  22. }
  23. const Stack = createStackNavigator();
  24. const Drawer = createDrawerNavigator();
  25. const store = createStore(rootReducer, applyMiddleware(thunk));
  26. export default class App extends Component {
  27. constructor(props){
  28. super(props);
  29. this.state = {
  30. loaded: false,
  31. }
  32. }
  33. componentDidMount(){
  34. firebase.auth().onAuthStateChanged((user) => {
  35. if (!user){
  36. this.setState({
  37. loggedIn: false,
  38. loaded: true,
  39. })
  40. }
  41. else{
  42. this.setState({
  43. loggedIn: true,
  44. loaded: true,
  45. })
  46. }
  47. });
  48. }
  49. createHomeStack = () =>
  50. <Stack.Navigator>
  51. <Stack.Screen name={"Home"} options={{headerShown: false}} component={HomeScreen}/>
  52. <Stack.Screen name={"Mail"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={MailScreen}/>
  53. <Stack.Screen name={"Availability"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={AvailabilityScreen}/>
  54. </Stack.Navigator>
  55. render() {
  56. const { loggedIn, loaded } = this.state
  57. if(!loaded){
  58. return(
  59. <Loading/>
  60. );
  61. }
  62. if(!loggedIn){
  63. return (
  64. <NavigationContainer>
  65. <Stack.Navigator>
  66. <Stack.Screen name={"Login"} options={{headerShown: false}} component={LoginScreen}/>
  67. <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
  68. </Stack.Navigator>
  69. </NavigationContainer>
  70. );
  71. }
  72. return(
  73. <Provider store={store}>
  74. <NavigationContainer>
  75. <Drawer.Navigator>
  76. <Drawer.Screen name={" "} options={{drawerLabel: "Home", headerTransparent: true}} children={this.createHomeStack}/>
  77. </Drawer.Navigator>
  78. </NavigationContainer>
  79. </Provider>
  80. );
  81. }
  82. }