Açıklama Yok

App.js 2.7KB

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