Auth.js 2.81 KB
import React, {useState, useEffect} from 'react';
import {ScrollView} from 'react-native';
import LoginComponent from "../components/Auth/LoginComponent";
import SignUpComponent from "../components/Auth/SignUpComponent";
import {useSelector} from "react-redux";
import {BUTTON_COLOR} from "../constant";
import SquareButtonComponent from "../components/Base/SquareButtonComponent";

const Auth = (props) => {
    // 데이터
    const {navigation} = props;
    const [tryLogin, setTryLogin] = useState(true);
    const {me} = useSelector(state => state.user);

    // 함수
    const changeTryLogin = () => {
        setTryLogin(prev => !prev)
    };

    // 렌더링
    useEffect(() => {
        if (me) {
            navigation.navigate('마이페이지');
        }
    }, [me]);
    return (
        <ScrollView>
            {
                tryLogin
                    ?
                    <>
                        <LoginComponent/>
                        <SquareButtonComponent
                            onPress={changeTryLogin}
                            text={'회원가입'}
                            style1={{
                                marginLeft: 20,
                                marginRight: 20,
                                marginTop: 10,
                                marginBottom: 10,
                                padding: 15,
                                borderRadius: 3,
                                backgroundColor: BUTTON_COLOR
                            }}
                            style2={{
                                fontSize: 16,
                                fontWeight: 'bold',
                                textAlign: 'center',
                                color: '#ffffff'
                            }}
                        />
                    </>
                    :
                    <>
                        <SignUpComponent/>
                        <SquareButtonComponent
                            onPress={changeTryLogin}
                            text={'로그인'}
                            style1={{
                                marginLeft: 20,
                                marginRight: 20,
                                marginTop: 10,
                                marginBottom: 10,
                                padding: 15,
                                borderRadius: 3,
                                backgroundColor: BUTTON_COLOR
                            }}
                            style2={{
                                fontSize: 16,
                                fontWeight: 'bold',
                                textAlign: 'center',
                                color: '#ffffff'
                            }}
                        />
                    </>
            }
        </ScrollView>
    )
};

export default Auth;