Нет описания

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