Skip to content

Commit

Permalink
REFACT :: [#326] 내 루틴 뷰 코드 정리
Browse files Browse the repository at this point in the history
  • Loading branch information
cyj513 committed May 15, 2024
1 parent 845b8b1 commit 17de4b4
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// TestViewController.swift
// SelfCareFeatureInterface
//
// Created by 조영준 on 5/13/24.
// Copyright © 2024 MaeumGaGym-iOS. All rights reserved.
//

import UIKit

public class TestViewController: UIViewController {

public override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = .blue
// Do any additional setup after loading the view.
}


/*
// MARK: - Navigation

// 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.
}
*/

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ public class SelfCareMyRoutineDetailViewController: BaseViewController<SelfCareM
$0.showsHorizontalScrollIndicator = false
$0.backgroundColor = .white
$0.separatorStyle = .none
$0.register(MyRoutineDetailTableViewCell.self,
forCellReuseIdentifier: MyRoutineDetailTableViewCell.identifier)
$0.register(
MyRoutineDetailTableViewCell.self,
forCellReuseIdentifier: MyRoutineDetailTableViewCell.identifier
)
}

private var bottomLine = MGLine(lineHeight: 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,38 +18,41 @@ import MGNetworks
import SelfCareFeatureInterface

public class SelfCareMyRoutineViewController: BaseViewController<SelfCareMyRoutineViewModel>, Stepper, UIGestureRecognizerDelegate {

private var naviBar = RoutineNavigationBarBar()

private var myRoutineModel: SelfCareMyRoutineModel = SelfCareMyRoutineModel(
titleTextData:
SelfCareMyRoutineTextModel(
titleTextData: SelfCareMyRoutineTextModel(
titleText: "",
infoText: ""),
myRoutineData: []
infoText: ""
), myRoutineData: []
)

private var containerView = UIView()
private var headerView = UIView()

private let myRoutineTitleLabel = MGLabel(font: UIFont.Pretendard.titleLarge,
textColor: .black,
isCenter: false
private let myRoutineTitleLabel = MGLabel(
font: UIFont.Pretendard.titleLarge,
textColor: .black,
isCenter: false
)

private let myRoutineSubTitleLabel = MGLabel(font: UIFont.Pretendard.bodyMedium,
textColor: DSKitAsset.Colors.gray600.color,
isCenter: false,
numberOfLineCount: 2
private let myRoutineSubTitleLabel = MGLabel(
font: UIFont.Pretendard.bodyMedium,
textColor: DSKitAsset.Colors.gray600.color,
isCenter: false,
numberOfLineCount: 2
)

private var myRoutineTableView = UITableView().then {
$0.showsVerticalScrollIndicator = false
$0.showsHorizontalScrollIndicator = false
$0.backgroundColor = .white
$0.separatorStyle = .none
$0.register(MyRoutineTableViewCell.self,
forCellReuseIdentifier: MyRoutineTableViewCell.identifier)
$0.register(
MyRoutineTableViewCell.self,
forCellReuseIdentifier: MyRoutineTableViewCell.identifier
)
}

private var plusRoutineButton = SelfCareButton(type: .plusRoutine)
Expand All @@ -76,11 +79,11 @@ public class SelfCareMyRoutineViewController: BaseViewController<SelfCareMyRouti

public override func layout() {
super.layout()

view.addSubviews([naviBar, myRoutineTableView, plusRoutineButton, headerView])

naviBar.snp.makeConstraints {
$0.leading.top.trailing.equalTo(view.safeAreaLayoutGuide)
$0.top.leading.trailing.equalTo(view.safeAreaLayoutGuide)
}

headerView = UIView(frame: CGRect(x: 0, y: 0, width: self.view.frame.width, height: 144.0))
Expand All @@ -97,14 +100,11 @@ public class SelfCareMyRoutineViewController: BaseViewController<SelfCareMyRouti

myRoutineTitleLabel.snp.makeConstraints {
$0.top.leading.equalToSuperview()
$0.width.equalToSuperview()
$0.height.equalTo(48.0)
}

myRoutineSubTitleLabel.snp.makeConstraints {
$0.leading.bottom.equalToSuperview()
$0.width.equalToSuperview()
$0.height.equalTo(40.0)
$0.top.equalTo(myRoutineTitleLabel.snp.bottom).offset(12.0)
$0.leading.equalToSuperview()
}

myRoutineTableView.tableHeaderView = headerView
Expand All @@ -115,12 +115,22 @@ public class SelfCareMyRoutineViewController: BaseViewController<SelfCareMyRouti
}

plusRoutineButton.snp.makeConstraints {
$0.bottom.equalToSuperview().offset(-54.0)
$0.leading.trailing.equalToSuperview().inset(20.0)
$0.bottom.equalToSuperview().inset(54.0)
$0.height.equalTo(58.0)
}
}

public override func bindActions() {
plusRoutineButton.rx.tap
.bind(onNext: { [weak self] in
let useCase = DefaultSelfCareUseCase(repository: SelfCareRepository(networkService: SelfCareService()))

let viewModel = SelfCareMyRoutineEditViewModel(useCase: useCase)
let vc = SelfCareMyRoutineEditViewController(viewModel)
self?.navigationController?.pushViewController(vc, animated: true)
}).disposed(by: disposeBag)
}
public override func bindViewModel() {
let useCase = DefaultSelfCareUseCase(repository: SelfCareRepository(networkService: SelfCareService()))

Expand Down Expand Up @@ -148,6 +158,7 @@ extension SelfCareMyRoutineViewController: UITableViewDelegate {
}
}
}

extension SelfCareMyRoutineViewController: UITableViewDataSource {
public func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
myRoutineModel.myRoutineData.count + 1
Expand All @@ -165,6 +176,27 @@ extension SelfCareMyRoutineViewController: UITableViewDataSource {
let routine = myRoutineModel.myRoutineData[indexPath.row]
cell?.setup(with: routine)
cell?.selectionStyle = .none
cell?.dotsButtonTap
.bind(onNext: { [weak self] in
let modal = TestViewController()

if #available(iOS 16.0, *) {
let customDetent = UISheetPresentationController.Detent.custom(identifier: .init("custom")) { _ in
return 257
}
if let sheet = modal.sheetPresentationController {
sheet.detents = [customDetent]
sheet.prefersGrabberVisible = true
}
} else {
if let sheet = modal.sheetPresentationController {
sheet.detents = [.medium()]
sheet.prefersGrabberVisible = true
}
}
self?.present(modal, animated: true)
}).disposed(by: disposeBag)

return cell ?? UITableViewCell()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ import UIKit
import SnapKit
import Then

import RxSwift
import RxCocoa

import Core
import DSKit
import Domain
Expand All @@ -11,6 +14,10 @@ import MGNetworks

public class MyRoutineTableViewCell: BaseTableViewCell {

public var dotsButtonTap: ControlEvent<Void> {
return dotsButton.rx.tap
}

static let identifier: String = "MyRoutineTableViewCell"

private var containerView = UIView().then {
Expand Down Expand Up @@ -43,6 +50,11 @@ public class MyRoutineTableViewCell: BaseTableViewCell {
changeSharingState(state: model.sharingState)
}

public override func prepareForReuse() {
super.prepareForReuse()
self.disposeBag = DisposeBag()
}

override public func layout() {
super.layout()

Expand Down

0 comments on commit 17de4b4

Please sign in to comment.