From 132d109cd769aca11d9207aff973a351aa0acb8a Mon Sep 17 00:00:00 2001 From: "ir.__.si" Date: Sat, 28 Oct 2023 20:20:29 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Feat:=20#4=20-=20touchArea=EC=9D=98?= =?UTF-8?q?=20style=EC=9D=84=20=EC=99=B8=EB=B6=80=EC=97=90=EC=84=9C?= =?UTF-8?q?=EB=8F=84=20=EC=A1=B0=EC=A0=88=20=EA=B0=80=EB=8A=A5=ED=95=98?= =?UTF-8?q?=EA=B2=8C...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DesignSystem/Sources/CMCTouchArea.swift | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/DesignSystem/Sources/CMCTouchArea.swift b/DesignSystem/Sources/CMCTouchArea.swift index b4a9247..7e41155 100644 --- a/DesignSystem/Sources/CMCTouchArea.swift +++ b/DesignSystem/Sources/CMCTouchArea.swift @@ -24,14 +24,14 @@ public final class CMCTouchArea: UIView{ // MARK: - UI private lazy var imageView: UIImageView = { let imageView = UIImageView() - imageView.image = image[style.rawValue] + imageView.image = image[style.value.rawValue] return imageView }() // MARK: - Properties private var disposeBag = DisposeBag() - private var style: TouchAreaStyle = .normal + private var style = BehaviorRelay(value: .normal) private var image: [Int:UIImage] = [:] /// 터치 영역의 `image`를 설정합니다. @@ -70,11 +70,18 @@ public final class CMCTouchArea: UIView{ } private func bind() { + + self.style + .withUnretained(self) + .subscribe(onNext: { owner, style in + owner.imageView.image = owner.image[style.rawValue] + }) + .disposed(by: disposeBag) + self.rx.tapped() .withUnretained(self) .subscribe(onNext: { owner, _ in - owner.style = owner.style == .normal ? .selected : .normal - owner.imageView.image = owner.image[owner.style.rawValue] + owner.style.accept(owner.style.value == .normal ? .selected : .normal) }) .disposed(by: disposeBag) } @@ -85,6 +92,10 @@ public final class CMCTouchArea: UIView{ } } + public func makeCustomState(type: TouchAreaStyle) { + style.accept(type) + } + } // MARK: - CMCTouchArea+RxSwift