-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
π :: [#215] κΈ°λ₯ μλ 리νν λ§
리ν
- Loading branch information
Showing
1 changed file
with
56 additions
and
37 deletions.
There are no files selected for viewing
93 changes: 56 additions & 37 deletions
93
Projects/Modules/DSKit/Sources/Components/MaeumGaGymVIew/MG+SearchView.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 |
---|---|---|
@@ -1,68 +1,87 @@ | ||
import UIKit | ||
|
||
import RxCocoa | ||
import RxSwift | ||
|
||
import SnapKit | ||
import Then | ||
|
||
open class MGSearchView: UIView { | ||
import Core | ||
|
||
open class MGSearchView: BaseView { | ||
|
||
private var searchImage = UIImageView().then { | ||
$0.contentMode = .scaleAspectFit | ||
$0.image = DSKitAsset.Assets.searchActIcon.image | ||
$0.image = DSKitAsset.Assets.blackSearchActIcon.image | ||
} | ||
|
||
private let searchTextField = MGSearchTextField() | ||
|
||
private var cancelImage = UIImageView().then { | ||
$0.contentMode = .scaleAspectFit | ||
$0.image = DSKitAsset.Assets.blackCancel.image | ||
|
||
public let searchTextField = UITextField().then { | ||
$0.tintColor = DSKitAsset.Colors.gray300.color | ||
$0.placeholder = "μμΈ κ²μ" | ||
} | ||
|
||
private var cancelButton = UIButton().then { | ||
$0.setImage(DSKitAsset.Assets.blackCancel.image, for: .normal) | ||
$0.isHidden = true | ||
} | ||
public init (backgroundColor: UIColor) { | ||
|
||
public init () { | ||
super.init(frame: .zero) | ||
|
||
self.backgroundColor = backgroundColor | ||
self.layer.cornerRadius = 8.0 | ||
|
||
if (backgroundColor == DSKitAsset.Colors.gray800.color ) { | ||
searchImage.image = DSKitAsset.Assets.searchActIcon.image | ||
cancelImage.image = DSKitAsset.Assets.searchActIcon.image | ||
} | ||
self.searchTextField.placeholder = "μμΈ κ²μ" | ||
|
||
setupUI() | ||
bind() | ||
} | ||
|
||
required public init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
public func hideCancelButton() { | ||
self.cancelImage.isHidden = true | ||
} | ||
|
||
public func showCancelButton() { | ||
self.cancelImage.isHidden = true | ||
|
||
public override func attribute() { | ||
super.attribute() | ||
|
||
self.backgroundColor = DSKitAsset.Colors.gray50.color | ||
self.layer.cornerRadius = 8.0 | ||
} | ||
private func setupUI() { | ||
self.addSubviews([searchImage, searchTextField, cancelImage]) | ||
|
||
public override func layout() { | ||
addSubviews([searchImage, searchTextField, cancelButton]) | ||
|
||
searchImage.snp.makeConstraints { | ||
$0.leading.equalToSuperview().offset(12.0) | ||
$0.top.bottom.equalToSuperview().inset(8.0) | ||
$0.width.height.equalTo(24.0) | ||
} | ||
|
||
searchTextField.snp.makeConstraints { | ||
$0.top.bottom.equalToSuperview().inset(10.0) | ||
$0.leading.equalTo(searchImage.snp.trailing).offset(8.0) | ||
$0.trailing.equalTo(cancelImage.snp.leading).offset(-8.0) | ||
$0.trailing.equalTo(cancelButton.snp.leading).offset(-8.0) | ||
$0.height.equalTo(40.0) | ||
} | ||
cancelImage.snp.makeConstraints { | ||
|
||
cancelButton.snp.makeConstraints { | ||
$0.trailing.equalToSuperview().offset(-12.0) | ||
$0.top.bottom.equalToSuperview().inset(8.0) | ||
$0.width.height.equalTo(24.0) | ||
} | ||
} | ||
|
||
private func bind() { | ||
searchTextField.rx.text.orEmpty | ||
.map { $0.isEmpty } | ||
.bind(to: cancelButton.rx.isHidden) | ||
.disposed(by: disposeBag) | ||
|
||
cancelButton.rx.tap.subscribe(onNext: { [weak self] in | ||
self?.searchTextField.text = "" | ||
}).disposed(by: disposeBag) | ||
} | ||
} | ||
|
||
public extension MGSearchView { | ||
func hideCancelButton() { | ||
self.cancelButton.isHidden = true | ||
} | ||
|
||
func showCancelButton() { | ||
self.cancelButton.isHidden = true | ||
} | ||
} |