-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Browse cell 일부 구현 #15
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0187223
[feat] #10 - CustomProgressBar를 추가하였습니다.
jinwoong16 807f0b4
[feat] close #10 - QuestCell을 재구성
jinwoong16 cc45533
close #10 - 주석을 추가와 이슈 종료
jinwoong16 3a695b1
[style] Quest Cell Constraints 수정
jinwoong16 9b06b05
[style] QuestCell inset 변경
jinwoong16 e5ca6bd
[feat] BrowseCell 정의
jinwoong16 41ca5a6
[feat] 가짜 데이터를 생성하는 viewmodel 작성
jinwoong16 6d332d1
[feat] BrowseViewController 작성
jinwoong16 895b3ff
[fix] Quest의 개수만큼 row의 개수가 처리되게 변경
jinwoong16 437c10d
[style] 가짜데이터 추가
jinwoong16 240e9ac
[fix] BrowseCell의 크기가 해당 위치의 퀘스트개수와 마진크기(20)를 포함하는 크기를 가지게 변경
jinwoong16 22d7ece
[refactor] view did load 메서드 내부에 위치한 tableView를 설정하는 코드를 분리
jinwoong16 30219bd
[feat] header를 추가
jinwoong16 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
DailyQuest/DailyQuest/Presentation/Browse/View/BrowseViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// | ||
// BrowseViewController.swift | ||
// DailyQuest | ||
// | ||
// Created by jinwoong Kim on 2022/11/15. | ||
// | ||
|
||
import UIKit | ||
|
||
import RxSwift | ||
import RxCocoa | ||
|
||
final class BrowseViewController: UITableViewController { | ||
private var viewModel: BrowseViewModel! | ||
private var disposableBag = DisposeBag() | ||
|
||
// MARK: - Life Cycle | ||
static func create(with viewModel: BrowseViewModel) -> BrowseViewController { | ||
let view = BrowseViewController() | ||
view.viewModel = viewModel | ||
return view | ||
} | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
configure() | ||
bind() | ||
} | ||
|
||
/** | ||
table view의 기본 정보를 설정합니다. | ||
*/ | ||
private func configure() { | ||
// 셀 사이사이의 구분선을 제거합니다. | ||
tableView.separatorStyle = .none | ||
|
||
tableView.allowsSelection = false | ||
|
||
// 델리게이트와 데이터소스를 rx로 재설정합니다. | ||
tableView.delegate = nil | ||
tableView.dataSource = nil | ||
tableView.rx.setDelegate(self).disposed(by: disposableBag) | ||
|
||
// BrowseCell을 등록합니다. | ||
tableView.register(BrowseCell.self, forCellReuseIdentifier: BrowseCell.reuseIdentifier) | ||
} | ||
|
||
private func bind() { | ||
viewModel | ||
.data | ||
.bind(to: tableView.rx.items(cellIdentifier: BrowseCell.reuseIdentifier, cellType: BrowseCell.self)) { row, item, cell in | ||
cell.setup(with: BrowseItemViewModel(user: item.0, quests: item.1)) | ||
} | ||
.disposed(by: disposableBag) | ||
} | ||
} | ||
|
||
extension BrowseViewController { | ||
/** | ||
하나의 BrowseCell의 크기를 결정합니다. BrowseCell내의 QuestCell의 개수만큼 크기가 늘어납니다. | ||
+20은 margins으로 인해 추가된 값입니다. | ||
*/ | ||
override func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
return (75.0 * CGFloat(viewModel.cellCount[indexPath.row])) + 20 + 75 | ||
} | ||
|
||
/** | ||
viewModel에서 총 몇개의 BrowseCell을 만들어야하는지 결정합니다. | ||
viewModel에는 UseCase를 통해 들어온 (User, [Quest]) 데이터에서 퀘스트의 **길이** 정보를 담는 프로퍼티(정ㅅ배열)가 있어야 합니다. | ||
Note. 여기에서는 Quest 정보 자체가 필요하진 않습니다. 해당 배열의 아이템들은 위에서 사용할, BrowseCell의 크기를 결정하고, | ||
배열 자체의 길이는 이 메서드의 결과를 결정합니다. | ||
*/ | ||
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
return viewModel.cellCount.count | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
DailyQuest/DailyQuest/Presentation/Browse/ViewModel/BrowseItemViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// | ||
// BrowseCellItemModel.swift | ||
// DailyQuest | ||
// | ||
// Created by jinwoong Kim on 2022/11/15. | ||
// | ||
|
||
import Foundation | ||
|
||
final class BrowseItemViewModel { | ||
let user: User | ||
let quests: [Quest] | ||
|
||
init(user: User, quests: [Quest]) { | ||
self.user = user | ||
self.quests = quests | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
DailyQuest/DailyQuest/Presentation/Browse/ViewModel/BrowseViewModel.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// | ||
// BrowseViewModel.swift | ||
// DailyQuest | ||
// | ||
// Created by jinwoong Kim on 2022/11/15. | ||
// | ||
|
||
import Foundation | ||
|
||
import RxSwift | ||
|
||
final class BrowseViewModel { | ||
let user1 = User(uuid: UUID(), nickName: "jinwoong", profile: Data(), backgroundImage: Data(), description: "") | ||
let quests1 = [ | ||
Quest(title: "물마시기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 2, totalCount: 5), | ||
Quest(title: "코딩하기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 0, totalCount: 10) | ||
] | ||
|
||
let user2 = User(uuid: UUID(), nickName: "someone", profile: Data(), backgroundImage: Data(), description: "") | ||
let quests2 = [ | ||
Quest(title: "물마시기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 4, totalCount: 5), | ||
Quest(title: "책읽기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 9, totalCount: 20), | ||
Quest(title: "달리기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 4, totalCount: 9), | ||
Quest(title: "잠자기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 1, totalCount: 1) | ||
] | ||
|
||
let data: Observable<[(User, [Quest])]> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. typealias BrowseItem = (user:User, quests: [Quest]) 이런 식으로 각각 명칭을 지정해주면 사용할 때 조금 더 명확하게 사용할 수 있을 것 같습니다! |
||
|
||
let cellCount = [2, 4] | ||
|
||
init() { | ||
self.data = .just([(user1, quests1), (user2, quests2)]) | ||
} | ||
} | ||
|
||
/** | ||
Usecase | ||
- fetching quests, it contains user and his quests. | ||
*/ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이 부분은 임시로 넣어놓은 부분일거라 생각이 되는데 나중에 코디네이터 구성이 완료되면 변경하면 될 것 같습니다!