-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(DesignSystem): Add a NofficeList component
- Loading branch information
Showing
5 changed files
with
255 additions
and
14 deletions.
There are no files selected for viewing
152 changes: 152 additions & 0 deletions
152
Projects/UI/DesignSystemUIModule/DesignSystem/Sources/Noffice/NofficeList.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
// | ||
// NofficeList.swift | ||
// DesignSystem | ||
// | ||
// Created by DOYEON LEE on 7/16/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import Assets | ||
|
||
import RxSwift | ||
import RxCocoa | ||
import SnapKit | ||
import Then | ||
|
||
public class NofficeList: UIControl { | ||
// MARK: Event | ||
public var _onTap: PublishSubject<Void> = PublishSubject() | ||
public var onTap: Observable<Void> { | ||
return _onTap.asObservable() | ||
} | ||
|
||
// MARK: Data source | ||
public var text: String = "" { | ||
didSet { | ||
label.text = text | ||
} | ||
} | ||
|
||
public var status: NofficeList.Status = .unselected { | ||
didSet { | ||
updateByStatus() | ||
} | ||
} | ||
|
||
// MARK: UI Component | ||
private lazy var backgroundView = UIView().then { | ||
$0.layer.cornerRadius = RoundedOffset.medium.same | ||
$0.clipsToBounds = true | ||
$0.isUserInteractionEnabled = false | ||
} | ||
|
||
private lazy var stackView = UIStackView(arrangedSubviews: [label, icon]).then { | ||
$0.axis = .horizontal | ||
$0.spacing = 8 | ||
$0.alignment = .center | ||
} | ||
|
||
private lazy var label = UILabel().then { | ||
$0.text = "" | ||
$0.setTypo(.body2b) | ||
$0.textColor = .blue500 | ||
$0.numberOfLines = 10 | ||
} | ||
|
||
private lazy var icon = UIImageView(image: .iconCheck).then { | ||
$0.tintColor = .grey300 | ||
$0.setSize(width: 16, height: 16) | ||
} | ||
|
||
// MARK: Initializer | ||
public init() { | ||
super.init(frame: .zero) | ||
|
||
setupHierarchy() | ||
setupLayout() | ||
setupBind() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
super.init(coder: coder) | ||
|
||
setupHierarchy() | ||
setupLayout() | ||
setupBind() | ||
} | ||
|
||
// MARK: Public | ||
public func stateToggle() { | ||
status = status == .selected ? .unselected : .selected | ||
} | ||
|
||
// MARK: Setup | ||
private func setupHierarchy() { | ||
addSubview(backgroundView) | ||
backgroundView.addSubview(stackView) | ||
} | ||
|
||
private func setupLayout() { | ||
backgroundView.snp.makeConstraints { | ||
$0.edges.equalToSuperview() | ||
} | ||
|
||
stackView.snp.makeConstraints { | ||
$0.top.bottom.equalToSuperview().inset(Self.verticalPadding) | ||
$0.leading.trailing.equalToSuperview().inset(Self.horizontalPadding) | ||
} | ||
} | ||
|
||
private func setupBind() { } | ||
|
||
// MARK: Update | ||
private func updateByStatus() { | ||
switch status { | ||
case .selected: | ||
UIView.transition( | ||
with: self, | ||
duration: 0.2, | ||
options: [.transitionCrossDissolve] | ||
) { [weak self] in | ||
guard let self = self else { return } | ||
|
||
self.backgroundView.backgroundColor = .green100 | ||
self.label.textColor = .green500 | ||
self.icon.tintColor = .green500 | ||
} | ||
case .unselected: | ||
self.icon.isHidden = false | ||
UIView.transition( | ||
with: self, | ||
duration: 0.2, | ||
options: [.transitionCrossDissolve] | ||
) { [weak self] in | ||
guard let self = self else { return } | ||
|
||
self.backgroundView.backgroundColor = .grey100 | ||
self.label.textColor = .grey400 | ||
self.icon.tintColor = .grey400 | ||
} | ||
} | ||
} | ||
|
||
// MARK: UIControl | ||
public override func endTracking(_ touch: UITouch?, with event: UIEvent?) { | ||
_onTap.onNext(()) | ||
sendActions(for: .touchUpInside) | ||
} | ||
} | ||
|
||
// MARK: - Display model | ||
public extension NofficeList { | ||
enum Status: String, CaseIterable { | ||
case unselected, selected | ||
} | ||
} | ||
|
||
// MARK: - Constant | ||
private extension NofficeList { | ||
static let verticalPadding = 12 | ||
static let horizontalPadding = 16 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...gnSystemUIModule/DesignSystemApp/Sources/Card/Noffice/NofficeListBookViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
// | ||
// NofficeListBookViewController.swift | ||
// DesignSystem | ||
// | ||
// Created by DOYEON LEE on 7/16/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import DesignSystem | ||
|
||
import RxSwift | ||
import SnapKit | ||
import Then | ||
|
||
class NofficeListBookViewController: UIViewController { | ||
// MARK: UI Components | ||
private lazy var scrollView = UIScrollView() | ||
|
||
private lazy var contentView = UIView() | ||
|
||
private lazy var stackView = UIStackView().then { | ||
$0.axis = .vertical | ||
$0.spacing = 16 | ||
$0.alignment = .fill | ||
$0.distribution = .fill | ||
} | ||
|
||
private lazy var stateSegmentedControl = UISegmentedControl( | ||
items: Array(NofficeList.Status.allCases).map { $0.rawValue } | ||
).then { | ||
$0.selectedSegmentIndex = 0 | ||
} | ||
|
||
private let listView = NofficeList().then { | ||
$0.text = "팀원 리스트 제출" | ||
} | ||
|
||
// MARK: DisposeBag | ||
private let disposeBag = DisposeBag() | ||
|
||
// MARK: Life Cycle | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = .white | ||
|
||
setupHierarchy() | ||
setupLayout() | ||
setupBind() | ||
} | ||
|
||
// MARK: Setup | ||
private func setupHierarchy() { | ||
view.addSubview(scrollView) | ||
scrollView.addSubview(contentView) | ||
contentView.addSubview(stackView) | ||
|
||
stackView.addArrangedSubview(stateSegmentedControl) | ||
|
||
stackView.addArrangedSubview(listView) | ||
} | ||
|
||
private func setupLayout() { | ||
scrollView.snp.makeConstraints { make in | ||
make.edges.equalToSuperview() | ||
} | ||
|
||
contentView.snp.makeConstraints { make in | ||
make.edges.equalToSuperview() | ||
make.width.equalTo(scrollView) | ||
} | ||
|
||
stackView.snp.makeConstraints { make in | ||
make.edges.equalToSuperview().inset(16) | ||
} | ||
} | ||
|
||
private func setupBind() { | ||
stateSegmentedControl.rx.selectedSegmentIndex | ||
.map { NofficeList.Status.allCases[$0] } | ||
.subscribe(onNext: { [weak self] state in | ||
self?.listView.status = state | ||
}) | ||
.disposed(by: disposeBag) | ||
|
||
listView.onTap | ||
.subscribe(onNext: { [weak self] _ in | ||
self?.listView.stateToggle() | ||
}) | ||
.disposed(by: disposeBag) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters