Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

박스오피스 [Step3] 쥬봉이, 기석 #124

Open
wants to merge 88 commits into
base: ic_10_jyubong
Choose a base branch
from

Conversation

carti1108
Copy link

@stevenkim18
안녕하세요 Steven!
어쩌다보니 많이 늦어지게된 step3 pr 보냅니다!,,

고민이 되었던 점

신규, 순위 등락에 따른 조건별 문자열 표기

조건문을 통해 각각의 경우마다 다른 값이 들어가도록 만들어주었고, 순위 등락에 따른 기호와 색상은 NSMutableAttributedString을 확장하여 문자열을 반환해주는 방식을 사용하였습니다.

CollectionView를 통한 리스트 구현

content view, content configuration, custom cell을 활용하여 uicollectionviewlistcell을 커스텀하였습니다.

내용
content configuration content view custom cell
역할 -content view의 view model역할
-custom cell에 대한 content view 인스턴스 생성 담당
-content view와 custom cell을 연결하는 다리 역할
-custom cell의 레이아웃 과 모양 정의
-제공된 content configuration을 기반으로 데이터와 모양을 표시하는 역할
-cell의 상태를 기반으로 content configuration 객체를 생성한 다음 해당 configuration을 자신에게 할당
장점 단점
내용 -state에 따른 다양한 뷰의 모습을 보여줄 수 있음
-객체 간 결합도도 낮아질 수 있다고 생각
-이렇게까지 해야하나 싶을 정도로 복잡하고 번거로움
코드
MovieListCell

movie 프로퍼티를 통해 영화 정보를 받고, MovieConfiguration에 업데이트

final class MovieListCell: UICollectionViewListCell {
    var movie: DailyBoxOfficeList?
    
    override func updateConfiguration(using state: UICellConfigurationState) {
        var newConfiguration = MovieConfiguration().updated(for: state)
        newConfiguration.rank = movie?.rank
        newConfiguration.rankFluctuation = movie?.rankFluctuation
        newConfiguration.movieName = movie?.movieName
        newConfiguration.audienceCount = movie?.audienceCount
        newConfiguration.audienceAccumulation = movie?.audienceAccumulation
        
        contentConfiguration = newConfiguration
    }
}
MovieConfiguration

MovieListCell에서 update 메서드 호출시 content configuration 생성 및 cell의 contentView 생성

struct MovieConfiguration: UIContentConfiguration, Hashable {
    var rank: String?
    var rankFluctuation: String?
    var movieName: String?
    var audienceCount: String?
    var audienceAccumulation: String?
    var rankOldAndNew: RankOldAndNew?
    
    func makeContentView() -> UIView & UIContentView {
        return MovieContentView(configuration: self)
    }
    
    func updated(for state: UIConfigurationState) -> Self {
        return self
    }
}
MovieContentView

레이아웃 설정 및 configuration 업데이트

final class MovieContentView: UIView, UIContentView {
    private var rankLabel = UILabel()
    private var rankFluctuationLabel = UILabel()
    private var rankStackView = UIStackView()
    private var movieNameLabel = UILabel()
    private var audienceCountLabel = UILabel()
    private var movieStackView = UIStackView()
    private var stackView = UIStackView()
    
    var configuration: UIContentConfiguration {
        didSet {
            apply(configuration)
        }
    }
    
    init(configuration: UIContentConfiguration) {
        self.configuration = configuration
        super.init(frame: .zero)

        configureUI()
        apply(configuration)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func apply(_ configuration: UIContentConfiguration) {
        guard let configuration = configuration as? MovieConfiguration else {
            return
        }
        
        guard let audienceCount = configuration.audienceCount,
              let audienceAccumulation = configuration.audienceAccumulation,
              let rankFluctuation = configuration.rankFluctuation else {
            return
        }
        
        rankLabel.text = configuration.rank
        movieNameLabel.text = configuration.movieName
        audienceCountLabel.text = "오늘 \(audienceCount.numberFormatter()) / 총 \(audienceAccumulation.numberFormatter())"
        
        if configuration.rankOldAndNew == RankOldAndNew.new {
            rankFluctuationLabel.textColor = .systemRed
            rankFluctuationLabel.text = "신작"
        } else if rankFluctuation.hasPrefix("-") {
            rankFluctuationLabel.attributedText = NSMutableAttributedString()
                .blueColor("")
                .body(string: rankFluctuation.trimmingCharacters(in: ["-"]), fontSize: 15)
        } else if rankFluctuation == "0" {
            rankFluctuationLabel.text = rankFluctuation
        } else {
            rankFluctuationLabel.attributedText = NSMutableAttributedString()
                .redColor("")
                .body(string: rankFluctuation, fontSize: 15)
        }
    }
}

참고 링크(UICollectionViewList Custom)

조언을 구하고 싶은 부분

  • 현재 configuration을 통해 content view에 영화 정보를 전달하고 있고, content view에서 조건문을 통해 신규, 순위 등락에 따른 텍스트를 조건 별로 다르게 나오도록 해주고 있는데 이 동작을 content view에서 하는게 옳은 것인지 고민이 됩니다.
  • 혼자 진행하다보니 놓친 부분이 많을 것 같습니다.
    많은 지적 부탁드립니다.

실행화면

메인화면 새로고침
Simulator Screen Recording - iPhone 15 Pro - 2023-12-13 at 19 16 06 Simulator Screen Recording - iPhone 15 Pro - 2023-12-13 at 19 16 31

jyubong and others added 30 commits December 5, 2023 14:32
rank, rankFluctuation, movieName, audienceCount, audienceAccumulation 프로퍼티 생성
makeContentView, updated 메서드 구현
Copy link

@stevenkim18 stevenkim18 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

기석! 갑자기 혼자가 되셔서 당황스러우셨을탠데 그래도 끝까지 열심히 잘 하셨습니다!!

모던 컬렉션 뷰 같은 경우에는 저도 잘 다뤄보지 않아서 같이 미팅으로 이야기 나누면 좋을 것 같습니다.
(미리 코드를 읽어보면서 동작은 어느 정도 파악했습니다)

기본적으로 API 통신을 통해서 화면에 뿌려주는 것은 잘 구현하셨습니다.
저랑 많은 대화를 나눠보면서 코드를 고도화하고 더 잘 정리봅시다!!

고생하셨습니다!

BoxOffice/Controller/ViewController.swift Outdated Show resolved Hide resolved
BoxOffice/Controller/ViewController.swift Outdated Show resolved Hide resolved
BoxOffice/Controller/ViewController.swift Outdated Show resolved Hide resolved
BoxOffice/Controller/ViewController.swift Outdated Show resolved Hide resolved
BoxOffice/Controller/ViewController.swift Outdated Show resolved Hide resolved
BoxOffice/Controller/ViewController.swift Outdated Show resolved Hide resolved
Comment on lines 18 to 20
func makeContentView() -> UIView & UIContentView {
return MovieContentView(configuration: self)
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

외부에서 사용하는 함수인가요??

Copy link
Author

@carti1108 carti1108 Dec 14, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

접근제어수준을 정해주면 UIContentConfiguration프로토콜을 따르지 못하게되어 따로 정해주지 않았습니다.

BoxOffice/View/MovieConfiguration.swift Outdated Show resolved Hide resolved
BoxOffice/View/MovieContentView.swift Outdated Show resolved Hide resolved
@carti1108 carti1108 marked this pull request as draft December 14, 2023 06:10
@carti1108 carti1108 marked this pull request as ready for review December 14, 2023 08:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants