Skip to content

Commit

Permalink
✨ Feat: #4 - touchArea의 style을 외부에서도 조절 가능하게...
Browse files Browse the repository at this point in the history
  • Loading branch information
usa4060 committed Oct 28, 2023
1 parent 4c187af commit 132d109
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions DesignSystem/Sources/CMCTouchArea.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<TouchAreaStyle>(value: .normal)
private var image: [Int:UIImage] = [:]

/// 터치 영역의 `image`를 설정합니다.
Expand Down Expand Up @@ -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)
}
Expand All @@ -85,6 +92,10 @@ public final class CMCTouchArea: UIView{
}
}

public func makeCustomState(type: TouchAreaStyle) {
style.accept(type)
}

}

// MARK: - CMCTouchArea+RxSwift
Expand Down

0 comments on commit 132d109

Please sign in to comment.