Skip to content

Commit

Permalink
작업중
Browse files Browse the repository at this point in the history
  • Loading branch information
joseph704 committed Dec 27, 2024
1 parent 1c24279 commit a9eeedf
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ final class GuTableViewCell: UITableViewCell {
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
nameLabel.textColor = selected ? .textPrimary : .gray400
contentView.backgroundColor = .gray800
}

override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
Expand Down Expand Up @@ -45,13 +46,13 @@ final class GuTableViewCell: UITableViewCell {

private extension GuTableViewCell {
func configureUI() {
backgroundColor = .gray600
contentView.backgroundColor = .gray800

addSubview(nameLabel)
contentView.addSubview(nameLabel)

nameLabel.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.horizontalEdges.equalToSuperview()
$0.leading.equalToSuperview().inset(24)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ final class RegionFilteringModalViewController: UIViewController, ModalPresentab
private let viewModel: RegionFilteringModalViewModel = .init()
private var cityDataSource: UITableViewDiffableDataSource<Int, String>?
private var guDataSource: UITableViewDiffableDataSource<Int, String>?
private let cityCellClickEvent: PublishRelay<String> = .init()

let modalContainerView: UIView = {
let view: UIView = .init()
Expand Down Expand Up @@ -51,6 +52,9 @@ final class RegionFilteringModalViewController: UIViewController, ModalPresentab
tableView.rowHeight = 56
tableView.showsVerticalScrollIndicator = false

tableView.delegate = self
tableView.separatorStyle = .none

return tableView
}()

Expand All @@ -60,6 +64,8 @@ final class RegionFilteringModalViewController: UIViewController, ModalPresentab
tableView.register(GuTableViewCell.self, forCellReuseIdentifier: GuTableViewCell.identifier)
tableView.rowHeight = 56

tableView.separatorStyle = .none

return tableView
}()

Expand All @@ -86,7 +92,8 @@ final class RegionFilteringModalViewController: UIViewController, ModalPresentab
private extension RegionFilteringModalViewController {
func bindViewModel() {
let input: RegionFilteringModalViewModel.Input = .init(
viewDidLoadEvent: .just(Void())
viewDidLoadEvent: .just(Void()),
cityCellClickEvent: cityCellClickEvent.asObservable()
)

let output = viewModel.convert(input: input, disposedBag: disposeBag)
Expand Down Expand Up @@ -151,20 +158,32 @@ private extension RegionFilteringModalViewController {
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
snapshot.appendSections([0])
snapshot.appendItems(cityNames, toSection: 0)
cityDataSource?.apply(snapshot, animatingDifferences: true)
cityDataSource?.apply(snapshot, animatingDifferences: false)
}

func displayGuNames(_ cityNames: [String]) {
var snapshot = NSDiffableDataSourceSnapshot<Int, String>()
snapshot.appendSections([0])
snapshot.appendItems(cityNames, toSection: 0)
guDataSource?.apply(snapshot, animatingDifferences: true)
guDataSource?.apply(snapshot, animatingDifferences: false) {
DispatchQueue.main.async { [weak self] in
if let rowCount = self?.guTableView.numberOfRows(inSection: 0), rowCount > 0 {
self?.guTableView.selectRow(
at: IndexPath(row: 0, section: 0),
animated: true,
scrollPosition: .top
)
} else {
print("No rows available to select.")
}
}
}
}
}

// MARK: - Table View

extension RegionFilteringModalViewController {
extension RegionFilteringModalViewController: UITableViewDelegate {
private func configureDataSource() {
cityDataSource = UITableViewDiffableDataSource<Int, String>(
tableView: cityTableView,
Expand Down Expand Up @@ -192,4 +211,10 @@ extension RegionFilteringModalViewController {
}
)
}

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if let selectedCity = cityDataSource?.itemIdentifier(for: indexPath) {
cityCellClickEvent.accept(selectedCity)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ final class RegionFilteringModalViewModel: ViewModel {

struct Input {
let viewDidLoadEvent: Observable<Void>
let cityCellClickEvent: Observable<String>
}

struct Output {
Expand Down Expand Up @@ -59,6 +60,13 @@ final class RegionFilteringModalViewModel: ViewModel {
}
.disposed(by: disposedBag)

input.cityCellClickEvent
.bind(with: self) { owner, clickedCity in
guard let guNames = owner.cityAndDistricts[clickedCity] else { return }
owner.output.guNamesRelay.accept(guNames)
}
.disposed(by: disposedBag)

return output
}
}
18 changes: 17 additions & 1 deletion StreetDrop/StreetDrop/Resource/CityAndDistrictsData.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{
"name": "서울",
"districts": [
"전체",
"종로구",
"중구",
"용산구",
Expand Down Expand Up @@ -37,6 +38,7 @@
{
"name": "인천",
"districts": [
"전체",
"중구",
"중구영종출장소",
"중구용유출장소",
Expand All @@ -55,6 +57,7 @@
{
"name": "경기",
"districts": [
"전체",
"수원시",
"수원시 장안구",
"수원시 권선구",
Expand Down Expand Up @@ -105,6 +108,7 @@
{
"name": "대전",
"districts": [
"전체",
"동구",
"중구",
"서구",
Expand All @@ -114,11 +118,14 @@
},
{
"name": "세종",
"districts": []
"districts": [
"전체"
]
},
{
"name": "대구",
"districts": [
"전체",
"중구",
"동구",
"서구",
Expand All @@ -133,6 +140,7 @@
{
"name": "부산",
"districts": [
"전체",
"중구",
"서구",
"동구",
Expand All @@ -154,6 +162,7 @@
{
"name": "강원",
"districts": [
"전체",
"춘천시",
"원주시",
"강릉시",
Expand All @@ -177,6 +186,7 @@
{
"name": "광주",
"districts": [
"전체",
"동구",
"서구",
"남구",
Expand All @@ -187,6 +197,7 @@
{
"name": "울산",
"districts": [
"전체",
"중구",
"남구",
"동구",
Expand All @@ -197,6 +208,7 @@
{
"name": "경남",
"districts": [
"전체",
"창원시 의창구",
"창원시 성산구",
"창원시 마산합포구",
Expand Down Expand Up @@ -224,6 +236,7 @@
{
"name": "경북",
"districts": [
"전체",
"포항시 남구",
"포항시 북구",
"경주시",
Expand Down Expand Up @@ -252,6 +265,7 @@
{
"name": "전남",
"districts": [
"전체",
"목포시",
"여수시",
"순천시",
Expand Down Expand Up @@ -279,6 +293,7 @@
{
"name": "전북",
"districts": [
"전체",
"전주시 완산구",
"전주시 덕진구",
"군산시",
Expand All @@ -297,6 +312,7 @@
{
"name": "제주",
"districts": [
"전체",
"제주시",
"서귀포시"
]
Expand Down

0 comments on commit a9eeedf

Please sign in to comment.