No Description

App.js 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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/RegisterScreen';
  6. import LoginScreen from './screens/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/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. /*const seConfig = {
  16. apiKey: "AIzaSyDW-ABAQ3r_WR7C7WC_3VprL77NcAoitJI",
  17. authDomain: "freehand-d8ecd.firebaseapp.com",
  18. projectId: "freehand-d8ecd",
  19. storageBucket: "freehand-d8ecd.appspot.com",
  20. messagingSenderId: "48371388186",
  21. appId: "1:48371388186:web:9a5a4bf1218e17ac6326a3"
  22. };
  23. */
  24. // Initialize Firebase
  25. //const app = firebase.initializeApp(seConfig);
  26. if (firebase.apps.length === 0) {
  27. firebase.initializeApp(firebaseConfig)
  28. }
  29. const store = createStore(rootReducer, applyMiddleware(thunk));
  30. const Stack = createStackNavigator();
  31. export class App extends Component {
  32. constructor(props){
  33. super(props);
  34. this.state = {
  35. loaded: false,
  36. }
  37. }
  38. componentDidMount(){
  39. firebase.auth().onAuthStateChanged((user) => {
  40. if (!user){
  41. this.setState({
  42. loggedIn: false,
  43. loaded: true,
  44. })
  45. }
  46. else{
  47. this.setState({
  48. loggedIn: true,
  49. loaded: true,
  50. })
  51. }
  52. })
  53. }
  54. render() {
  55. const { loggedIn, loaded } = this.state
  56. if(!loaded){
  57. return(
  58. <View style={styles.regcontainer}>
  59. <Text>Hopper</Text>
  60. </View>
  61. );
  62. }
  63. if(!loggedIn){
  64. return (
  65. <NavigationContainer>
  66. <Stack.Navigator>
  67. <Stack.Screen name={" "} options={{headerShown: false}} component={LoginScreen}/>
  68. <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
  69. </Stack.Navigator>
  70. </NavigationContainer>
  71. );
  72. }
  73. return(
  74. <Provider store={store}>
  75. <NavigationContainer>
  76. <Stack.Navigator initialRouteName="Home">
  77. <Stack.Screen name="HomeScreen" component={AddScreen} />
  78. </Stack.Navigator>
  79. </NavigationContainer>
  80. </Provider>
  81. );
  82. }
  83. }