diff --git a/Projects/Features/Falling/Src/Subviews/Cell/FallingUserCollectionViewCell.swift b/Projects/Features/Falling/Src/Subviews/Cell/FallingUserCollectionViewCell.swift index 6bfc80a7..6a08f73f 100644 --- a/Projects/Features/Falling/Src/Subviews/Cell/FallingUserCollectionViewCell.swift +++ b/Projects/Features/Falling/Src/Subviews/Cell/FallingUserCollectionViewCell.swift @@ -16,8 +16,7 @@ struct FallingUserCollectionViewCellObserver { var timerActiveTrigger: Observable } -final class FallingUserCollectionViewCell: TFBaseCollectionViewCell { - +final class FallingUserCollectionViewCell: UserCardViewCollectionViewCell { lazy var profileCarouselView = ProfileCarouselView() lazy var cardTimeView = CardTimeView() @@ -36,6 +35,8 @@ final class FallingUserCollectionViewCell: TFBaseCollectionViewCell { $0.top.leading.trailing.equalToSuperview().inset(12) $0.height.equalTo(32) } + + self.showUserCardDimView() } override func prepareForReuse() { @@ -52,18 +53,20 @@ final class FallingUserCollectionViewCell: TFBaseCollectionViewCell { let output = viewModel .transform(input: input) + + output.user + .drive(with: self, onNext: { owner, user in + owner.profileCarouselView.bind(user) + }) + .disposed(by: disposeBag) output.timeState .drive(self.rx.timeState) .disposed(by: self.disposeBag) - output.isDimViewHidden - .drive(with: self, onNext: { owner, isHidden in - if isHidden { - owner.profileCarouselView.hiddenDimView() - } else { - owner.profileCarouselView.showDimView() - } + output.timeStart + .drive(with: self, onNext: { owner, _ in + owner.hiddenUserCardDimView() }) .disposed(by: disposeBag) @@ -71,12 +74,6 @@ final class FallingUserCollectionViewCell: TFBaseCollectionViewCell { .drive(scrollToNextObserver) .disposed(by: disposeBag) - output.user - .drive(with: self, onNext: { owner, user in - owner.profileCarouselView.bind(user) - }) - .disposed(by: disposeBag) - profileCarouselView.infoButton.rx.tap.asDriver() .scan(true) { lastValue, _ in return !lastValue diff --git a/Projects/Features/Falling/Src/Subviews/Cell/FallinguserCollectionViewCellModel.swift b/Projects/Features/Falling/Src/Subviews/Cell/FallinguserCollectionViewCellModel.swift index 061a8b56..1f751a6f 100644 --- a/Projects/Features/Falling/Src/Subviews/Cell/FallinguserCollectionViewCellModel.swift +++ b/Projects/Features/Falling/Src/Subviews/Cell/FallinguserCollectionViewCellModel.swift @@ -128,10 +128,10 @@ final class FallinguserCollectionViewCellModel: ViewModelType { } struct Output { + let user: Driver let timeState: Driver + let timeStart: Driver let timeZero: Driver - let user: Driver - let isDimViewHidden: Driver } func transform(input: Input) -> Output { @@ -162,18 +162,14 @@ final class FallinguserCollectionViewCellModel: ViewModelType { }.asDriver(onErrorJustReturn: 8.0) let timeState = timer.map { TimeState(rawValue: $0) } + let timeStart = timer.filter { $0 == 8.0 }.map { _ in } let timeZero = timer.filter { $0 == 0 }.map { _ in } - let isDimViewHidden = Driver.merge( - timerActiveTrigger.take(1).asDriverOnErrorJustEmpty(), // take(1)을 해주지 않으면 일시정지 때마다 dimmed 됨 - timeZero.map { _ in false } - ) - return Output( - timeState: timeState, - timeZero: timeZero, user: user, - isDimViewHidden: isDimViewHidden + timeState: timeState, + timeStart: timeStart, + timeZero: timeZero ) } } diff --git a/Projects/Modules/DesignSystem/Src/BaseView/UserCardViewCollectionViewCell.swift b/Projects/Modules/DesignSystem/Src/BaseView/UserCardViewCollectionViewCell.swift new file mode 100644 index 00000000..d09ca25a --- /dev/null +++ b/Projects/Modules/DesignSystem/Src/BaseView/UserCardViewCollectionViewCell.swift @@ -0,0 +1,48 @@ +// +// UserCardViewCollectionViewCell.swift +// DSKit +// +// Created by SeungMin on 1/31/24. +// + +import UIKit + +open class UserCardViewCollectionViewCell: TFBaseCollectionViewCell { + private let userCardDimView: UIView = { + let userCardWidth = (UIWindow.keyWindow?.bounds.width ?? .zero) - 32 + let view = UIView( + frame: CGRect( + x: 0, + y: 0, + width: userCardWidth, + height: userCardWidth * 1.64 + ) + ) + view.layer.cornerRadius = 20 + return view + }() + + public func showUserCardDimView() { + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + self.addSubviews(userCardDimView) + print("DimView added!") + UIView.animate(withDuration: 0.0) { + self.userCardDimView.backgroundColor = DSKitAsset.Color.DimColor.default.color + } + } + } + + public func hiddenUserCardDimView() { + DispatchQueue.main.async { [weak self] in + guard let self = self else { return } + UIView.animate(withDuration: 0.0) { + self.userCardDimView.backgroundColor = DSKitAsset.Color.clear.color + } completion: { [weak self] _ in + guard let self = self else { return } + print("Removed DimView!") + self.userCardDimView.removeFromSuperview() + } + } + } +}