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

๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ - Movies app : Native Stack & Bottom tabs ์ ์šฉํ•˜์—ฌ UI ๋งŒ๋“ค๊ธฐ ๋ณธ๋ฌธ

React-Navtive

๋ฆฌ์•กํŠธ ๋„ค์ดํ‹ฐ๋ธŒ - Movies app : Native Stack & Bottom tabs ์ ์šฉํ•˜์—ฌ UI ๋งŒ๋“ค๊ธฐ

hyo.loui 2023. 1. 4. 16:58

๐ŸŽฏ๋ชฉ์  :

1. React-navigation ์ ์šฉ UI ๋งŒ๋“ค๊ธฐ

  • Native-Stack
  • Bottom-tabs

2. StyleSheet.absoluteFill

3. Swiper ์ ์šฉ

 

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

  • UI ๋ถ€๋ถ„์ด๋ผ ์˜ค๋ฅ˜๊ฐ€ ๋”ฑํžˆ ์—†์—ˆ๋‹ค๊ณ  ํ•œ๋‹ค..

 


1. User Interface ๋งŒ๋“ค๊ธฐ   /   horizontal : ์‚ฌ์ด๋“œ(๊ฐ€๋กœ) ์Šคํฌ๋กค

 

์šฐ์„  UI๋Š” ๋น ๋ฅด๊ฒŒ ์ž‘์—…์„ ํ•ด ๋‘๊ณ ,

๋ฆฌํŒฉํ† ๋ง์„ ํ•˜๊ณ  ๋‚˜์„œ ์Šคํƒ€์ผ์„ ์ ์šฉํ•˜๊ฒ ๋‹ค!

 

Emotion – @emotion/native

 

Emotion – @emotion/native

Style and render React Native components using emotion This package also depends on react, react-native and prop-types so make sure you've them installed. Use @emotion/react for theming support.

emotion.sh

์œ„ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ†ตํ•ด styled.component ์Šคํƒ€์ผ์„ ์ ์šฉํ•  ์˜ˆ์ •์ด๋ผ ๋ฏธ๋ฆฌ install์„ ํ–ˆ๋‹ค

 

web์—์„œ๋Š” ๊ฐ€๋กœ ์Šคํฌ๋กค์„ ์ƒ๋‹นํžˆ ์–ด๋ ต๊ฒŒ ๋งŒ๋“ค์—ˆ๋˜ ๊ธฐ์–ต์ด ์žˆ์—ˆ๋Š”๋ฐ..

RN์—์„œ๋Š” ์•„์ฃผ ์‹ฌํ”Œํ•˜๊ฒŒ <ScrollView/> ํƒœ๊ทธ์—

horizontal ์ด๋ผ๋Š” ์†์„ฑ์„ true๋กœ ํ• ๋‹นํ•˜๋ฉด

์˜์ƒ์ฒ˜๋Ÿผ ์‚ฌ์ด๋“œ ์Šคํฌ๋กค์ด ๊ฐ€๋Šฅํ•˜๋‹ค

 

์„ธ๋กœ ์Šคํฌ๋กค์€ RN์˜ ๊ธฐ๋ณธ๊ฐ’์œผ๋กœ

ํƒœ๊ทธ๋งˆ๋‹ค

  • display: flex
  • flex-direction : column

์œ„ ์Šคํƒ€์ผ์ด ๊ธฐ๋ณธ๊ฐ’์ด๋ฏ€๋กœ <ScrollView/> ํƒœ๊ทธ ๋‚ด์—์„œ๋Š” ์ž๋™์ ์œผ๋กœ ์„ธ๋กœ๋กœ ์Šคํฌ๋กค์ด ๋œ๋‹ค!

 


2. StyleSheet.absoluteFill (RN absolute , ์—˜๋ฆฌ๋จผํŠธ ๋˜๋Š” ํƒœ๊ทธ ๊ฒน์น˜๊ธฐ)

StyleSheet๋Š” RN์— ์žˆ๋Š” ๊ธฐ๋ณธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ด์ง€๋งŒ

๊ธฐ์กด์—๋Š” const ๋ณ€์ˆ˜๋ช… = StyleSheet.create`~css style~`;

์ด๋Ÿฐ ์‹์œผ๋กœ ์ž์ฃผ ์ผ์ง€๋งŒ StyleSheet์—์„œ ์ œ๊ณตํ•˜๋Š” absoluteFill ์ด๋ผ๋Š” ์†์„ฑ์„ ์ด์šฉํ•˜๋ฉด

 

๋ฒˆ๊ฑฐ๋กญ๊ฒŒ ํฌ์ง€์…˜์„ ํ•˜๋‚˜ํ•˜๋‚˜ ์ง€์ •ํ•ด ์ฃผ์ง€ ์•Š๊ณ ๋„ ์œ„ ํ™”๋ฉด๊ณผ ๊ฐ™์ด ๋ฐ”๋กœ ๊ฒน์น˜๊ฒŒ ์ ์šฉ ํ• ์ˆ˜ ์žˆ๋‹ค

์œ„์—์„œ๋Š” LinearGradient ๋ผ๋Š” ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ 

๊ทธ๋ผ๋ฐ์ด์…˜ ํšจ๊ณผ๋ฅผ ๋„ฃ๊ณ , color: "white" ์ ์šฉํ–ˆ๋‹ค

 

 


3. Swiper ์ ์šฉํ•˜๊ธฐ

https://github.com/leecade/react-native-swiper.

 

GitHub - leecade/react-native-swiper: The best Swiper component for React Native.

The best Swiper component for React Native. Contribute to leecade/react-native-swiper development by creating an account on GitHub.

github.com

์œ„ Read.me ๋ฅผ ์ฝ๊ณ  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ค์น˜ํ–ˆ๋‹ค,

 

์ ์šฉ์€ ์•„์ฃผ ๊ฐ„๋‹จํ•˜๋‹ค
๋˜‘๊ฐ™์ด Read.me ์— ์ž‘์„ฑ๋˜์–ด์žˆ๋Š” import ๊ตฌ๋ฌธ์„ ๊ฐ€์ ธ์˜ค๊ณ ,

์›ํ•˜๋Š” ํƒœ๊ทธ์˜ ์ƒ์œ„์— <Swiper> ํƒœ๊ทธ๋งŒ ์”Œ์›Œ์ฃผ๋ฉด ๋œ๋‹ค

autoplay : ์ž๋™ ์Šฌ๋ผ์ด๋“œ ํšจ๊ณผ
loop : ๋งˆ์ง€๋ง‰ ํŽ˜์ด์ง€ >> ์ฒซํŽ˜์ด์ง€ ( ๋ฌดํ•œ๋ฐ˜๋ณต )
showPagination : ํŽ˜์ด์ง€๋„ค์ด์…˜(ํŒŒ๋ž€์ƒ‰ ํŽ˜์ด์ง€๋ฒ„ํŠผ)

 

์—ฌ๊ธฐ์„œ Swiper์— ๋“ค์–ด๊ฐ€๋Š” width์™€ height๊ฐ’์ด flex 1 ๋กœ ๋“ค์–ด๊ฐ€๊ฒŒ๋˜์–ด์„œ

์˜๋„์น˜ ์•Š๊ฒŒ, ์•„๋ž˜๋กœ ์ญ‰ ์ „์ฒดํ™”๋ฉด์ด ๋˜์—ˆ๋‹ค...

๊ณต์‹ ๋ฌธ์„œ ๋‚ด์šฉ

๊ทธ๋ž˜์„œ Swiper์—๋Š” height๋ฅผ 100%๋กœ ์ฃผ๊ณ ,

์ž์‹ ํƒœ๊ทธ์— height๋ฅผ ๋”ฐ๋กœ ์ž‘์„ฑํ•ด์ค˜์•ผํ•œ๋‹ค!

 

์กฐ๊ธˆ ๋ฒˆ๊ฑฐ๋กญ์ง€๋งŒ ์ด๊ฒŒ ๊ธฐ๋ณธ๊ฐ’์ด๋‹ˆ react-native-swiper๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด ์–ด์ฉ” ์ˆ˜ ์—†๋Š” ๋ถ€๋ถ„์ด๋‹ค.

 


4. ์ ์šฉ UI

 


 ์ตœ์ข… ์ •๋ฆฌ 

  1. <ScrollView> ํƒœ๊ทธ์— horizontal={true} ์ ์šฉ ์‹œ, ๊ฐ€๋กœ(์‚ฌ์ด๋“œ) ์Šคํฌ๋กค ์ ์šฉ
  2. StyleSheet์—์„œ ์ œ๊ณตํ•˜๋Š” absoluteFill ์ด๋ผ๋Š” ์†์„ฑ์œผ๋กœ ๊ฐ„ํŽธํ•˜๊ฒŒ ์—˜๋ฆฌ๋จผํŠธ ๊ฒน์น˜๊ธฐ ๊ฐ€๋Šฅ
  3.  Swiper์— ๋“ค์–ด๊ฐ€๋Š” width์™€ height๊ฐ’์ด flex 1์ด ๊ธฐ๋ณธ๊ฐ’ ์ด๋ฏ€๋กœ, ๋”ฐ๋กœ ์‚ฌ์ด์ฆˆ ์ง€์ • ํ•„์š”