Skip to content
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

[FEAT] 메인페이지 페이징작업 #393

Merged
merged 14 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions PLUB.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
705FD29D2A14E06900F353FE /* ProofTodoAlertViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705FD29C2A14E06900F353FE /* ProofTodoAlertViewController.swift */; };
705FD2B52A1734CE00F353FE /* EditTodolistRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705FD2B42A1734CE00F353FE /* EditTodolistRequest.swift */; };
705FD2B72A17CA4700F353FE /* DeleteTodolistResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705FD2B62A17CA4700F353FE /* DeleteTodolistResponse.swift */; };
705FD2C12A1E51E800F353FE /* TodoGoalHeaderView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 705FD2C02A1E51E800F353FE /* TodoGoalHeaderView.swift */; };
706315962A0BA93400DD8EFE /* TodoPlannerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 706315952A0BA93400DD8EFE /* TodoPlannerViewModel.swift */; };
706315982A0BAA6000DD8EFE /* CreateTodoRequest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 706315972A0BAA6000DD8EFE /* CreateTodoRequest.swift */; };
7063159A2A0BAAE200DD8EFE /* CreateTodoResponse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 706315992A0BAAE200DD8EFE /* CreateTodoResponse.swift */; };
Expand Down Expand Up @@ -483,6 +484,7 @@
705FD29C2A14E06900F353FE /* ProofTodoAlertViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProofTodoAlertViewController.swift; sourceTree = "<group>"; };
705FD2B42A1734CE00F353FE /* EditTodolistRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditTodolistRequest.swift; sourceTree = "<group>"; };
705FD2B62A17CA4700F353FE /* DeleteTodolistResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeleteTodolistResponse.swift; sourceTree = "<group>"; };
705FD2C02A1E51E800F353FE /* TodoGoalHeaderView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoGoalHeaderView.swift; sourceTree = "<group>"; };
706315952A0BA93400DD8EFE /* TodoPlannerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TodoPlannerViewModel.swift; sourceTree = "<group>"; };
706315972A0BAA6000DD8EFE /* CreateTodoRequest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateTodoRequest.swift; sourceTree = "<group>"; };
706315992A0BAAE200DD8EFE /* CreateTodoResponse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CreateTodoResponse.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1085,6 +1087,7 @@
70727A1E29BF7FC6003DE956 /* BoardSystemCollectionViewCell.swift */,
70727A3229D2C635003DE956 /* TodoCollectionViewCell.swift */,
70C9CC922A01CE8B00BEB5F2 /* TodoCollectionHeaderView.swift */,
705FD2C02A1E51E800F353FE /* TodoGoalHeaderView.swift */,
);
path = Cell;
sourceTree = "<group>";
Expand Down Expand Up @@ -2627,6 +2630,7 @@
C3B3435D29BE4A3000935B73 /* MyPlubbingParameter.swift in Sources */,
C374E79729FC2F4D004738C2 /* MyTodoResponse.swift in Sources */,
BA72BCF029BB03FF007165E5 /* BaseNavigationController.swift in Sources */,
705FD2C12A1E51E800F353FE /* TodoGoalHeaderView.swift in Sources */,
70197B722953698F000503F6 /* SelectedCategoryViewController.swift in Sources */,
70727A2529C4C21A003DE956 /* CreateBoardViewModel.swift in Sources */,
BA5EC6CD29F167D7000A68B7 /* BoardDetailViewModelFactory.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ final class BoardCollectionViewCell: UICollectionViewCell {
fatalError("init(coder:) has not been implemented")
}

override func prepareForReuse() {
super.prepareForReuse()
profileImageView.image = nil
authorLabel.text = nil
dateLabel.text = nil
heartCountLabel.text = nil
commentCountLabel.text = nil
titleLabel.text = nil
contentLabel.text = nil
}

// MARK: - Configuration

private func setupLayouts() {
Expand Down
19 changes: 12 additions & 7 deletions PLUB/Sources/Views/Home/MainPage/BoardViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ final class BoardViewController: BaseViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.selectPlubbingID.onNext(plubbingID)
viewModel.clearStatus()
}

override func setupStyles() {
Expand Down Expand Up @@ -134,6 +134,17 @@ final class BoardViewController: BaseViewController {
Log.debug("해당 게시글 삭제 성공")
})
.disposed(by: disposeBag)

collectionView.rx.didScroll
.subscribe(with: self, onNext: { owner, _ in
let offSetY = owner.collectionView.contentOffset.y
let contentHeight = owner.collectionView.contentSize.height

if offSetY > (contentHeight - owner.collectionView.frame.size.height) {
owner.viewModel.fetchMoreDatas.onNext(())
}
})
.disposed(by: disposeBag)
}

@objc func handleLongPress(gestureRecognizer: UILongPressGestureRecognizer) {
Expand All @@ -156,12 +167,6 @@ final class BoardViewController: BaseViewController {

}

extension BoardViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {

}
}

extension BoardViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return 1
Expand Down
55 changes: 55 additions & 0 deletions PLUB/Sources/Views/Home/MainPage/Cell/TodoGoalHeaderView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
//
// TodoGoalHeaderView.swift
// PLUB
//
// Created by 이건준 on 2023/05/24.
//

import UIKit

import SnapKit
import Then

final class TodoGoalHeaderView: UICollectionReusableView {

static let identifier = "TodoGoalHeaderView"

private let titleLabel = UILabel().then {
$0.font = .appFont(family: .nanum, size: 32)
$0.textAlignment = .center
$0.numberOfLines = 0
}

private let goalBackgroundView = UIView().then {
$0.backgroundColor = .subMain
}

override init(frame: CGRect) {
super.init(frame: frame)
configureUI()
}

required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}

private func configureUI() {
[goalBackgroundView, titleLabel].forEach { addSubview($0) }

goalBackgroundView.snp.makeConstraints {
$0.top.equalToSuperview().inset(40)
$0.centerX.equalToSuperview()
$0.width.equalTo(187)
$0.height.equalTo(19)
}

titleLabel.snp.makeConstraints {
$0.top.equalToSuperview().inset(24)
$0.directionalHorizontalEdges.equalToSuperview()
}
}

func configureUI(with model: String) {
titleLabel.text = model
}
}
74 changes: 42 additions & 32 deletions PLUB/Sources/Views/Home/MainPage/TodolistViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import UIKit

import RxSwift
import SnapKit
import Then

Expand All @@ -25,6 +26,7 @@ final class TodolistViewController: BaseViewController {
weak var delegate: TodolistDelegate?

private let plubbingID: Int
private let goal: String

private var model: [TodolistModel] = [] {
didSet {
Expand All @@ -38,32 +40,25 @@ final class TodolistViewController: BaseViewController {
}
}

private let titleLabel = UILabel().then {
$0.font = .appFont(family: .nanum, size: 32)
$0.textAlignment = .center
$0.numberOfLines = 0
$0.sizeToFit()
}

private let goalBackgroundView = UIView().then {
$0.backgroundColor = .subMain
}

private lazy var todoCollectionView = UICollectionView(frame: .zero, collectionViewLayout: UICollectionViewFlowLayout().then {
$0.minimumLineSpacing = 8
$0.scrollDirection = .vertical
}).then {
$0.backgroundColor = .background
$0.register(TodoCollectionViewCell.self, forCellWithReuseIdentifier: TodoCollectionViewCell.identifier)
$0.register(TodoCollectionHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: TodoCollectionHeaderView.identifier)
$0.register(TodoGoalHeaderView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: TodoGoalHeaderView.identifier)
$0.delegate = self
$0.dataSource = self
$0.contentInset = UIEdgeInsets(top: .zero, left: 16, bottom: .zero, right: 16)
$0.showsVerticalScrollIndicator = false
$0.showsHorizontalScrollIndicator = false
}

init(plubbingID: Int, goal: String, viewModel: TodolistViewModelType = TodolistViewModel()) {
self.viewModel = viewModel
self.plubbingID = plubbingID
titleLabel.text = goal
self.goal = goal
super.init(nibName: nil, bundle: nil)
bind(plubbingID: plubbingID)
}
Expand All @@ -74,32 +69,19 @@ final class TodolistViewController: BaseViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.selectPlubbingID.onNext(plubbingID)
viewModel.clearStatus()
}

override func setupLayouts() {
super.setupLayouts()
[goalBackgroundView, titleLabel, todoCollectionView].forEach { view.addSubview($0) }
view.addSubview(todoCollectionView)
}

override func setupConstraints() {
super.setupConstraints()

goalBackgroundView.snp.makeConstraints {
$0.top.equalToSuperview().inset(32)
$0.centerX.equalToSuperview()
$0.width.equalTo(187)
$0.height.equalTo(19)
}

titleLabel.snp.makeConstraints {
$0.top.equalToSuperview().inset(16)
$0.directionalHorizontalEdges.equalToSuperview()
}

todoCollectionView.snp.makeConstraints {
$0.top.equalTo(titleLabel.snp.bottom)
$0.directionalHorizontalEdges.bottom.equalToSuperview()
$0.directionalEdges.equalToSuperview()
}
}

Expand All @@ -124,33 +106,58 @@ final class TodolistViewController: BaseViewController {
owner.present(alert, animated: false)
}
.disposed(by: disposeBag)

todoCollectionView.rx.didScroll
.subscribe(with: self) { owner, _ in
let offSetY = owner.todoCollectionView.contentOffset.y
let contentHeight = owner.todoCollectionView.contentSize.height

if offSetY > (contentHeight - owner.todoCollectionView.frame.size.height) {
owner.viewModel.fetchMoreDatas.onNext(())
}
}
.disposed(by: disposeBag)

}
}

extension TodolistViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func numberOfSections(in collectionView: UICollectionView) -> Int {
return model.count
return model.count + 1
}

func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if section == 0 {
return 0
}
return 1
}

func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if indexPath.section == 0 {
return UICollectionViewCell()
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: TodoCollectionViewCell.identifier, for: indexPath) as? TodoCollectionViewCell ?? TodoCollectionViewCell()
cell.configureUI(with: model[indexPath.section].cellModel)
cell.configureUI(with: model[indexPath.section - 1].cellModel)
cell.delegate = self
return cell
}

func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
if indexPath.section == 0 {
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: TodoGoalHeaderView.identifier, for: indexPath) as? TodoGoalHeaderView ?? TodoGoalHeaderView()
header.configureUI(with: goal)
return header
}
let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: TodoCollectionHeaderView.identifier, for: indexPath) as? TodoCollectionHeaderView ?? TodoCollectionHeaderView()
header.configureUI(with: model[indexPath.section].headerModel)
header.configureUI(with: model[indexPath.section - 1].headerModel)
return header
}

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize {
if section == 0 {
return CGSize(width: collectionView.frame.width, height: 85)
}
let width: CGFloat = collectionView.frame.width
let height: CGFloat = 8 + 21 + 8
return CGSize(width: width, height: height)
Expand All @@ -159,12 +166,15 @@ extension TodolistViewController: UICollectionViewDelegate, UICollectionViewData

extension TodolistViewController: UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if indexPath.section == 0 {
return .zero
}
return TodoCollectionViewCell.estimatedCommentCellSize(
CGSize(
width: view.bounds.width - 32,
height: UIView.layoutFittingCompressedSize.height
),
model: model[indexPath.section].cellModel
model: model[indexPath.section - 1].cellModel
)
}
}
Expand Down
Loading