ํ‹ฐ์Šคํ† ๋ฆฌ ๋ทฐ

Carousel Slide

 

Issue

์œ„ Carousel Slide ๊ธฐ๋Šฅ์€ ํ•ด๋‹น Main Page ๋ฟ๋งŒ ์•„๋‹ˆ๋ผ ๋‹ค๋ฅธ Page ๋‚ด์—์„œ๋„ ์“ฐ์ด๊ธฐ ๋•Œ๋ฌธ์— ๋”ฐ๋กœ ์ปดํฌ๋„ŒํŠธ๋กœ ๋ถ„๋ฆฝํ•  ํ•„์š”๊ฐ€ ์žˆ์Œ์„ ํ™•์ธํ•˜์˜€๋‹ค.

 

Carousel Slide ๊ธฐ๋Šฅ์ด ๋ฆฌ์ŠคํŠธ ํ˜•์‹์—์„œ ์ œ๋Œ€๋กœ ๋™์ž‘ํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”, ํ•ด๋‹น ๋ฆฌ์ŠคํŠธ ์š”์†Œ๋“ค์ด Wrapper์ธ Carousel Slide ํƒœ๊ทธ ๋‚ด๋ถ€๋กœ ๋“ค์–ด๊ฐ€์•ผ ํ•œ๋‹ค. 

 

Solution

์šฐ์„ ์€ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ๋ฆฌ์ŠคํŠธ ์š”์†Œ๋ฅผ ๋™์ ์œผ๋กœ ์ƒ์„ฑํ•ด ์ฃผ๋Š” MovieList ์ปดํฌ๋„ŒํŠธ๋ฅผ ๋”ฐ๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ์ฃผ์—ˆ๋‹ค.

(Feed Layout ๋˜ํ•œ ๋‚˜์ค‘์— ์žฌํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด Presentation Component๋กœ ๋”ฐ๋กœ ๋ถ„๋ฆฌํ•˜์—ฌ ์ฃผ์—ˆ๋‹ค)

render() {
    let { curFeedsType, curMovieListData } = this.state;

    if (this.isFeedsType(curFeedsType)) {
      return curMovieListData.map(({ id, movieTitle, movieTear, url }) => {
        return (
          <SoleFeedLayout
            key={id}
            movieTitle={movieTitle}
            movieTear={movieTear}
            url={url}
          />
        );
      });
    } 
    ( ... )
  }

 

๋‹ค์Œ์œผ๋ก  MovieList ์ปดํฌ๋„ŒํŠธ์—์„œ ๋žœ๋”๋ง ๋œ Feed List์— Carousel Slide ๊ธฐ๋Šฅ์„ ์ ์šฉํ•ด์ฃผ๊ธฐ ์œ„ํ•ด์„œ ๊ด€๋ จ ๋™์ž‘์„ ๋‹ด๋‹นํ•˜๋Š” ์ปดํฌ๋„ŒํŠธ๋ฅผ ์•„๋ž˜์™€ ๊ฐ™์ด ์ปดํฌ๋„ŒํŠธ๋กœ ๋”ฐ๋กœ ๋งŒ๋“ค์–ด ์ฃผ์—ˆ๋‹ค.

๊ทธ๋ฆฌ๊ณ  MovieList ์ปดํฌ๋„ŒํŠธ๋ฅผ Carousel Slide ๋‚ด๋ถ€์—์„œ ๋™์ž‘ํ•  ์ˆ˜ ์žˆ๋„๋ก this.props.children์„ ์‚ฌ์šฉํ•˜์˜€๋‹ค.

(this.props.children์€ MovieList Component๋ฅผ ๋ฐ”์ธ๋”ฉํ•˜๊ณ  ์žˆ๋‹ค)

render() {
    let { curTranslateX, curScrollLeftPos } = this.state;
    let { children } = this.props;

    return (
      <>
        <div className="feedsCarousel" onScroll={this.moveToX}> // moveToX() ๋ฉ”์„œ๋“œ๋Š” Slide Swipping์ด ๋˜๋„๋ก ๋™์ž‘ํ•œ๋‹ค.
          <ul
            className="carouselSlider"
            style={{ transform: `translateX(${curTranslateX}%)` }}
          >
            {children}
          </ul>
        </div>
       ( ... )
      </>
    );
  }

์ตœ์ข…์ ์œผ๋กœ ์ตœ์ƒ์œ„ ๋ถ€๋ชจ ์ปดํฌ๋„ŒํŠธ์—์„œ ์œ„ ๋‘ ์ปดํฌ๋„ŒํŠธ๋ฅผ importํ•˜์—ฌ ๋‹ค์Œ๊ณผ ๊ฐ™์ด ์ฝ”๋“œ๋ฅผ ์ž‘์„ฑํ•˜์—ฌ ๊ณ„์ธตํ™” ์‹œ์ผฐ๋‹ค.

render() {
    let { soleFeedsData, collectionFeedsData } = this.state;

    return (
      <article className="feeds">
        {soleFeedsData.map(({ category, movieList }, index) => {
          return (
            <section key={index} className="feedsContainer">
              <div className="feedsCategoryNameContainer">
                <p className="feedsCategoryName">{category}</p>
              </div>
              <CarouselSlide> // Carousel Slide ๊ธฐ๋Šฅ์„ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์€ list ํ˜•์‹์— ๋ชจ๋‘ ์ ์šฉํ•  ์ˆ˜ ์žˆ์Œ
                <MovieList type="movieListType" movieListData={movieList} /> // this.props.children ๋ฐ”์ธ๋”ฉ ๊ฐ€๋Šฅ
              </CarouselSlide>
            </section>
          );
        })}
        ( ... )
      </article>
    );
  }
๋Œ“๊ธ€
๊ณต์ง€์‚ฌํ•ญ
์ตœ๊ทผ์— ์˜ฌ๋ผ์˜จ ๊ธ€
์ตœ๊ทผ์— ๋‹ฌ๋ฆฐ ๋Œ“๊ธ€
Total
Today
Yesterday
๋งํฌ
TAG
more
ยซ   2024/12   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31
๊ธ€ ๋ณด๊ด€ํ•จ