app.js for backup

 import React, {useEffectfrom 'react';

import {
  SafeAreaView,
  StyleSheet,
  ScrollView,
  View,
  Text,
  StatusBar,
  ActivityIndicator,
from 'react-native';
import {createStackNavigatorfrom '@react-navigation/stack';
import {createDrawerNavigatorfrom '@react-navigation/drawer';
import LottieView from 'lottie-react-native';
import RNPreventScreenshot from 'react-native-prevent-screenshot';

import HomeScreen from './Screens/HomeScreen';
import Login from './Screens/Login';
import SignUp from './Screens/SignUp';
import ChatScreen from './Screens/ChatScreen';
import SplashScreen from './Screens/SplashScreen';
import SignInScreen from './Screens/SignInScreen';
import SignUpScreen from './Screens/SignUpScreen';
import ProfileScreen from './Screens/ProfileScreen';
import Settings from './Screens/Settings';
import Terms_Privacy from './Screens/Terms_Privacy';
import Help from './Screens/Help';
import Privacy from './Screens/Privacy';
import Notifications from './Screens/Notifications';
import Advanced from './Screens/Advanced';
import sms_and_chats from './Screens/sms_and_chats';
import Contact from './Screens/Contact';
import RootStack from './Screens/RootStack';
import OnboardingScreen from './Screens/OnboardingScreen';
import EditProfileScreen from './Screens/EditProfileScreen';
import {NavigationContainerfrom '@react-navigation/native';
import {DrawerContentfrom './Screens/DrawerContent';
import AsyncStorage from '@react-native-community/async-storage'

const AppStack = createStackNavigator();

const Drawer = createDrawerNavigator();

RNPreventScreenshot;

const AppStackScreen = ({Navigation}) => {
  const [isLoadingsetIsLoading] = React.useState(true);
  const [isFirstLaunchsetIsFirstLaunch] = React.useState(true);
  

  // useEffect(() => {
  //   AsyncStorage.getItem('alreadylaunched').then(value => {
  //     if(value == null)
  //     {
  //       AsyncStorage.setItem('alreadylaunched','true');
  //       setIsFirstLaunch(true);
  //     }
  //     else
  //     {
  //       setIsFirstLaunch(false);
  //     }
  //   });
  // })

  // if(isFirstLaunch == null) {
  //   return null;
  // }
  // else if(isFirstLaunch == true)
  // {
  //   return(
  //   );
  // }
  // else
  // {
  //   <Login />
  // }
  
  useEffect(() => {
    setTimeout(() => {
      setIsLoading(false);
    }, 1700);
  }, []);

  if (isLoading) {
    return (
      <View style={{flex: 1justifyContent: 'center'alignItems: 'center'}}>
        <LottieView source={require('./assets/loader/4.json')} autoPlay loop />
      </View>
    );
  }


  // const initialLoginState = {
  //   isLoading: true,
  //   userName: null,
  //   userToken: null,
  // };

  
  // const loginReducer = (prevState, action) => {
  //   switch (action.type) {
  //     case 'RETRIVE_TOKEN':
  //       return {
  //         ...prevState,
  //         userToken: action.token,
  //         isLoading: false,
  //       };
  //     case 'LOGIN':
  //       return {
  //         ...prevState,
  //         userName: action.id,
  //         userToken: action.token,
  //         isLoading: false,
  //       };
  //     case 'LOGOUT':
  //       return {
  //         ...prevState,
  //         userName: null,
  //         userToken: null,
  //         isLoading: false,
  //       };
  //     case 'REGISTER':
  //       return {
  //         ...prevState,
  //         userName: action.id,
  //         userToken: action.token,
  //         isLoading: false,
  //       };
  //   }
  // };

  // const [loginState, dispatch] = React.useReducer(
  //   loginReducer,
  //   initialLoginState,
  // );

  // const authContext = React.useMemo(
  //   () => ({
  //     signIn: async (foundUser) => {
  //       // setUserToken('NIck');
  //       // setIsLoading(false);
  //       const userToken = String(foundUser[0].userToken);
  //       const userName = String(foundUser[0].userName);
  //       // if (userName == 'nickkubde2' && password == 'password')
  //       {
  //         try {
  //           await AsyncStorage.setItem('userToken', userToken);
  //         } catch (e) {
  //           console.log(e);
  //         }
  //       }

  //       dispatch({type: 'LOGIN', id: userName, token: userToken});
  //     },
  //     signOut: async () => {
  //       // setUserToken(null);
  //       // setIsLoading(false);
  //       try {
  //         await AsyncStorage.removeItem('userToken');
  //       } catch (e) {
  //         console.log(e);
  //       }
  //       dispatch({type: 'LOGOUT'});
  //     },
  //     signUp: () => {
  //       // setUserToken('NIck');
  //       // setIsLoading(false);
  //     },
  //     toggleTheme: () => {
  //       setIsDarkTheme((isDarkTheme) => !isDarkTheme);
  //     },
  //   }),
  //   [],
  // );

  // useEffect(() => {
  //   setTimeout(async () => {
  //     // setIsLoading(false);
  //     let userToken;
  //     userToken = null;
  //     try {
  //       userToken = await AsyncStorage.getItem('userToken');
  //     } catch (e) {
  //       console.log(e);
  //     }
  //     // console.log('user token:', userToken);
  //     dispatch({type: 'RETRIVE_TOKEN', token: userToken});
  //   }, 1000);
  // }, []);

  // useEffect(() => {
  //   AsyncStorage.getItem('alreadyLaunched').then(value => {
  //     if(value = null) {
  //       AsyncStorage.setItem('alredyLaunched', 'true');
  //       setIsFirstLaunch(true);
  //     } else{
  //       setIsFirstLaunch(false);
  //     }
  //   })
  // },[])

  // if(isFirstLaunch === null) {
  //   return null;
  // } else if(isFirstLaunch === true) {
    return (
    <NavigationContainer >
      <Drawer.Navigator
        drawerContent={(props=> <DrawerContent {...props} />} 
        initialRouteName="Home">
        <Drawer.Screen name="RootStack" component={RootStack} />
        {/* <Drawer.Screen name="Login" component={Login} />
        <Drawer.Screen name="SignUp" component={SignUp} /> */}
        <Drawer.Screen name="HomeScreen" component={HomeScreen} />
        <Drawer.Screen name="ProfileScreen" component={ProfileScreen} />
        <Drawer.Screen name="EditProfileScreen" component={EditProfileScreen} />
        <Drawer.Screen name="ChatScreen" component={ChatScreen} />
        <Drawer.Screen name="Settings" component={Settings} />
        <Drawer.Screen name="Help" component={Help} />
        <Drawer.Screen name="Privacy" component={Privacy} />
        <Drawer.Screen name="Notifications" component={Notifications} />
        <Drawer.Screen name="Advanced" component={Advanced} />
        <Drawer.Screen name="OnboardingScreen" component={OnboardingScreen} />
        <Drawer.Screen name="sms_and_chats" component={sms_and_chats} />
        <Drawer.Screen name="Terms_Privacy" component={Terms_Privacy} />
        <Drawer.Screen name="Contact" component={Contact} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
};
export default AppStackScreen;

Comments

Popular Posts