15.6.4 AuthForm 컴포넌트 만들기
AuthForm이라는 컴포넌트를 만들어서 이를 통해 회원가입 또는 로그인 기능을 구현하겠습니다. 이 컴포넌트는 isRegister Props를 통해 컴포넌트에서 회원가입 UI 또는 로그인 UI를 보여줄지 결정합니다.
components/AuthForm.tsx
import React, {useState} from 'react'; import { View, StyleSheet, Pressable, Platform, Text, TextInput, KeyboardAvoidingView, } from 'react-native'; export interface AuthFormProps { isRegister ; } function ({isRegister} AuthFormProps) { const [email, setEmail] (''); const [username, setUsername] (''); const [identifier, setIdentifier] (''); const [password, setPassword] (''); return ( <KeyboardAvoidingView style={styles.block} behavior={Platform. ({ios 'padding'})}> <View style={styles.block}> <View> {isRegister ? ( <> <TextInput style={styles.input} placeholder="이메일" value={email} onChangeText={setEmail} autoCapitalize="none" keyboardType="email-address" /> <TextInput style={styles.input} placeholder="계정명" value={username} onChangeText={setUsername} autoCapitalize="none" /> </> ) : ( <TextInput style={styles.input} placeholder="이메일 또는 계정명" value={identifier} onChangeText={setIdentifier} autoCapitalize="none" /> )} <TextInput style={styles.input} placeholder="비밀번호" secureTextEntry value={password} onChangeText={setPassword} /> <Pressable style={({pressed}) => [ styles.submit, Platform.OS === 'ios' && pressed && styles.submitPressed, ]} android_ripple={{color '#42a5f5'}}> <Text style={styles.submitText}> {isRegister ? '회원가입' : '로그인'} </Text> </Pressable> </View> </View> </KeyboardAvoidingView> ); } const styles StyleSheet. ({ block { flex 1, justifyContent 'center', paddingHorizontal 12, }, input { backgroundColor 'white', padding 8, borderColor '#dddddd', borderWidth 1, marginBottom 8, }, submit { marginTop 24, backgroundColor '#2196f3', height 56, borderRadius 4, alignItems 'center', justifyContent 'center', }, submitPressed { opacity 0.75, }, submitText { fontSize 16, color 'white', fontWeight 'bold', }, }); export default AuthForm;