์ฑ์์ ๊ฐ์ฅ ๋ง์ด ์ฌ์ฉ๋๋ ์ปดํฌ๋ํธ ์ค ํ๋๋
๋ฐ๋ก TextInput
์ด๋ค.
ํ์ง๋ง ๊ธฐ๋ณธ ์ฌ์ฉ๋ง์ผ๋ก๋ ๋ถํธํ ์
๋ ฅ UX,
์๋ฅผ ๋ค์ด ํค๋ณด๋์ ๊ฐ๋ ค์ง๋ ์
๋ ฅ์ฐฝ,
ํฌ์ปค์ค๊ฐ ์ ๋์ด๊ฐ๋ ๋ฌธ์ ๋ฑ์ด ์๊ธด๋ค.
์ด๋ฒ ๊ธ์ React Native์์ ์ฌ์ฉ์ ์ ๋ ฅ ๊ฒฝํ์ ์ต์ ํํ๋ ์ ๋ต์ ์ ๋ฆฌํ ๊ธ์ด๋ค.
<TextInput
value={email}
onChangeText={setEmail}
placeholder="์ด๋ฉ์ผ์ ์
๋ ฅํ์ธ์"
keyboardType="email-address"
autoCapitalize="none"
returnKeyType="next"
/>
keyboardType
: ์
๋ ฅ ํค๋ณด๋ ์ข
๋ฅ (default
, numeric
, email-address
, ...) autoCapitalize
: ์๋ ๋๋ฌธ์ ์ค์ (none
, sentences
, ...) returnKeyType
: ๋ค์/์๋ฃ ๋ฒํผ UI ๋ณ๊ฒฝ secureTextEntry
: ๋น๋ฐ๋ฒํธ ์
๋ ฅ ์ ์ฌ์ฉconst emailRef = useRef(null);
const passwordRef = useRef(null);
<TextInput
ref={emailRef}
returnKeyType="next"
onSubmitEditing={() => passwordRef.current?.focus()}
/>
<TextInput
ref={passwordRef}
returnKeyType="done"
/>
โ
๋ก๊ทธ์ธ/ํ์๊ฐ์
ํ๋ฉด์์ ์์ฃผ ์ฌ์ฉ
โ
ํค๋ณด๋์์ '๋ค์' ๋๋ ์ ๋ ์์ฐ์ค๋ฝ๊ฒ ์ด๋
KeyboardAvoidingView
<KeyboardAvoidingView behavior="padding">
<ScrollView>
<TextInput />
</ScrollView>
</KeyboardAvoidingView>
padding
, Android๋ height
์ถ์ฒ KeyboardAwareScrollView
(๋ผ์ด๋ธ๋ฌ๋ฆฌ)npm install react-native-keyboard-aware-scroll-view
const [email, setEmail] = useState('');
const [error, setError] = useState('');
useEffect(() => {
const emailRegex = /\S+@\S+\.\S+/;
setError(emailRegex.test(email) ? '' : '์ฌ๋ฐ๋ฅธ ์ด๋ฉ์ผ ํ์์ด ์๋๋๋ค.');
}, [email]);
โ
์ค์๊ฐ ํผ๋๋ฐฑ
โ
์ค๋ฅ ๋ฉ์์ง ์ถ๋ ฅ โ UX ์น์ ๋ ์์น
ํญ๋ชฉ | ์ ๋ต |
---|---|
placeholder ์ปฌ๋ฌ | placeholderTextColor="#999" ๋ฑ ๋ช
ํํ ์ง์ |
ํฐ์น ์ ํค๋ณด๋ ๋ซ๊ธฐ | TouchableWithoutFeedback + Keyboard.dismiss() ์กฐํฉ |
์๋ฌ ๋ฉ์์ง UI | ์ ๋ ฅ์ฐฝ ์๋์ ์๊ฒ ํ์, ์์์ ๋ถ์ ๊ณ์ด |
์ ๋ ฅ ์๋ฃ ์ ์ฒ๋ฆฌ | onSubmitEditing ์ผ๋ก ๋ฒํผ ํด๋ฆญ ์์ด๋ ์ ์ก ๊ฐ๋ฅ |
์ฒ์์๋ TextInput๋ง ๋ฃ์ด๋ ๋๋ ์ค ์์๋๋ฐ
๋ง์ ์ ์ ์
์ฅ์์ ์จ๋ณด๋
ํฌ์ปค์ค๊ฐ ์ ๋์ด๊ฐ๊ณ , ํค๋ณด๋๊ฐ ๋ฒํผ์ ๊ฐ๋ฆฌ๊ณ ,
์
๋ ฅ ์๋ฌ๊ฐ ๋ญ์ง๋ ์ ์๋ ค์ฃผ๋ ์ฑ์ ๋ต๋ตํ UX ๊ทธ ์์ฒด์๋ค.
์ง๊ธ์ ๊ธฐ๋ณธ์ ์ผ๋ก
โ๏ธ โ์ ๋ ฅ์ ๊ธฐ๋ฅ์ด ์๋๋ผ ํ๋ฆ์ด๋ค. ๊ทธ ํ๋ฆ์ด ๋ถ๋๋ฌ์ธ์๋ก ์ฑ์ ์ข์์ง๋ค.โ