From a900b8412413a4a05d87c4bc454a7d2f9d4406cc Mon Sep 17 00:00:00 2001 From: Ari Date: Sun, 24 Jul 2022 00:55:08 +0900 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20[refactor]=20=EC=88=98?= =?UTF-8?q?=EC=A7=91=20=ED=98=84=ED=99=A9=EB=8F=84=20=EC=B9=B4=ED=83=88?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EB=A5=BC=20=EB=84=A4=ED=8A=B8=EC=9B=8C?= =?UTF-8?q?=ED=81=AC=EB=A5=BC=20=ED=86=B5=ED=95=B4=20=EC=99=84=EC=A0=84?= =?UTF-8?q?=ED=9E=88=20=EB=B0=9B=EA=B8=B0=20=EC=A0=84=EC=97=90=EB=8A=94=20?= =?UTF-8?q?=EB=A1=9C=EB=94=A9=EB=B7=B0=EB=A5=BC=20=EB=9D=84=EC=9A=B0?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EA=B0=9C=EC=84=A0=20#17?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CollectionProgressSectionViewModel.swift | 8 +++++- .../Views/CollectionProgressView.swift | 27 ++++++++++++++----- 2 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/ViewModels/CollectionProgressSectionViewModel.swift b/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/ViewModels/CollectionProgressSectionViewModel.swift index cc097aa8..ac421dc1 100644 --- a/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/ViewModels/CollectionProgressSectionViewModel.swift +++ b/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/ViewModels/CollectionProgressSectionViewModel.swift @@ -18,11 +18,17 @@ final class CollectionProgressSectionViewModel { struct Input { let didTapSection: Observable } + + struct Output { + let isLoading: Observable + } - 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) } } diff --git a/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/Views/CollectionProgressView.swift b/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/Views/CollectionProgressView.swift index 2f252aab..9fb01bec 100644 --- a/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/Views/CollectionProgressView.swift +++ b/Animal-Crossing-Wiki/Animal-Crossing-Wiki/Dashboard/Views/CollectionProgressView.swift @@ -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) @@ -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() } }