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

[Redesign] TodayVC #105

Open
wants to merge 4 commits into
base: Redesign/100-NavBar
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 7 additions & 7 deletions HRHN.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
/* Begin PBXBuildFile section */
500CA076299740260012779B /* CustomHeightTabBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 500CA075299740260012779B /* CustomHeightTabBar.swift */; };
500CA071299697320012779B /* CustomNavBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = 500CA070299697320012779B /* CustomNavBar.swift */; };
500CA07329973A8F0012779B /* Assets.swift in Sources */ = {isa = PBXBuildFile; fileRef = 500CA07229973A8F0012779B /* Assets.swift */; };
505B95352959926A005F00C8 /* ReviewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505B95342959926A005F00C8 /* ReviewViewController.swift */; };
505B953829599976005F00C8 /* UIViewController+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505B953729599976005F00C8 /* UIViewController+.swift */; };
505B953B29599A24005F00C8 /* ReviewView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 505B953A29599A24005F00C8 /* ReviewView.swift */; };
507089B0295ABC2B00DD8D85 /* Color+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507089AF295ABC2B00DD8D85 /* Color+.swift */; };
507089B2295ADE1A00DD8D85 /* View+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507089B1295ADE1A00DD8D85 /* View+.swift */; };
507089B4295AE9D600DD8D85 /* ReviewViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507089B3295AE9D600DD8D85 /* ReviewViewModel.swift */; };
507305F229965AAB00A20CA1 /* TabIcons.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507305F129965AAB00A20CA1 /* TabIcons.swift */; };
507305F42996652500A20CA1 /* UINavigationBar+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 507305F32996652500A20CA1 /* UINavigationBar+.swift */; };
5080B2ED29601A2A005115AA /* DateComponents+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5080B2EC29601A2A005115AA /* DateComponents+.swift */; };
5080B2EE29601A3D005115AA /* DateComponents+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5080B2EC29601A2A005115AA /* DateComponents+.swift */; };
Expand Down Expand Up @@ -133,13 +133,13 @@
/* Begin PBXFileReference section */
500CA075299740260012779B /* CustomHeightTabBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomHeightTabBar.swift; sourceTree = "<group>"; };
500CA070299697320012779B /* CustomNavBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomNavBar.swift; sourceTree = "<group>"; };
500CA07229973A8F0012779B /* Assets.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Assets.swift; sourceTree = "<group>"; };
505B95342959926A005F00C8 /* ReviewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewViewController.swift; sourceTree = "<group>"; };
505B953729599976005F00C8 /* UIViewController+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIViewController+.swift"; sourceTree = "<group>"; };
505B953A29599A24005F00C8 /* ReviewView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewView.swift; sourceTree = "<group>"; };
507089AF295ABC2B00DD8D85 /* Color+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Color+.swift"; sourceTree = "<group>"; };
507089B1295ADE1A00DD8D85 /* View+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "View+.swift"; sourceTree = "<group>"; };
507089B3295AE9D600DD8D85 /* ReviewViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewViewModel.swift; sourceTree = "<group>"; };
507305F129965AAB00A20CA1 /* TabIcons.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TabIcons.swift; sourceTree = "<group>"; };
507305F32996652500A20CA1 /* UINavigationBar+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UINavigationBar+.swift"; sourceTree = "<group>"; };
5080B2EC29601A2A005115AA /* DateComponents+.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "DateComponents+.swift"; sourceTree = "<group>"; };
50A5000B295D8B8300710B5D /* HRHN.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = HRHN.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -271,18 +271,18 @@
507305EF29965A8100A20CA1 /* Design */ = {
isa = PBXGroup;
children = (
507305F029965A9900A20CA1 /* TabIcons */,
507305F029965A9900A20CA1 /* Assets */,
50DBEA0B2952EB3B00ED00FD /* Color */,
);
path = Design;
sourceTree = "<group>";
};
507305F029965A9900A20CA1 /* TabIcons */ = {
507305F029965A9900A20CA1 /* Assets */ = {
isa = PBXGroup;
children = (
507305F129965AAB00A20CA1 /* TabIcons.swift */,
500CA07229973A8F0012779B /* Assets.swift */,
);
path = TabIcons;
path = Assets;
sourceTree = "<group>";
};
50A5FFF1295D784A00710B5D /* Frameworks */ = {
Expand Down Expand Up @@ -800,7 +800,6 @@
505B953829599976005F00C8 /* UIViewController+.swift in Sources */,
A79121792955FBCE0044E652 /* CustomColor.swift in Sources */,
A791210C294B190E0044E652 /* TodayViewController.swift in Sources */,
507305F229965AAB00A20CA1 /* TabIcons.swift in Sources */,
A7ED3EF6295C284200342CC8 /* SettingViewController.swift in Sources */,
A79121272950D12A0044E652 /* TabBarController.swift in Sources */,
A7ED3F07295E053600342CC8 /* OBFirstViewController.swift in Sources */,
Expand All @@ -809,6 +808,7 @@
500CA071299697320012779B /* CustomNavBar.swift in Sources */,
A79121292950D2000044E652 /* RecordViewController.swift in Sources */,
A7ED3EFA295C6E6E00342CC8 /* SettingViewModel.swift in Sources */,
500CA07329973A8F0012779B /* Assets.swift in Sources */,
A7912115294B1AAB0044E652 /* Challenge.swift in Sources */,
A79120DC294A0A5F0044E652 /* HRHN.xcdatamodeld in Sources */,
505B953B29599A24005F00C8 /* ReviewView.swift in Sources */,
Expand Down
12 changes: 12 additions & 0 deletions HRHN/Resources/Assets.xcassets/Dot.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"images" : [
{
"filename" : "Dot.svg",
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
3 changes: 3 additions & 0 deletions HRHN/Resources/Assets.xcassets/Dot.imageset/Dot.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 6 additions & 6 deletions HRHN/Sources/UI/TabBar/TabBarController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ class TabBarController: UITabBarController {
let firstTab = UINavigationController(rootViewController: todayVC)
firstTab.tabBarItem = UITabBarItem(
title: I18N.tabToday,
image: UIImage(named: TabbarIcons.todayUnselected.rawValue),
selectedImage: UIImage(named: TabbarIcons.todaySelected.rawValue)
image: UIImage(named: Assets.TabbarIcons.todayUnselected.rawValue),
selectedImage: UIImage(named: Assets.TabbarIcons.todaySelected.rawValue)
)
firstTab.tabBarItem.imageInsets = .init(top: 0, left: 0, bottom: -6, right: 0)
firstTab.tabBarItem.titlePositionAdjustment = .init(horizontal: 0, vertical: -5)
Expand All @@ -53,8 +53,8 @@ class TabBarController: UITabBarController {
let secondTab = UINavigationController(rootViewController: recordVC)
secondTab.tabBarItem = UITabBarItem(
title: I18N.tabRecord,
image: UIImage(named: TabbarIcons.recordUnselected.rawValue),
selectedImage: UIImage(named: TabbarIcons.recordSelected.rawValue)
image: UIImage(named: Assets.TabbarIcons.recordUnselected.rawValue),
selectedImage: UIImage(named: Assets.TabbarIcons.recordSelected.rawValue)
)
secondTab.tabBarItem.imageInsets = .init(top: 0, left: 0, bottom: -6, right: 0)
secondTab.tabBarItem.titlePositionAdjustment = .init(horizontal: 0, vertical: -5)
Expand All @@ -63,8 +63,8 @@ class TabBarController: UITabBarController {
let thirdTab = UINavigationController(rootViewController: storageVC)
thirdTab.tabBarItem = UITabBarItem(
title: I18N.tabStorage,
image: UIImage(named: TabbarIcons.storageUnselected.rawValue),
selectedImage: UIImage(named: TabbarIcons.storageSelected.rawValue)
image: UIImage(named: Assets.TabbarIcons.storageUnselected.rawValue),
selectedImage: UIImage(named: Assets.TabbarIcons.storageSelected.rawValue)
)
thirdTab.tabBarItem.imageInsets = .init(top: 0, left: 0, bottom: -6, right: 0)
thirdTab.tabBarItem.titlePositionAdjustment = .init(horizontal: 0, vertical: -5)
Expand Down
161 changes: 93 additions & 68 deletions HRHN/Sources/UI/Today/TodayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,10 @@ final class TodayViewController: UIViewController {
// MARK: - Properties
private let viewModel: TodayViewModel

private lazy var titleLabel: UILabel = {
private let titleLabel: UILabel = {
$0.text = I18N.todayTitle
$0.textColor = UIColor.point
$0.font = .systemFont(ofSize: 25, weight: .bold)
$0.numberOfLines = 0
return $0
}(UILabel())

private lazy var dateLabel: UILabel = {
$0.text = Date().localizedFullDate(NSLocale.current.language.languageCode?.identifier
?? "en")
$0.textColor = .secondaryLabel
$0.font = .systemFont(ofSize: 12, weight: .medium)
$0.numberOfLines = 0
$0.font = .systemFont(ofSize: 15)
return $0
}(UILabel())

Expand All @@ -40,38 +30,45 @@ final class TodayViewController: UIViewController {
return $0
}(UIView())

private lazy var emptyStackView: UIStackView = {
$0.spacing = 20
$0.alignment = .center
$0.distribution = .fill
$0.axis = .vertical
return $0
}(UIStackView())

private lazy var challengeLabel: UILabel = {
$0.textColor = .cellLabel
$0.font = .systemFont(ofSize: 25, weight: .bold)
$0.font = .systemFont(ofSize: 26, weight: .bold)
$0.numberOfLines = 0
$0.textAlignment = .center
return $0
}(UILabel())

private lazy var emptyLabel: UILabel = {
$0.text = I18N.todayEmpty
$0.textColor = .dim
$0.font = .systemFont(ofSize: 16, weight: .light)
$0.textColor = .cellLabel.withAlphaComponent(0.3)
$0.font = .systemFont(ofSize: 26, weight: .bold)
$0.numberOfLines = 0
$0.textAlignment = .center
return $0
}(UILabel())

private lazy var addButton: UIButton = {
$0.setTitle(I18N.btnAdd, for: .normal)
$0.setTitleColor(.white, for: .normal)
$0.backgroundColor = .point
$0.layer.cornerRadius = 20
$0.addTarget(self, action: #selector(addButtonDidTap(_:)), for: .primaryActionTriggered)
private lazy var addButton: UIButton = { [weak self] in
var titleAttribute = AttributedString(I18N.btnAdd)
titleAttribute.font = .systemFont(ofSize: 15)
$0.configuration?.attributedTitle = titleAttribute

let imageConfig = UIImage.SymbolConfiguration(font: UIFont.systemFont(ofSize: 13))
$0.setImage(UIImage(systemName: "plus", withConfiguration: imageConfig), for: .normal)
$0.configuration?.imagePadding = 4

$0.configuration?.baseBackgroundColor = .cellFill
$0.configuration?.baseForegroundColor = .point
$0.configuration?.cornerStyle = .fixed
$0.configuration?.background.cornerRadius = 16
$0.configuration?.contentInsets = .init(top: 0, leading: 20, bottom: 0, trailing: 20)

let action = UIAction { _ in
self?.viewModel.addButtonDidTap(navigationController: self?.navigationController)
}
$0.addAction(action, for: .touchUpInside)

return $0
}(UIButton(type: .system))
}(UIButton(configuration: .filled()))

// MARK: - LifeCycle

Expand All @@ -94,8 +91,6 @@ final class TodayViewController: UIViewController {

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
dateLabel.text = Date().localizedFullDate(NSLocale.current.language.languageCode?.identifier
?? "en")
bind()
}

Expand All @@ -110,15 +105,13 @@ extension TodayViewController {
self.navigationController?.pushViewController(settingVC, animated: true)
}

@objc func addButtonDidTap(_ sender: UIButton) {
viewModel.addButtonDidTap(navigationController: navigationController)
}

@objc private func cardDidTap(tapGestureRecognizer: UITapGestureRecognizer) {
if viewModel.isTodayChallengeExist() {
let modifyVC = EditChallengeViewController(viewModel: EditChallengeViewModel(mode: .modify))
modifyVC.hidesBottomBarWhenPushed = true
navigationController?.pushViewController(modifyVC, animated: true)
} else {
viewModel.addButtonDidTap(navigationController: navigationController)
}
}
}
Expand All @@ -129,12 +122,25 @@ extension TodayViewController {
private func bind() {
viewModel.fetchTodayChallenge()
viewModel.todayChallenge.subscribe { value in
DispatchQueue.main.async {
self.challengeLabel.text = value
if value == nil {
self.makeEmptyState()
DispatchQueue.main.async { [weak self] in
if let value {
let challengeText = value
let mutableAttrString = NSMutableAttributedString(string: challengeText)

let whiteSpaceAttachment = NSTextAttachment()
whiteSpaceAttachment.image = UIImage()
whiteSpaceAttachment.bounds = CGRect(x: 0, y: 0, width: 2, height: 0)
mutableAttrString.append(NSAttributedString(attachment: whiteSpaceAttachment))

let dotAttachment = NSTextAttachment()
dotAttachment.image = UIImage(named: Assets.dot)
dotAttachment.bounds = CGRect(x: 0, y: 0, width: 8, height: 8)
mutableAttrString.append(NSAttributedString(attachment: dotAttachment))

self?.challengeLabel.attributedText = mutableAttrString
self?.makeChallengeState()
} else {
self.makeChallengeState()
self?.makeEmptyState()
}
}
}
Expand All @@ -145,46 +151,65 @@ extension TodayViewController {
extension TodayViewController {
private func setUI(){
view.backgroundColor = .background
view.addSubviews(titleLabel, dateLabel)
}

private func makeChallengeState() {
emptyLabel.removeFromSuperview()
addButton.removeFromSuperview()

view.addSubviews(
titleLabel,
cardView,
challengeLabel
)

titleLabel.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(view.safeAreaLayoutGuide).offset(20)
$0.bottom.equalTo(cardView.snp.top).offset(-10)
$0.left.equalTo(cardView)
}

dateLabel.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalTo(titleLabel.snp.bottom).offset(5)
challengeLabel.snp.makeConstraints {
$0.center.equalToSuperview()
$0.horizontalEdges.equalToSuperview().inset(80)
}

view.addSubviews(cardView)
cardView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(40.constraintMultiplierTargetValue.horizontallyAdjusted)
$0.centerY.equalToSuperview()
$0.height.equalTo(400.constraintMultiplierTargetValue.horizontallyAdjusted)
}

}

private func makeChallengeState(){
emptyStackView.removeFromSuperview()
cardView.addSubviews(challengeLabel)
challengeLabel.snp.makeConstraints {
$0.leading.trailing.equalToSuperview().inset(20.constraintMultiplierTargetValue.horizontallyAdjusted)
$0.centerY.equalToSuperview()
$0.horizontalEdges.equalToSuperview().inset(40)
$0.top.equalTo(challengeLabel).offset(-20)
$0.bottom.equalTo(challengeLabel).offset(20)
}
}

private func makeEmptyState(){
private func makeEmptyState() {
challengeLabel.removeFromSuperview()
cardView.addSubviews(emptyStackView)
emptyStackView.addArrangedSubviews(emptyLabel, addButton)
emptyStackView.snp.makeConstraints {
$0.center.equalTo(self.cardView.snp.center)

view.addSubviews(
titleLabel,
cardView,
emptyLabel,
addButton
)

titleLabel.snp.makeConstraints {
$0.bottom.equalTo(cardView.snp.top).offset(-10)
$0.left.equalTo(cardView)
}

emptyLabel.snp.makeConstraints {
$0.center.equalToSuperview()
$0.horizontalEdges.equalToSuperview().inset(80)
}

cardView.snp.makeConstraints {
$0.horizontalEdges.equalToSuperview().inset(40)
$0.top.equalTo(emptyLabel).offset(-20)
$0.bottom.equalTo(emptyLabel).offset(20)
}

addButton.snp.makeConstraints {
$0.width.equalTo(109)
$0.height.equalTo(40)
$0.top.equalTo(cardView.snp.bottom).offset(10)
$0.right.equalTo(cardView)
$0.height.equalTo(50)
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions HRHN/Sources/Utils/Design/Assets/Assets.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
//
// Assets.swift
// HRHN
//
// Created by 민채호 on 2023/02/11.
//

import Foundation

struct Assets {

enum TabbarIcons: String {
case todaySelected = "Today_selected"
case todayUnselected = "Today_unselected"
case recordSelected = "Record_selected"
case recordUnselected = "Record_unselected"
case storageSelected = "Storage_selected"
case storageUnselected = "Storage_unselected"
}

static let dot = "Dot"
}
17 changes: 0 additions & 17 deletions HRHN/Sources/Utils/Design/TabIcons/TabIcons.swift

This file was deleted.