Skip to content

Commit

Permalink
Merge branch 'feature/22_productListUI' into feature/90_ProductList_V…
Browse files Browse the repository at this point in the history
…iewModel
  • Loading branch information
jangseoyoung committed Nov 30, 2021
2 parents 710f8c3 + c8b3bb9 commit 29c808b
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Sources/Extension/UIDropDownButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
116 changes: 106 additions & 10 deletions Sources/View/Product/ProductListViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<UIViewController> = []

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
}
}
}
52 changes: 52 additions & 0 deletions Sources/View/Product/StoreMainViewController.swift
Original file line number Diff line number Diff line change
@@ -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<SSGPAPI>()

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")
}
}
12 changes: 5 additions & 7 deletions Sources/View/Reuseable/ProductTableViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions Sources/View/TabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()!)
}

Expand Down

0 comments on commit 29c808b

Please sign in to comment.