Skip to content
Snippets Groups Projects
Commit b851fb01 authored by Bruno Muniz's avatar Bruno Muniz :apple:
Browse files

Finished country picker button

parent aec93b0f
No related branches found
No related tags found
2 merge requests!54Releasing 1.1.4,!50Search UI 2.0
......@@ -86,6 +86,13 @@ final class SearchLeftController: UIViewController {
.sink { [unowned self] in screenView.updateUIForItem(item: $0) }
.store(in: &cancellables)
viewModel.statePublisher
.map(\.country)
.removeDuplicates()
.receive(on: DispatchQueue.main)
.sink { [unowned self] in screenView.countryButton.setFlag($0.flag, prefix: $0.prefix) }
.store(in: &cancellables)
viewModel.statePublisher
.compactMap(\.snapshot)
.receive(on: DispatchQueue.main)
......@@ -102,6 +109,16 @@ final class SearchLeftController: UIViewController {
.sink { [unowned self] in presentSearchDisclaimer() }
.store(in: &cancellables)
screenView.countryButton
.publisher(for: .touchUpInside)
.receive(on: DispatchQueue.main)
.sink { [unowned self] in
coordinator.toCountries(from: self) { [weak self] country in
guard let self = self else { return }
self.viewModel.didPick(country: country)
}
}.store(in: &cancellables)
screenView.inputField
.textPublisher
.receive(on: DispatchQueue.main)
......
......@@ -2,6 +2,7 @@ import HUD
import UIKit
import Combine
import XXModels
import Countries
import Integration
import DependencyInjection
......@@ -10,6 +11,7 @@ typealias SearchSnapshot = NSDiffableDataSourceSnapshot<SearchSection, SearchIte
struct SearchLeftViewState {
var input = ""
var snapshot: SearchSnapshot?
var country: Country = .fromMyPhone()
var item: SearchSegmentedControl.Item = .username
}
......@@ -36,6 +38,10 @@ final class SearchLeftViewModel {
stateSubject.value.input = string
}
func didPick(country: Country) {
stateSubject.value.country = country
}
func didSelectItem(_ item: SearchSegmentedControl.Item) {
stateSubject.value.item = item
}
......@@ -45,10 +51,15 @@ final class SearchLeftViewModel {
hudSubject.send(.on(nil))
var content = stateSubject.value.input
let prefix = stateSubject.value.item.written.first!.uppercased()
if stateSubject.value.item == .phone {
content += stateSubject.value.country.code
}
do {
try session.search(fact: "\(prefix)\(stateSubject.value.input)") { [weak self] in
try session.search(fact: "\(prefix)\(content)") { [weak self] in
guard let self = self else { return }
switch $0 {
......
......@@ -17,7 +17,6 @@ final class SearchLeftView: UIView {
tableView.backgroundColor = Asset.neutralWhite.color
inputStackView.spacing = 5
countryButton.isHidden = true
inputStackView.addArrangedSubview(countryButton)
inputStackView.addArrangedSubview(inputField)
......
......@@ -2,7 +2,7 @@ import UIKit
public final class SearchCountryComponent: UIControl {
let flagLabel = UILabel()
let codeLabel = UILabel()
let prefixLabel = UILabel()
let containerView = UIView()
public init() {
......@@ -12,21 +12,28 @@ public final class SearchCountryComponent: UIControl {
containerView.backgroundColor = Asset.neutralSecondary.color
flagLabel.text = "🇺🇸"
codeLabel.text = "+1"
codeLabel.textColor = Asset.neutralDisabled.color
codeLabel.font = Fonts.Mulish.semiBold.font(size: 14.0)
prefixLabel.text = "+1"
prefixLabel.textColor = Asset.neutralDisabled.color
prefixLabel.font = Fonts.Mulish.semiBold.font(size: 14.0)
addSubview(containerView)
containerView.addSubview(flagLabel)
containerView.addSubview(codeLabel)
containerView.addSubview(prefixLabel)
containerView.isUserInteractionEnabled = false
setupConstraints()
flagLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
codeLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
prefixLabel.setContentCompressionResistancePriority(.required, for: .horizontal)
}
required init?(coder: NSCoder) { nil }
public func setFlag(_ flag: String, prefix: String) {
flagLabel.text = flag
prefixLabel.text = prefix
}
private func setupConstraints() {
containerView.snp.makeConstraints {
$0.top.equalToSuperview()
......@@ -41,7 +48,7 @@ public final class SearchCountryComponent: UIControl {
$0.centerY.equalToSuperview()
}
codeLabel.snp.makeConstraints {
prefixLabel.snp.makeConstraints {
$0.left.equalTo(flagLabel.snp.right).offset(10)
$0.right.equalToSuperview().offset(-13)
$0.centerY.equalToSuperview()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment