Skip to content

Commit

Permalink
♻️ [refactor] 수집 현황도 카탈로그를 네트워크를 통해 완전히 받기 전에는 로딩뷰를 띄우도록 개선 #17
Browse files Browse the repository at this point in the history
  • Loading branch information
leeari95 committed Jul 23, 2022
1 parent 73b74d5 commit a900b84
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@ final class CollectionProgressSectionViewModel {
struct Input {
let didTapSection: Observable<UITapGestureRecognizer>
}

struct Output {
let isLoading: Observable<Bool>
}

func bind(input: Input, disposeBag: DisposeBag) {
func transform(input: Input, disposeBag: DisposeBag) -> Output {
input.didTapSection
.subscribe(onNext: { _ in
self.coordinator?.transition(for: .progress)
}).disposed(by: disposeBag)

return Output(isLoading: Items.shared.isLoading)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ class CollectionProgressView: UIView {
return stackView
}()

private lazy var activityIndicator: LoadingView = {
let activityIndicator = LoadingView(backgroundColor: .acSecondaryBackground, alpha: 1)
return activityIndicator
}()

private func configure() {
let config = UIImage.SymbolConfiguration(scale: .small)
let image = UIImageView(image: UIImage(systemName: "chevron.forward", withConfiguration: config))
image.tintColor = .systemGray
addSubviews(backgroundStackView, image)
addSubviews(backgroundStackView, image, activityIndicator)
backgroundStackView.addArrangedSubviews(Category.progress().map { ProgressView(category: $0) })

let heightAnchor = backgroundStackView.heightAnchor.constraint(equalTo: heightAnchor)
Expand All @@ -36,18 +41,28 @@ class CollectionProgressView: UIView {
backgroundStackView.topAnchor.constraint(equalTo: topAnchor),
backgroundStackView.leadingAnchor.constraint(equalTo: leadingAnchor),
backgroundStackView.widthAnchor.constraint(equalTo: widthAnchor, constant: -25),
heightAnchor
heightAnchor,
activityIndicator.widthAnchor.constraint(equalTo: widthAnchor),
activityIndicator.topAnchor.constraint(equalTo: backgroundStackView.topAnchor),
activityIndicator.bottomAnchor.constraint(equalTo: backgroundStackView.bottomAnchor)
])
}

private func bind(to viewModel: CollectionProgressSectionViewModel) {
let tap = UITapGestureRecognizer()
addGestureRecognizer(tap)
let input = CollectionProgressSectionViewModel.Input(didTapSection: tap.rx.event.asObservable())
let output = viewModel.transform(input: input, disposeBag: disposeBag)
output.isLoading
.bind(to: self.activityIndicator.rx.isAnimating)
.disposed(by: disposeBag)
}
}

extension CollectionProgressView {
convenience init(viewModel: CollectionProgressSectionViewModel) {
self.init(frame: .zero)
let tap = UITapGestureRecognizer()
addGestureRecognizer(tap)
let input = CollectionProgressSectionViewModel.Input(didTapSection: tap.rx.event.asObservable())
viewModel.bind(input: input, disposeBag: disposeBag)
bind(to: viewModel)
configure()
}
}

0 comments on commit a900b84

Please sign in to comment.