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

[Team-08][iOS] 숙박인원 입력 뷰 생성, 캘린더 뷰 개선 및 버그 수정 #308

Open
wants to merge 23 commits into
base: team-08
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
0f1157a
chore: 인원수 추가에 필요한 파일 추가
SangHwi-Back Jun 8, 2022
363e47f
feat: 기본 뷰 요소와 레이아웃 설정
SangHwi-Back Jun 8, 2022
a6fe439
feature: 인원수 모델 적용
SangHwi-Back Jun 9, 2022
a9a61fe
chore: 인원수 뷰들의 각 요소가 추상 타입을 참조할 수 있도록 수정합니다.
SangHwi-Back Jun 9, 2022
2c4ede5
feature: 공통 테이블 뷰 인원수 반영하는 로직 추가
SangHwi-Back Jun 9, 2022
d5b618b
feature: 화면에 인원수 모델을 적용하는 기능 추가
SangHwi-Back Jun 9, 2022
fb88667
chore: git resolve conflict
SangHwi-Back Jun 9, 2022
b3f634f
chore: git confict resolving
SangHwi-Back Jun 9, 2022
2a50967
Merge pull request #87 from ak2j38/feature-headCountView
SangHwi-Back Jun 9, 2022
afe61cd
fix: 매월 첫번 째주에 빈 cell 이 클릭 안되도록 수정
Damagucci-Juice Jun 8, 2022
35cb8f4
feat: cell 이 선택되었을때 왼쪽 배경, 오른쪽 배경을 삽입
Damagucci-Juice Jun 8, 2022
50d4c97
feat: 날짜 클릭시에 tableView에 반영
Damagucci-Juice Jun 8, 2022
307b00d
fix: 같은 날짜가 두번 탭되었을 때 checkIn, out 날을 모두 업데이트하도록 코드 수정
Damagucci-Juice Jun 8, 2022
5ae2ccd
fix: 테이블 뷰의 두번째 행에서 날짜 표시하는 형식 수정
Damagucci-Juice Jun 8, 2022
1720fa5
feat: 지우기 버튼으로 일정 정보 리셋
Damagucci-Juice Jun 9, 2022
6621be1
fix: 지우기 버튼을 눌렀을 때 다시 건너뛰기 버튼이 나오게 수정
Damagucci-Juice Jun 9, 2022
f5671f4
refactor: 사용하지 않는 코드 삭제
Damagucci-Juice Jun 9, 2022
999c2f0
feat: 검색어에 기반해서 LocationView를 업데이트
Damagucci-Juice Jun 9, 2022
f875c40
refactor: 리뷰어 피드백 반영
Damagucci-Juice Jun 9, 2022
4724462
Merge pull request #88 from ak2j38/feature-calendarVC
SangHwi-Back Jun 10, 2022
6ecd73c
fix: dateFormmater 익스텐션 선언
Damagucci-Juice Jun 10, 2022
55b2153
refactor: 폴더 구조 개편
Damagucci-Juice Jun 10, 2022
caeb239
refactor: CalendarAYearModel과 CalendarModelProtocol 을 분리
Damagucci-Juice Jun 10, 2022
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
Binary file modified iOS/.DS_Store
Binary file not shown.
Binary file modified iOS/Airbnb/.DS_Store
Binary file not shown.
164 changes: 122 additions & 42 deletions iOS/Airbnb/Airbnb.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,29 @@

import Foundation

class CalendarModel {
protocol CalenderModelProtocol {
var checkinDayIndex: IndexPath? { get set }
var checkoutDayIndex: IndexPath? { get set }
var month: [Month] { get }
var onUpdate: ([Day]) -> Void { get set }
var onUpdateBeforeDays: ([Day]) -> Void { get set }
var numberOfWeeksInBaseDate: Int { get }
func validateCheckDate(at indexPath: IndexPath)
func getLastDate(at path: IndexPath) -> Date?
func getADay(at path: IndexPath) -> Day
}

class CalendarAYearModel: CalenderModelProtocol {

var checkinDayIndex: IndexPath? {
didSet {
guard let checkinDayIndex = checkinDayIndex else { return }
guard let checkinDayIndex = checkinDayIndex else {
guard let beforeDays = beforeDays else { return }
beforeDays.forEach {
$0.fadeState = .none
}
return self.onUpdateBeforeDays(beforeDays)
}
let currentDays = getDays(fromIndex: checkinDayIndex, toIndex: checkoutDayIndex)
self.beforeDays = currentDays
}
Expand All @@ -25,7 +43,7 @@ class CalendarModel {
self.beforeDays = currentDays
}
}

private var beforeDays: [Day]? {
willSet {
guard let beforeDays = beforeDays else { return }
Expand All @@ -35,13 +53,19 @@ class CalendarModel {
beforeDays[i].fadeState = .none
}
}
else if newValue.count == 1 {
beforeDays.forEach {
$0.fadeState = .none
}
}
self.onUpdateBeforeDays(beforeDays)
}
didSet {
guard let beforeDays = beforeDays else { return }
self.onUpdate(beforeDays)
}
}


private var baseDate: Date {
didSet {
Expand All @@ -56,15 +80,11 @@ class CalendarModel {
}

var onUpdate: ([Day]) -> Void = { _ in }

var onUpdateBeforeDays: ([Day]) -> Void = { _ in }

let calendar: Calendar = Calendar.current
private let calendar: Calendar = Calendar.current

private lazy var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "d"
return dateFormatter
}()
private lazy var dateFormatter = DateFormatter.formatting(from: "d")

init(baseDate: Date) {
self.baseDate = baseDate
Expand Down Expand Up @@ -132,31 +152,7 @@ enum CalendarDateError: Error {
case monthMetadataError
}

extension CalendarModel {
func shinghaSayMakeDays(for baseDate: Date) -> [Date?] {
let component = calendar.dateComponents([.year, .month], from: baseDate)
guard let firstDate = calendar.date(from: component),
let nextMonthDate = calendar.date(byAdding: .month, value: 1, to: firstDate), // 7월 1일
let lastDate = calendar.date(byAdding: .day, value: -1, to: nextMonthDate) else {
return []
}
let startComponent = calendar.dateComponents([.day, .weekday], from: firstDate)
let lastComponent = calendar.dateComponents([.day, .weekday], from: lastDate)
guard let lastday = lastComponent.day,
let startWeekDay = startComponent.weekday,
let lastWeekDay = lastComponent.weekday else {
return []
}
var dates: [Date?] = (0..<lastday).map { addDay in
calendar.date(byAdding: .day, value: addDay, to: firstDate)
}
(0..<startWeekDay - 1).forEach { _ in dates.insert(nil, at: 0) }
(lastWeekDay - 1..<6).forEach { _ in dates.append(nil) }
return dates
}
}

extension CalendarModel {
extension CalendarAYearModel {
func validateCheckDate(at indexPath: IndexPath) {
if let checkinDayIndex = checkinDayIndex {
if checkinDayIndex <= indexPath {
Expand All @@ -176,13 +172,13 @@ extension CalendarModel {
}
}

private extension CalendarModel {
private extension CalendarAYearModel {
func getDays(fromIndex: IndexPath, toIndex: IndexPath? = nil) -> [Day] {
let indexes = generateIndexes(fromIndex: fromIndex, toIndex: toIndex)
let days = indexes.compactMap {
month[$0.section].result[$0.row]
}

return drawingDays(days: days)
}

Expand All @@ -195,7 +191,7 @@ private extension CalendarModel {
} else {
let sections = Array(fromIndex.section...toIndex.section)
var result: [IndexPath] = []

sections.enumerated().forEach { offset, value in
let numberOfDays = month[value].count
switch offset {
Expand Down Expand Up @@ -238,3 +234,23 @@ private extension CalendarModel {
}
}
}

extension CalendarAYearModel {
func getLastDate(at path: IndexPath) -> Date? {
return month[path.section].result.last?.date
}

func getADay(at path: IndexPath) -> Day {
let month = self.month[path.section].result
let day = month[path.row]
return day
}
}

extension DateFormatter {
static func formatting(from text: String) -> DateFormatter {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = text
return dateFormatter
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@ class CalendarHearderView: UICollectionReusableView {
}
}

private lazy var dateFormatter: DateFormatter = {
let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "yyyy년 M월"
return dateFormatter
}()
private lazy var dateFormatter = DateFormatter.formatting(from: "yyyy년 M월")

private let yearMonthLabel: UILabel = {
let label = UILabel()
Expand Down
87 changes: 58 additions & 29 deletions iOS/Airbnb/Airbnb/Search/Calendar/View/CalendarViewCell.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class CalendarViewCell: UICollectionViewCell {
updateSelectionStatus()
} else {
selectionBackgroundView.isHidden = true
fadeStateView.isHidden = true
leftFadeBackgroundView.isHidden = true
rightFadeBackgroundView.isHidden = true
}
}
}
Expand All @@ -33,7 +34,15 @@ class CalendarViewCell: UICollectionViewCell {
return view
}()

private var fadeStateView: UIView = {
private lazy var leftFadeBackgroundView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.clipsToBounds = true
view.backgroundColor = UIColor.getGrayScale(.Grey6)
return view
}()

private lazy var rightFadeBackgroundView: UIView = {
let view = UIView()
view.translatesAutoresizingMaskIntoConstraints = false
view.clipsToBounds = true
Expand Down Expand Up @@ -62,7 +71,8 @@ class CalendarViewCell: UICollectionViewCell {

isAccessibilityElement = true
accessibilityTraits = .button
contentView.addSubview(fadeStateView)
contentView.addSubview(leftFadeBackgroundView)
contentView.addSubview(rightFadeBackgroundView)
contentView.addSubview(selectionBackgroundView)
contentView.addSubview(numberLabel)

Expand All @@ -80,21 +90,26 @@ class CalendarViewCell: UICollectionViewCell {
let size = traitCollection.horizontalSizeClass == .compact ?
min(min(frame.width, frame.height) - 10, 60) : 45

NSLayoutConstraint.activate([
numberLabel.centerYAnchor.constraint(equalTo: centerYAnchor),
numberLabel.centerXAnchor.constraint(equalTo: centerXAnchor),

selectionBackgroundView.centerYAnchor
.constraint(equalTo: numberLabel.centerYAnchor),
selectionBackgroundView.centerXAnchor
.constraint(equalTo: numberLabel.centerXAnchor),
selectionBackgroundView.widthAnchor.constraint(equalToConstant: size),
selectionBackgroundView.heightAnchor
.constraint(equalTo: selectionBackgroundView.widthAnchor)
])
numberLabel.snp.makeConstraints {
$0.center.equalToSuperview()
}

selectionBackgroundView.snp.makeConstraints {
$0.center.equalTo(numberLabel)
$0.width.equalTo(size)
$0.height.equalTo(selectionBackgroundView.snp.width)
}

leftFadeBackgroundView.snp.makeConstraints {
$0.top.bottom.equalToSuperview().inset(3)
$0.trailing.equalToSuperview()
$0.width.equalToSuperview().dividedBy(2)
}

fadeStateView.snp.makeConstraints {
$0.edges.equalToSuperview().inset(-1)
rightFadeBackgroundView.snp.makeConstraints {
$0.top.bottom.equalToSuperview().inset(3)
$0.leading.equalToSuperview()
$0.width.equalToSuperview().dividedBy(2)
}

selectionBackgroundView.layer.cornerRadius = size / 2
Expand All @@ -105,29 +120,30 @@ class CalendarViewCell: UICollectionViewCell {
super.prepareForReuse()
numberLabel.text = nil
selectionBackgroundView.isHidden = true
fadeStateView.isHidden = true
leftFadeBackgroundView.isHidden = true
rightFadeBackgroundView.isHidden = true
}

func tabGenerated(for day: Day) {
if !day.isBeforeToday {
prepareForReuse()
self.day = day
}
guard !day.isBeforeToday else { return }
prepareForReuse()
self.day = day
}

}

// MARK: - Appearance
// TODO: - Refactorying으로 중복되는 코드를 줄일 수 있으면 줄이자.
private extension CalendarViewCell {

func updateSelectionStatus() {
guard let day = day else { return }

switch day.fadeState {
case .left:
fallthrough
applyLeftSelectedStyle()
case .right:
applySelectedStyle()
applyRightSelectedStyle()
case .fill:
applyFadeStyle()
case .none:
Expand All @@ -144,13 +160,24 @@ private extension CalendarViewCell {
return isCompact && (smallWidth || widthGreaterThanHeight)
}

private func applySelectedStyle() {
private func applyLeftSelectedStyle() {
accessibilityTraits.insert(.selected)
accessibilityHint = nil

numberLabel.textColor = isSmallScreenSize ? .systemRed : .white
selectionBackgroundView.isHidden = isSmallScreenSize
rightFadeBackgroundView.isHidden = true
leftFadeBackgroundView.isHidden = false
}

private func applyRightSelectedStyle() {
accessibilityTraits.insert(.selected)
accessibilityHint = nil

numberLabel.textColor = isSmallScreenSize ? .systemRed : .white
selectionBackgroundView.isHidden = isSmallScreenSize
fadeStateView.isHidden = true
rightFadeBackgroundView.isHidden = false
leftFadeBackgroundView.isHidden = true
}

private func applyDefaultStyle() {
Expand All @@ -160,12 +187,14 @@ private extension CalendarViewCell {

numberLabel.textColor = day.isBeforeToday ? .secondaryLabel : .label
selectionBackgroundView.isHidden = true
fadeStateView.isHidden = true
leftFadeBackgroundView.isHidden = true
rightFadeBackgroundView.isHidden = true
}

private func applyFadeStyle() {
fadeStateView.isHidden = false
numberLabel.textColor = .label
selectionBackgroundView.isHidden = true
leftFadeBackgroundView.isHidden = false
rightFadeBackgroundView.isHidden = false
}
}
Loading