Frontend ๊ฐœ๋ฐœ์ž - hyo.loui

Project : MZL - ํšŒ์›๊ฐ€์ž… ๋ณธ๋ฌธ

Project

Project : MZL - ํšŒ์›๊ฐ€์ž…

hyo.loui 2023. 1. 9. 21:08

๐ŸŽฏ๋ชฉ์  :

Firebase - Authentication : ํšŒ์›๊ฐ€์ž… ๊ธฐ๋Šฅ ํ•™์Šต ๋ฐ ์ ์šฉ >> Firebase : FireStore ์—ฐ๊ฒฐ

 

๐Ÿคข ์˜ค๋ฅ˜ ํ•ด๊ฒฐ :

  • ์Šคํฌ๋กค ๋ฌธ์ œ <KeyboardAwareScrollView/> ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ํƒœ๊ทธ๋กœ ํ•ด๊ฒฐ
  • ํœด๋จผ์—๋Ÿฌ..

1. UI Layout ๋งŒ๋“ค๊ธฐ

UI๋ฅผ ๋งŒ๋“ค๋ฉด์„œ ํ‚ค๋ณด๋“œ ํ™œ์„ฑ ์‹œ์— ๋†’์ด๊ฐ€ ๊ณ ์ •๋˜์–ด์žˆ๋Š” ์ด์Šˆ๋กœ

์Šคํฌ๋กค์ด ๋˜์ง€์•Š์•„ <KeyboardAwareScrollView/> ๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ–ˆ๋‹ค..

 

์ด ๋ฌธ์ œ๋กœ ํผ๋ธ”๋ฆฌ์…”๋กœ ์žฌ์งํ•˜๋˜ ์ง์žฅ์—์„œ ๊ณจ๋จธ๋ฆฌ๋ฅผ ์ฉ์€ ์ ์ด ์žˆ๋Š”๋ฐ

ํŒ€์›์ค‘ ํ•œ๋ถ„์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”์ฒœ ํ•ด์ฃผ์…”์„œ ์•„์ฃผ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด๊ฒฐ๋˜์—ˆ๋‹ค.. (์—๋Ÿฌ ํ•ด๊ฒฐ ์ฐธ๊ณ )

 

๊ทธ๋ ‡๊ฒŒ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ๊ฐ€์ ธ์˜จ ํƒœ๊ทธ๋กœ ์ƒ์œ„๋ฅผ ๊ฐ์‹ธ์ฃผ์—ˆ๊ณ ,

 

ํฌ๊ฒŒ ๋‹‰๋„ค์ž„, ์ด๋ฉ”์ผ, ๋น„๋ฐ€๋ฒˆํ˜ธ, ๋น„๋ฐ€๋ฒˆํ˜ธ 2์ฐจ ํ™•์ธ
๋ถ€๋ถ„์œผ๋กœ ๋‚˜๋ˆ„์—ˆ๋‹ค

 

ํ•˜์ง€๋งŒ ํ”„๋กœ์ ํŠธ ๊ธฐ๋Šฅ์‚ฌํ•ญ์œผ๋กœ

์ž…๋ ฅ๊ฐ’์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ๋ฅผ ํ†ตํ•ด ๋ฉ”์„ธ์ง€๋ฅผ ์ž…๋ ฅํ•ด์ฃผ๋Š” Text๊ฐ€ ํ•„์š”ํ•ด์„œ

setState๋ฅผ ํ™œ์šฉํ•ด Text ๋ฅผ ๋ฏธ๋ฆฌ ๋„ฃ์–ด ์ฃผ์—ˆ๋‹ค ( ์•„๋ž˜ ์ƒ์„ธ๋‚ด์šฉ ์ž‘์„ฑ )


2. ์œ ํšจ์„ฑ ๊ฒ€์‚ฌ

์œ„์ฒ˜๋Ÿผ ํ•ด๋‹น ๋‚ด์šฉ์˜ ๊ฐ’์ด ์—†๋Š”์ƒํƒœ ์ฆ‰, false == !state๋ฅผ ํ™œ์šฉํ•ด์„œ

๋นˆ๊ฐ’์— ๋Œ€ํ•œ ์œ ํšจ์„ฑ๊ฒ€์‚ฌ๋ฅผ ์ง„ํ–‰ํ–ˆ๊ณ ,

 

๋นˆ๊ฐ’์— ๋Œ€ํ•œ ํฌ์ปค์Šค๋ฅผ ์ง„ํ–‰์‹œ์ผœ์ฃผ๊ธฐ ์œ„ํ•ด useRef Hook์„ ์‚ฌ์šฉํ•ด์„œ

ํ•ด๋‹น TextInput ํƒœ๊ทธ์— focus() ํ•จ์ˆ˜๋ฅผ ์‹คํ–‰ ์‹œ์ผœ ์ฃผ์—ˆ๋‹ค.

 

๋‚˜๋จธ์ง€๋Š” ๋ณด์ด๋Š” ๋ฉ”์„ธ์ง€์™€ ๊ฐ™๋‹ค

 

์—ฌ๊ธฐ์„œ ๋‚ด๊ฐ€ ๋งŒ๋“ค์–ด ์‚ฌ์šฉํ•œ alertTextTimer ํ•จ์ˆ˜๋ฅผ ์†Œ๊ฐœํ•˜๊ฒ ๋‹ค

์œ„์—์„œ ์–ธ๊ธ‰ํ–ˆ๋˜ ๋ถ€๋ถ„์˜ ์œ ํšจ์„ฑ๊ฒ€์‚ฌ ๋ฉ”์„ธ์ง€๋ฅผ ๋ฐ›๋„๋ก

state๋ฅผ ์ธ์ˆ˜๋กœ๋ฐ›์€ ํ…์ŠคํŠธ๋กœ update๋ฅผ ์‹œ์ผœ์ฃผ์—ˆ๊ณ ,

setTimeout์„ ํ†ตํ•ด ํ•ด๋‹น ํ…์ŠคํŠธ๋Š” 3์ดˆ๊ฐ€ ์ง€๋‚˜๋ฉด ์‚ฌ๋ผ์ง€๋„๋ก ํ•ด์ฃผ์—ˆ๋‹ค



3. authentication >> ํšŒ์›๊ฐ€์ž… api

Authentication์˜ API ์ธ createUserWithemailAndPassword ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ํšŒ์›๊ฐ€์ž…์„ ์ง„ํ–‰์‹œ์ผฐ๋‹ค.

Authentication์„ ์—ฐ๊ฒฐํ•œ ๋ณ€์ˆ˜์ธ auth์™€

state๋กœ TextInput ์—์„œ ๋ฐ›์•„์˜ค๋Š” email ๊ณผ password

 

์ด๋ ‡๊ฒŒ 3๊ฐœ๋ฅผ ์ธ์ž๋กœ ๋ฐ›์•„์˜ค๊ณ 

API๊ฐ€ ์ •์ƒ ์ž‘๋™ํ–ˆ์„ ๋•Œ,

 

updateProfile ์ด๋ผ๋Š” API๋กœ ํ•ด๋‹น ์œ ์ €์˜ ํ”„๋กœํ•„์˜ ๋‹‰๋„ค์ž„์„ ์—…๋ฐ์ดํŠธ ์‹œ์ผœ์ฃผ์—ˆ๋‹ค.

 

์—ฌ๊ธฐ์„œ email๊ณผ password, displayName ์€ es6 ๋ฌธ๋ฒ•์ด ์ ์šฉ๋˜์–ด

๊ธฐ์กด์— email: email ์„ ๋ฐ˜๋ณตํ•˜์ง€ ์•Š์•„๋„ ์•Œ์•„์„œ ๋“ค์–ด๊ฐ€๋„๋ก 

ํ‚ค์™€ ๋ฐธ๋ฅ˜๊ฐ€ ๋™์ผํ•˜๋‹ค๋ฉด
ํ•จ์ถ•ํ˜•์„ ์ธ์ง€ํ•ด ์ž๋™์œผ๋กœ ์œ„์™€๊ฐ™์ด ํ• ๋‹นํ•ด ์ค„ ์ˆ˜ ์žˆ๋‹ค.

 

๋˜ํ•œ, .catch๋ฌธ์„ ์ด์šฉํ•ด

์—๋Ÿฌ๋ฅผ ์œ ํšจ์„ฑ๊ฒ€์‚ฌ์—์„œ ํ™œ์šฉํ•œ ํ•จ์ˆ˜๋ฅผ ์ ์šฉํ•˜์—ฌ

์–ด๋– ํ•œ ์—๋Ÿฌ๊ฐ€ ๋‚ฌ๋Š”์ง€๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ์•Œ๋ ค์ค„ ์ˆ˜ ์žˆ์—ˆ๋‹ค

 


4. ํšŒ์›๊ฐ€์ž… ์ •์ƒ์ž‘๋™

์ž‘๋™์ด ์ •์ƒ์ ์œผ๋กœ ์ด๋ฃจ์–ด ์ง„๋‹ค๋ฉด

.then ํ•จ์ˆ˜๋“ค์ด ์ž‘๋™๋  ๊ฒƒ์ด๋‹ค

 

๊ทธ๋ž˜์„œ ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๊ฐ€ ๋˜๋ฉด ux์ ์œผ๋กœ ํŽธ๋ฆฌํ•˜๋„๋ก

reset ํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•ด ๋‹ค์‹œ Home ์˜ ์ƒํƒœ๋กœ ๋Œ์•„๊ฐ€๊ฒŒ ํ•ด์ค€๋‹ค

 

์ด ์ „์—๋Š” navigate๋ฅผ ์‚ฌ์šฉํ•ด์„œ Home์œผ๋กœ ํ•ธ๋“ค๋ง์„ ํ–ˆ์—ˆ๋Š”๋ฐ

 

tabs ๋ถ€๋ถ„์ด ๋‚˜์˜ค์ง€ ์•Š๊ณ , ์ปดํฌ๋„ŒํŠธ๋งŒ ๋ Œ๋”๋ง ๋˜์—ˆ๋˜ ํ˜„์ƒ์œผ๋กœ

๋‹ค์‹œ reset์„ ํ™œ์šฉํ•ด refactoring์„ ์ง„ํ–‰ํ–ˆ๋‹ค!


+ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ :

 

before - ํ•ด๊ฒฐ ์ „

 

after - ํ•ด๊ฒฐ ํ›„

 

 

+ ์˜ค๋ฅ˜ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•:

https://github.com/APSL/react-native-keyboard-aware-scroll-view

 

GitHub - APSL/react-native-keyboard-aware-scroll-view: A ScrollView component that handles keyboard appearance and automatically

A ScrollView component that handles keyboard appearance and automatically scrolls to focused TextInput. - GitHub - APSL/react-native-keyboard-aware-scroll-view: A ScrollView component that handles ...

github.com

๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ณต์‹ ๊นƒํ—ˆ๋ธŒ์— ์ƒ์„ธํ•œ ๋‚ด์šฉ์ด ๋‚˜์™€์žˆ๋‹ค.

 

์งง๊ฒŒ ์š”์•ฝํ•˜์ž๋ฉด,

 

npm i react-native-keyboard-aware-scroll-view --save
  • ์œ„ ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด ์ธ์Šคํ†จ

 

  • ์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ์—์„œ import { KeyboardAwareScrollView }

 

  • import ํ•œ ํƒœ๊ทธ๋กœ ์ƒ์œ„ ํƒœ๊ทธ ๊ฐ์‹ธ์ฃผ๋ฉด ๋!

 


 

 ์ตœ์ข… ์ •๋ฆฌ 

  1. ์œ ํšจ์„ฑ๊ฒ€์‚ฌ์— ํ†ต๊ณผ๋˜์ง€ ์•Š๋Š”๋‹ค๋ฉด ์‹คํ–‰ํ•  alertTextTimer() ํ•จ์ˆ˜ ๋งŒ๋“ค์–ด์ฃผ์—ˆ๋‹ค ( ๋ฉ”์„ธ์ง€ ๋ณด์—ฌ์ฃผ๊ณ  ์‚ฌ๋ผ์ง€๊ธฐ )
    ๊ทธ ํ›„ useRef Hook์„ ํ™œ์šฉํ•ด focus() ๊ฐ€ ์‹คํ–‰๋˜์–ด ํ•ด๋‹นํ•˜๋Š” TextInput์œผ๋กœ ์ž๋™์ ์œผ๋กœ ์ปค์„œ๊ฐ€ ์ƒ๊ธฐ๊ฒŒ ํ–ˆ๋‹ค
  2. createUserWithemailAndPassword ํ•จ์ˆ˜๋Š” auth key / email / password ์ด ์„ธ๊ฐœ๊ฐ€ ํ•„์ˆ˜ ๊ฐ’์ด๋‹ค
  3. ๋‹‰๋„ค์ž„์ธ displayName ์€ ํ•จ๊ป˜ ์ „๋‹ฌํ•˜์ง€ ๋ชปํ•˜๊ธฐ ๋•Œ๋ฌธ์— ํšŒ์›๊ฐ€์ž… ์งํ›„ updateProfile ํ•จ์ˆ˜๋กœ ๊ฐ™์ด ๋‹‰๋„ค์ž„์„ ๋„ฃ์–ด์ฃผ์—ˆ๋‹ค
  4. ํšŒ์›๊ฐ€์ž…์ด ์™„๋ฃŒ๊ฐ€ ๋˜๋ฉด ux์ ์œผ๋กœ ํŽธ๋ฆฌํ•˜๋„๋ก reset ํ•จ์ˆ˜๋ฅผ ํ™œ์šฉํ•ด ๋‹ค์‹œ Home ์˜ ์ƒํƒœ๋กœ ๋Œ์•„๊ฐ€๊ฒŒ ํ•ด์ค€๋‹ค
  5. KeyboardAwareScrollView ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋กœ ํ‚ค๋ณด๋“œ ํ™œ์„ฑ์‹œ ๋†’์ด ์ด์Šˆ ๊ฐ„๋‹จํ•˜๊ฒŒ ํ•ด๊ฒฐ