Ingen beskrivning

App.js 2.1KB

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