Skip to content

Commit

Permalink
Merge pull request #23 from boostcampwm-2022/feature/BrowseView
Browse files Browse the repository at this point in the history
BrowseView 구성
  • Loading branch information
jinwoong16 committed Nov 17, 2022
2 parents 6526158 + f9e049e commit c302b7e
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 24 deletions.
12 changes: 12 additions & 0 deletions DailyQuest/DailyQuest.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
34A529E429248178001BAD34 /* SettingsSceneDIContainer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A529E329248178001BAD34 /* SettingsSceneDIContainer.swift */; };
34A529E7292481E1001BAD34 /* BrowseCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A529E6292481E1001BAD34 /* BrowseCoordinator.swift */; };
34A529E929248B58001BAD34 /* AppAppearance.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A529E829248B58001BAD34 /* AppAppearance.swift */; };
34A529EB2924B077001BAD34 /* UserInfoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34A529EA2924B077001BAD34 /* UserInfoView.swift */; };
34ACC32D291DE9C000741371 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34ACC32C291DE9C000741371 /* AppDelegate.swift */; };
34ACC32F291DE9C000741371 /* SceneDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 34ACC32E291DE9C000741371 /* SceneDelegate.swift */; };
34ACC336291DE9C100741371 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 34ACC335291DE9C100741371 /* Assets.xcassets */; };
Expand Down Expand Up @@ -103,6 +104,7 @@
34A529E329248178001BAD34 /* SettingsSceneDIContainer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsSceneDIContainer.swift; sourceTree = "<group>"; };
34A529E6292481E1001BAD34 /* BrowseCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BrowseCoordinator.swift; sourceTree = "<group>"; };
34A529E829248B58001BAD34 /* AppAppearance.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppAppearance.swift; sourceTree = "<group>"; };
34A529EA2924B077001BAD34 /* UserInfoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserInfoView.swift; sourceTree = "<group>"; };
34ACC329291DE9C000741371 /* DailyQuest.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DailyQuest.app; sourceTree = BUILT_PRODUCTS_DIR; };
34ACC32C291DE9C000741371 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
34ACC32E291DE9C000741371 /* SceneDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SceneDelegate.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -240,6 +242,7 @@
3499551A292332B2007AB99E /* Browse */ = {
isa = PBXGroup;
children = (
34EE6EB12924B3CF005AF583 /* View */,
3499552429235034007AB99E /* ViewController */,
349955252923503C007AB99E /* ViewModel */,
34A529E5292481C9001BAD34 /* Flow */,
Expand Down Expand Up @@ -418,6 +421,14 @@
path = Data;
sourceTree = "<group>";
};
34EE6EB12924B3CF005AF583 /* View */ = {
isa = PBXGroup;
children = (
34A529EA2924B077001BAD34 /* UserInfoView.swift */,
);
path = View;
sourceTree = "<group>";
};
A51189C029226DF7008A9D33 /* RealmStorage */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -717,6 +728,7 @@
A5AC96D929223648003B7637 /* RealmStorage.swift in Sources */,
A51189C329226E66008A9D33 /* UserQuestEntity+Mapping.swift in Sources */,
A51F01D3292340360031ECA2 /* BrowseQuestsStorage.swift in Sources */,
34A529EB2924B077001BAD34 /* UserInfoView.swift in Sources */,
A51F01CA2923397E0031ECA2 /* UserInfoEntity.swift in Sources */,
A51F01D8292343A80031ECA2 /* RealmBrowseQuestsStorage.swift in Sources */,
A51F01DD2923468F0031ECA2 /* BrowseQuestEntity+Mapping.swift in Sources */,
Expand Down
2 changes: 2 additions & 0 deletions DailyQuest/DailyQuest/Application/AppAppearance.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ final class AppAppearance {
static func setupAppearance() {
UITabBar.appearance().backgroundColor = .white
UITabBar.appearance().tintColor = .maxYellow
UITableViewCell.appearance().selectionStyle = .none
UITableView.appearance().separatorStyle = .none
}
}
63 changes: 63 additions & 0 deletions DailyQuest/DailyQuest/Presentation/Browse/View/UserInfoView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// UserInfoView.swift
// DailyQuest
//
// Created by jinwoong Kim on 2022/11/16.
//

import UIKit

import SnapKit

final class UserInfoView: UIStackView {

// MARK: - Components
private lazy var userImage: UIImageView = {
let userImage = UIImageView()
userImage.image = UIImage(systemName: "heart.fill")
userImage.clipsToBounds = true
userImage.backgroundColor = .white

return userImage
}()

private lazy var welcomeLabel: UILabel = {
let welcomeLabel = UILabel()

return welcomeLabel
}()

// MARK: - Methods
convenience init() {
self.init(frame: .zero)

axis = .horizontal
alignment = .center
spacing = 10
isLayoutMarginsRelativeArrangement = true
layoutMargins = UIEdgeInsets(top: 0, left: 10, bottom: 0, right: 10)

configureUI()
}

override func layoutSubviews() {
super.layoutSubviews()
userImage.layer.cornerRadius = userImage.frame.height / 2
}

private func configureUI() {
addArrangedSubview(userImage)
addArrangedSubview(welcomeLabel)

userImage.snp.makeConstraints { make in
make.height.equalToSuperview().offset(-40)
make.width.equalTo(userImage.snp.height)
}
}

func setup(with user: User) {
welcomeLabel.text = user.nickName + "님의 퀘스트"
guard let image = UIImage(data: user.profile) else { return }
userImage.image = image
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@ final class BrowseViewController: UITableViewController {
table view의 기본 정보를 설정합니다.
*/
private func configure() {
// 셀 사이사이의 구분선을 제거합니다.
tableView.separatorStyle = .none

tableView.allowsSelection = false

// 델리게이트와 데이터소스를 rx로 재설정합니다.
tableView.delegate = nil
tableView.dataSource = nil
Expand All @@ -53,6 +48,12 @@ final class BrowseViewController: UITableViewController {
cell.setup(with: BrowseItemViewModel(user: item.0, quests: item.1))
}
.disposed(by: disposableBag)

tableView.rx.itemSelected
.subscribe(onNext: { indexPath in
print(self.viewModel.users[indexPath.row])
})
.disposed(by: disposableBag)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,24 @@ final class BrowseViewModel {
Quest(uuid: UUID(), title: "잠자기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 1, totalCount: 1)
]

let user3 = User(uuid: UUID(), nickName: "Max...", profile: Data(), backgroundImage: Data(), description: "")
let quests3 = [
Quest(uuid: UUID(), title: "물마시기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 4, totalCount: 5),
Quest(uuid: UUID(), title: "그림 그리기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 1, totalCount: 2),
Quest(uuid: UUID(), title: "달리기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 4, totalCount: 9),
Quest(uuid: UUID(), title: "책읽기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 1, totalCount: 1),
Quest(uuid: UUID(), title: "잠자기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 1, totalCount: 1),
Quest(uuid: UUID(), title: "행복하기", startDay: Date(), endDay: Date(), repeat: 1, currentCount: 0, totalCount: 1)
]

let data: Observable<[(User, [Quest])]>
private(set) var users: [User] = []

let cellCount = [2, 4]
let cellCount = [2, 4, 6]

init() {
self.data = .just([(user1, quests1), (user2, quests2)])
self.data = .just([(user1, quests1), (user2, quests2), (user3, quests3)])
self.users.append(contentsOf: [user1, user2, user3])
}
}

Expand Down
21 changes: 4 additions & 17 deletions DailyQuest/DailyQuest/Presentation/Common/Cells/BrowseCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,13 @@ final class BrowseCell: UITableViewCell {
/**
아직 사용되고 있는 view는 아닙니다.
*/
private lazy var header: UILabel = {
let header = UILabel()
header.text = "test"

return header
private lazy var header: UserInfoView = {
return UserInfoView()
}()

private lazy var questTableView: UITableView = {
let questTableView = UITableView()
questTableView.backgroundColor = .maxLightGrey
questTableView.separatorStyle = .none

return questTableView
}()
Expand All @@ -50,15 +46,6 @@ final class BrowseCell: UITableViewCell {
configureUI()
}

/**
Browse Cell 내부의 테이블뷰의 모든 방향에 패딩을 추가합니다.
*/
override func layoutSubviews() {
super.layoutSubviews()

questTableView.frame = questTableView.frame.inset(by: UIEdgeInsets(top: 10, left: 10, bottom: 10, right: 10))
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
Expand All @@ -67,7 +54,7 @@ final class BrowseCell: UITableViewCell {
addSubview(questTableView)

questTableView.snp.makeConstraints { make in
make.edges.equalToSuperview()
make.edges.equalToSuperview().inset(10)
}
}

Expand All @@ -79,6 +66,7 @@ final class BrowseCell: UITableViewCell {
*/
func setup(with viewModel: BrowseItemViewModel) {
self.viewModel = viewModel
header.setup(with: viewModel.user)

questTableView.reloadData()
}
Expand Down Expand Up @@ -113,7 +101,6 @@ extension BrowseCell: UITableViewDataSource {
assertionFailure("Cannot deque reuseable cell.")
return UITableViewCell()
}

cell.setup(with: viewModel.quests[indexPath.row])

return cell
Expand Down

0 comments on commit c302b7e

Please sign in to comment.