Brak opisu

App.js 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. import HomeScreen from './screens/main/Home_page';
  21. import Calendario from './screens/main/Calendar';
  22. import Time from './screens/main/StateTime';
  23. import Search from './screens/main/Search';
  24. if (firebase.apps.length === 0) {
  25. firebase.initializeApp(firebaseConfig)
  26. }
  27. const Stack = createStackNavigator();
  28. const Drawer = createDrawerNavigator();
  29. const store = createStore(rootReducer, applyMiddleware(thunk));
  30. export default class App extends Component {
  31. constructor(props){
  32. super(props);
  33. this.state = {
  34. loaded: false,
  35. }
  36. }
  37. componentDidMount(){
  38. firebase.auth().onAuthStateChanged((user) => {
  39. if (!user){
  40. this.setState({
  41. loggedIn: false,
  42. loaded: true,
  43. })
  44. }
  45. else{
  46. this.setState({
  47. loggedIn: true,
  48. loaded: true,
  49. })
  50. }
  51. });
  52. }
  53. createHomeStack = () =>
  54. <Stack.Navigator>
  55. <Stack.Screen name={"Home"} options={{headerShown: false}} component={HomeScreen}/>
  56. <Stack.Screen name={"Mail"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={MailScreen}/>
  57. <Stack.Screen name={"Availability"} options={{ headerStatusBarHeight: 100, headerTransparent: true, headerBackTitle: " ", headerTitle: " "}} component={AvailabilityScreen}/>
  58. </Stack.Navigator>
  59. render() {
  60. const { loggedIn, loaded } = this.state
  61. if(!loaded){
  62. return(
  63. <Loading/>
  64. );
  65. }
  66. if(!loggedIn){
  67. return (
  68. <NavigationContainer>
  69. <Stack.Navigator>
  70. <Stack.Screen name={"Login"} options={{headerShown: false}} component={LoginScreen}/>
  71. <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
  72. </Stack.Navigator>
  73. </NavigationContainer>
  74. );
  75. }
  76. return(
  77. <Provider store={store}>
  78. <NavigationContainer>
  79. <Stack.Navigator initialRouteName="Home">
  80. <Stack.Screen name="Home" options={{headerTransparent: true, headerTitle: " "}} component={HomeScreen} />
  81. <Stack.Screen name="Calendar" component={Calendario}/>
  82. <Stack.Screen name = "StateTime" component={Time}/>
  83. <Stack.Screen name = "Search" component={Search}/>
  84. </Stack.Navigator>
  85. </NavigationContainer>
  86. </Provider>
  87. );
  88. }
  89. }