-
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
[Refactor] #198 - 홈 UI 로직 변경 #204
Changes from 10 commits
99a37f7
1a72b60
a23f507
092e89e
af4c171
b06e714
03b07a4
12ef425
5bb2322
24bbb2c
beb0339
dabac04
5bc7cdb
c6f8999
084de48
ae4d34a
7c81600
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -146,22 +146,13 @@ extension DetailAchievementViewController { | |
} | ||
|
||
extension DetailAchievementViewController { | ||
func requestDetailAPI(date: String) { | ||
HomeAPI.shared.getDailyMission(date: date) { [self] result in | ||
switch result { | ||
case let .success(data): | ||
guard let data = data as? [DailyMissionResponseDTO] else { return } | ||
self.missionList = data | ||
updateData(item: missionList) | ||
case .requestErr: | ||
print("requestErr") | ||
case .pathErr: | ||
print("pathErr") | ||
case .serverErr: | ||
print("serverErr") | ||
case .networkFail: | ||
print("networkFail") | ||
} | ||
|
||
private func requestDetailAPI(date: String) { | ||
HomeAPI.shared.getDailyMission(date: date) { response in | ||
guard let response = response else { return } | ||
guard let data = response.data else { return } | ||
let missionList = data | ||
self.updateData(item: missionList) | ||
} | ||
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. escaping closure라서 weak self를 써줘야 안전하게 메모리 해제될 것 같네여~ 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. 앗 ! 이 부분도 수정하겠습니당! 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. |
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,18 +11,27 @@ | |
import Then | ||
import SnapKit | ||
|
||
protocol CalendarViewDelegate { | ||
Check failure on line 14 in iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/Calendar/CalendarView.swift GitHub Actions / SwiftLint
|
||
|
||
func todayBtnTapped() | ||
} | ||
|
||
final class CalendarView: UIView { | ||
|
||
// MARK: - Properties | ||
|
||
let today = Date() | ||
var monthCalendarClosure: ((_ month: String) -> Void)? | ||
var delegate: CalendarViewDelegate? | ||
|
||
// MARK: - UI Components | ||
|
||
let yearMonthLabel = UILabel() | ||
private let yearMonthLabel = UILabel() | ||
let todayButton = UIButton(configuration: .filled()) | ||
let horizonStackView = UIStackView() | ||
let leftButton = UIButton() | ||
let rightButton = UIButton() | ||
var calendar = WeekMonthFSCalendar() | ||
private lazy var today: Date = { return Date() }() | ||
var monthCalendarClosure: ((_ month: String) -> Void)? | ||
private let horizonStackView = UIStackView() | ||
private let leftButton = UIButton() | ||
private let rightButton = UIButton() | ||
var calendar = WeekMonthFSCalendar() | ||
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. 사소하지만 들여쓰기,,ㅎㅎ 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. 어멋 ..ㅎㅎ 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. |
||
|
||
// MARK: - Life Cycle | ||
|
||
|
@@ -43,10 +52,12 @@ | |
extension CalendarView { | ||
|
||
private func setCalendar(scope: FSCalendarScope, scrollDirection: FSCalendarScrollDirection) { | ||
|
||
calendar = WeekMonthFSCalendar(calendarScope: scope, scrollDirection: scrollDirection) | ||
} | ||
|
||
private func setUI() { | ||
|
||
backgroundColor = .ntdBlack | ||
|
||
yearMonthLabel.do { | ||
|
@@ -56,15 +67,20 @@ | |
} | ||
|
||
todayButton.do { | ||
$0.configuration?.image = .icBackToday | ||
$0.configuration?.title = I18N.todayButton | ||
$0.configuration?.imagePadding = 2 | ||
$0.configuration?.contentInsets = NSDirectionalEdgeInsets.init(top: 3, leading: 6, bottom: 2, trailing: 7) | ||
$0.configuration?.cornerStyle = .capsule | ||
$0.configuration?.attributedTitle?.font = .Pretendard(.regular, size: 14) | ||
$0.configuration?.baseBackgroundColor = .gray2 | ||
$0.configuration?.baseForegroundColor = .gray5 | ||
var config = UIButton.Configuration.filled() | ||
config.image = .icBackToday | ||
config.title = I18N.todayButton | ||
config.imagePadding = 2 | ||
config.contentInsets = NSDirectionalEdgeInsets.init(top: 3, leading: 6, bottom: 2, trailing:7) | ||
Check failure on line 74 in iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/Calendar/CalendarView.swift GitHub Actions / SwiftLint
Check warning on line 74 in iOS-NOTTODO/iOS-NOTTODO/Presentation/Common/Calendar/CalendarView.swift GitHub Actions / SwiftLint
|
||
config.cornerStyle = .capsule | ||
config.attributedTitle?.font = .Pretendard(.regular, size: 14) | ||
config.baseBackgroundColor = .gray2 | ||
config.baseForegroundColor = .gray5 | ||
|
||
$0.configuration = config | ||
$0.addTarget(self, action: #selector(todayBtnTapped), for: .touchUpInside) | ||
} | ||
|
||
horizonStackView.do { | ||
$0.axis = .horizontal | ||
$0.spacing = 16 | ||
|
@@ -79,9 +95,15 @@ | |
$0.setImage(.calendarRight, for: .normal) | ||
$0.addTarget(self, action: #selector(nextBtnTapped), for: .touchUpInside) | ||
} | ||
|
||
calendar.do { | ||
$0.collectionView.register(MissionCalendarCell.self, | ||
forCellWithReuseIdentifier: MissionCalendarCell.identifier) | ||
} | ||
} | ||
|
||
private func setLayout(scope: FSCalendarScope) { | ||
|
||
switch scope { | ||
case .week: | ||
addSubviews(calendar, yearMonthLabel, todayButton) | ||
|
@@ -102,16 +124,15 @@ | |
$0.directionalHorizontalEdges.equalToSuperview().inset(11) | ||
$0.bottom.equalToSuperview().inset(20) | ||
} | ||
|
||
case .month: | ||
addSubviews(horizonStackView, calendar) | ||
horizonStackView.addArrangedSubviews(leftButton, yearMonthLabel, rightButton) | ||
|
||
leftButton.snp.makeConstraints { | ||
$0.size.equalTo(CGSize(width: 25, height: 25)) | ||
} | ||
|
||
rightButton.snp.makeConstraints { | ||
$0.size.equalTo(CGSize(width: 25, height: 25)) | ||
[leftButton, rightButton].forEach { | ||
$0.snp.makeConstraints { | ||
$0.size.equalTo(CGSize(width: 25, height: 25)) | ||
} | ||
} | ||
|
||
horizonStackView.snp.makeConstraints { | ||
|
@@ -131,6 +152,7 @@ | |
} | ||
|
||
func scrollCurrentPage(calendar: WeekMonthFSCalendar, isPrev: Bool) { | ||
|
||
let gregorian = Calendar(identifier: .gregorian) | ||
calendar.setCurrentPage( gregorian.date(byAdding: calendar.scope == .week ? .weekOfMonth : .month, value: isPrev ? -1 : 1, to: calendar.currentPage)!, animated: true) | ||
let monthDateFormatter = DateFormatter() | ||
|
@@ -152,9 +174,41 @@ | |
scrollCurrentPage(calendar: calendar, isPrev: false) | ||
} | ||
|
||
@objc | ||
func todayBtnTapped(_sender: UIButton) { | ||
delegate?.todayBtnTapped() | ||
} | ||
|
||
} | ||
|
||
extension CalendarView { | ||
|
||
func setCalendarSelectedDate(_ dates: [Date]) { | ||
dates.forEach { | ||
calendar.select($0) | ||
} | ||
} | ||
|
||
func configure(delegate: FSCalendarDelegate, datasource: FSCalendarDataSource) { | ||
calendar.delegate = delegate | ||
calendar.dataSource = datasource | ||
} | ||
|
||
func configureYearMonth(to text: String) { | ||
yearMonthLabel.text = text | ||
} | ||
|
||
func reloadCollectionView() { | ||
calendar.collectionView.reloadData() | ||
} | ||
|
||
func updateDetailConstraints() { | ||
horizonStackView.snp.updateConstraints { | ||
$0.top.equalToSuperview().offset(54) | ||
} | ||
calendar.snp.updateConstraints { | ||
$0.bottom.equalToSuperview().inset(45) | ||
} | ||
} | ||
|
||
} |
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.
이 함수에서 completion이 escaping 클로저여서 이 함수가 끝났다는 것을 알려주는 역할을 하는데
요렇게 return 부분에 completion handler가 없으면 끝났다는걸 알릴 방법이 없어진다고 하네여!!
그래서 요 부분에도 밑에 .failure 에 completion(nil) 추가해준 것처럼 completion을 추가해주면 좋을 것 같습니다~
관련내용은 Meet async/await in Swift라는 WWDC 세션에 앞부분에 나와여! (결국 여기서 하는 말은 이거 다 개발자 책임이니까 이제 async, await를 쓰라고 하긴 함 ㅋㅋ ㅠㅠ)
밑에 제가 세션들으면서 필기한 내용 간단히 캡쳐한거 올려보겟슴다..
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.
오오 !! 감사합니다:)
return 부분에 completion은 생각을 못하고 있었던 부분인 것 같아요! ㅠㅠ
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.
beb0339