diff --git a/Sources/Extension/UIDropDownButton.swift b/Sources/Extension/UIDropDownButton.swift index a6f6dee..f014973 100644 --- a/Sources/Extension/UIDropDownButton.swift +++ b/Sources/Extension/UIDropDownButton.swift @@ -53,7 +53,7 @@ class UIDropDownButton: UIButton { } // Private Method - private func setDropDownButton() { + func setDropDownButton() { self.contentHorizontalAlignment = UIControl.ContentHorizontalAlignment.right self.contentMode = .right self.setTitle("\(SortMethod.allCasesStr()[0]) ▾", for: .normal) diff --git a/Sources/View/Product/ProductListViewController.swift b/Sources/View/Product/ProductListViewController.swift index 0eadf5a..1c3e410 100644 --- a/Sources/View/Product/ProductListViewController.swift +++ b/Sources/View/Product/ProductListViewController.swift @@ -7,26 +7,122 @@ // import UIKit +import Pageboy +import Tabman +import SnapKit +import DropDown +import RxSwift +import Then -class ProductListViewController: UIViewController { +class ProductListViewController: TabmanViewController { + let disposeBag = DisposeBag() + + lazy var button = UIDropDownButton().then { + $0.setAction().subscribe(onNext: { + switch $0 { + case .popularity: break + // 인기순 정렬 코드 + case .suggestion: break + // 추천순 정렬 코드 + case .lowestPrice: break + // 최저가순 정렬 코드 + } + }) + .disposed(by: disposeBag) + } + + lazy var barButtonItem = UIBarButtonItem(customView: button) + + private var viewControllers: Array = [] private let viewModel = ProductListViewModel() override func viewDidLoad() { super.viewDidLoad() + setNavigationBar() + setViewControllers() + view.backgroundColor = R.color.background() + } - // Do any additional setup after loading the view. + override func viewWillAppear(_ animated: Bool) { + setNavigationBar() } - - /* - // MARK: - Navigation + private func setNavigationBar() { + navigationItem.title = "제품" + navigationItem.rightBarButtonItem = barButtonItem + let searchBar = UISearchBar() + searchBar.placeholder = "검색" + navigationItem.titleView = searchBar + navigationItem.hidesSearchBarWhenScrolling = true + navigationController?.navigationBar.isTranslucent = false + navigationController?.navigationBar.isTranslucent = true + } + + private func setViewControllers() { + let storeMainVC = StoreMainViewController(index: 0) + let GS25VC = StoreMainViewController(index: 1) + let CUVC = StoreMainViewController(index: 2) + let miniStopVC = StoreMainViewController(index: 3) + let sevenElevenVC = StoreMainViewController(index: 4) + let emartVC = StoreMainViewController(index: 5) + + [storeMainVC, GS25VC, CUVC, miniStopVC, sevenElevenVC, emartVC].forEach({ viewControllers.append($0) }) + + self.dataSource = self + + let bar = TMBar.ButtonBar() + bar.layout.transitionStyle = .snap + bar.backgroundView.style = .clear + bar.layout.contentMode = .fit + bar.layout.alignment = .centerDistributed + bar.indicator.overscrollBehavior = .bounce + bar.buttons.customize { (button) in + button.font = .systemFont(ofSize: 12) + } - // In a storyboard-based application, you will often want to do a little preparation before navigation - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - // Get the new view controller using segue.destination. - // Pass the selected object to the new view controller. + addBar(bar, dataSource: self, at: .top) } - */ +} + +extension ProductListViewController: PageboyViewControllerDataSource, TMBarDataSource { + func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int { + viewControllers.count + } + + func viewController(for pageboyViewController: PageboyViewController, + at index: PageboyViewController.PageIndex) -> UIViewController? { + return viewControllers[index] + } + + func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? { + return nil + } + + func barItem(for bar: TMBar, at index: Int) -> TMBarItemable { + switch index { + case 0: + let item = TMBarItem(title: "전체") + return item + case 1: + let item = TMBarItem(title: "GS25") + return item + case 2: + let item = TMBarItem(title: "CU") + return item + case 3: + let item = TMBarItem(title: "MINI\nSTOP") + return item + case 4: + let item = TMBarItem(title: "SEVEN\nELEVEN") + return item + case 5: + let item = TMBarItem(title: "EMART") + return item + default: + let item = TMBarItem(title: "") + return item + } + } } diff --git a/Sources/View/Product/StoreMainViewController.swift b/Sources/View/Product/StoreMainViewController.swift new file mode 100644 index 0000000..ed58d1b --- /dev/null +++ b/Sources/View/Product/StoreMainViewController.swift @@ -0,0 +1,52 @@ +// +// StoreMainViewController.swift +// SSGP +// +// Created by 장서영 on 2021/11/18. +// Copyright © 2021 com.ssgp. All rights reserved. +// + +import UIKit +import SnapKit +import Then +import RxSwift +import Moya + +class StoreMainViewController: UIViewController, UIScrollViewDelegate { + + let disposeBag = DisposeBag() + + let provider = MoyaProvider() + + let productModel = [ProductList]() + + let tableView = UITableView().then { + $0.register(ProductTableViewCell.self, forCellReuseIdentifier: "productCell") + $0.backgroundColor = R.color.background() + } + + override func viewDidLoad() { + super.viewDidLoad() + setUpSubViews() + tableView.rx + .setDelegate(self) + .disposed(by: disposeBag) + } + + private func setUpSubViews() { + view.addSubview(tableView) + tableView.snp.makeConstraints { + $0.top.equalTo(view.safeAreaLayoutGuide) + $0.width.equalTo(375) + $0.bottom.equalToSuperview() + } + } + + init(index: Int) { + super.init(nibName: nil, bundle: nil) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/Sources/View/Reuseable/ProductTableViewCell.swift b/Sources/View/Reuseable/ProductTableViewCell.swift index 8dc82d2..9666583 100644 --- a/Sources/View/Reuseable/ProductTableViewCell.swift +++ b/Sources/View/Reuseable/ProductTableViewCell.swift @@ -72,13 +72,11 @@ class ProductTableViewCell: UITableViewCell { // MARK: - public method - public func bind() { - // 후에 파라미터로 데이터 받아서 바인딩 - - // demo data - self.titleLabel.text = "돼지바" - self.priceLabel.text = "₩2500" - self.likeCounterLabel.text = "13" + public func bind(title: String, price: String, likeCount: String, store: [String]) { + + self.titleLabel.text = title + self.priceLabel.text = "₩\(price)" + self.likeCounterLabel.text = likeCount self.setStoreList([.cu, .gs25, .emart24]) self.fireButton.rx.tap diff --git a/Sources/View/TabBarController.swift b/Sources/View/TabBarController.swift index def6d21..f006a42 100644 --- a/Sources/View/TabBarController.swift +++ b/Sources/View/TabBarController.swift @@ -32,11 +32,14 @@ class TabBarController: UITabBarController, UITabBarControllerDelegate { let productListViewController = UINavigationController().then { let rootViewController = ProductListViewController() $0.setViewControllers([rootViewController], animated: true) + //$0.navigationBar.prefersLargeTitles = true + $0.navigationItem.largeTitleDisplayMode = .never $0.tabBarItem.setTabBarItem(title: "제품", image: R.image.tabBarMenuIcon()!) } let myPageViewController = UINavigationController().then { let rootViewController = MyPageViewController() $0.setViewControllers([rootViewController], animated: true) + $0.navigationBar.prefersLargeTitles = true $0.tabBarItem.setTabBarItem(title: "마이페이지", image: R.image.tabBarPersonIcon()!) }