Nenhuma descrição

App.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. if (firebase.apps.length === 0) {
  11. firebase.initializeApp(firebaseConfig)
  12. }
  13. const Stack = createStackNavigator();
  14. export default class App extends Component {
  15. constructor(props){
  16. super(props);
  17. this.state = {
  18. loaded: false,
  19. }
  20. }
  21. componentDidMount(){
  22. firebase.auth().onAuthStateChanged((user) => {
  23. if (!user){
  24. this.setState({
  25. loggedIn: false,
  26. loaded: true,
  27. })
  28. }
  29. else{
  30. this.setState({
  31. loggedIn: true,
  32. loaded: true,
  33. })
  34. }
  35. })
  36. }
  37. render() {
  38. const { loggedIn, loaded } = this.state
  39. if(!loaded){
  40. return(
  41. <View style={styles.regcontainer}>
  42. <Text>Hopper</Text>
  43. </View>
  44. );
  45. }
  46. if(!loggedIn){
  47. return (
  48. <NavigationContainer>
  49. <Stack.Navigator>
  50. <Stack.Screen name={" "} options={{headerShown: false}} component={LoginScreen}/>
  51. <Stack.Screen name={"Register"} options={{headerTransparent: true, headerTitle: " "}} component={RegisterScreen}/>
  52. </Stack.Navigator>
  53. </NavigationContainer>
  54. );
  55. }
  56. return(
  57. <View style={styles.regcontainer}>
  58. <Text>Cheese</Text>
  59. </View>
  60. );
  61. }
  62. }