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

✨feature/bind tab items #18

Merged
merged 5 commits into from
Jan 1, 2021
Merged
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
128 changes: 63 additions & 65 deletions Dear-World/Dear-World.xcodeproj/MessageCountBadgeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,79 +6,77 @@
//

import UIKit

import SnapKit
import Then

public final class MessageCountBadgeView: UIView {
private var totalCount: UILabel = UILabel()

public var count: Int? {
didSet {
self.totalCount.text = "\(count ?? 0)"
}
private var totalCount: UILabel = UILabel()

public var count: Int? {
didSet {
self.totalCount.text = count?.formatted
}

override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
setupSubviews()
}

override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
setupSubviews()
}

override public func didMoveToSuperview() {
self.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalToSuperview().inset(60)
}
override public func didMoveToSuperview() {
self.snp.makeConstraints {
$0.centerX.equalToSuperview()
$0.top.equalToSuperview().inset(60)
}
}

private func setupUI() {
self.snp.makeConstraints {
$0.width.equalTo(88)
$0.height.equalTo(80)
}

private func setupUI() {
self.snp.makeConstraints {
$0.width.equalTo(88)
$0.height.equalTo(80)
}
}

private func setupSubviews() {
let mainLogo: UIImageView = UIImageView().then {
$0.image = UIImage(named: "earth")
}

private func setupSubviews() {
let mainLogo: UIImageView = UIImageView().then {
$0.image = UIImage(named: "earth")
}
self.addSubview(mainLogo)
mainLogo.snp.makeConstraints {
$0.width.height.equalTo(48)
$0.centerX.equalToSuperview()
$0.top.equalToSuperview()
}
let totalCountContainer: UIView = UIView().then {
$0.backgroundColor = .livelyBlue
$0.layer.masksToBounds = true
$0.layer.borderWidth = 2
$0.layer.cornerRadius = 19
$0.layer.borderColor = UIColor.warmBlue.cgColor
}
self.addSubview(totalCountContainer)
totalCountContainer.snp.makeConstraints {
$0.width.equalTo(88)
$0.height.equalTo(37)
$0.centerX.equalToSuperview()
$0.top.equalTo(mainLogo.snp.bottom).offset(-6)
}
self.totalCount.do {
$0.text = "-1"
$0.textAlignment = .center
$0.font = .systemFont(ofSize: 14)
$0.textColor = .warmBlue
}
totalCountContainer.addSubview(totalCount)
totalCount.snp.makeConstraints {
$0.center.equalToSuperview()
}
self.addSubview(mainLogo)
mainLogo.snp.makeConstraints {
$0.width.height.equalTo(48)
$0.centerX.equalToSuperview()
$0.top.equalToSuperview()
}

required init?(coder: NSCoder) {
super.init(coder: coder)

setupUI()
setupSubviews()
let totalCountContainer: UIView = UIView().then {
$0.backgroundColor = .livelyBlue
$0.layer.masksToBounds = true
$0.layer.borderWidth = 2
$0.layer.cornerRadius = 19
$0.layer.borderColor = UIColor.warmBlue.cgColor
}
self.addSubview(totalCountContainer)
totalCountContainer.snp.makeConstraints {
$0.width.equalTo(88)
$0.height.equalTo(37)
$0.centerX.equalToSuperview()
$0.top.equalTo(mainLogo.snp.bottom).offset(-6)
}
self.totalCount.do {
$0.textAlignment = .center
$0.font = .boldSystemFont(ofSize: 14)
$0.textColor = .warmBlue
}
totalCountContainer.addSubview(totalCount)
totalCount.snp.makeConstraints {
$0.center.equalToSuperview()
}
}

required init?(coder: NSCoder) {
super.init(coder: coder)

setupUI()
setupSubviews()
}
}
34 changes: 17 additions & 17 deletions Dear-World/Dear-World.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
121BDB8E259829840062B15A /* CountrySelectController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 121BDB8D259829840062B15A /* CountrySelectController.swift */; };
128313E32598A08700BDF8A3 /* Message.swift in Sources */ = {isa = PBXBuildFile; fileRef = 128313E22598A08700BDF8A3 /* Message.swift */; };
128313EE2598A14E00BDF8A3 /* List.swift in Sources */ = {isa = PBXBuildFile; fileRef = 128313ED2598A14E00BDF8A3 /* List.swift */; };
128313F42598CDA900BDF8A3 /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 128313F32598CDA900BDF8A3 /* MainTabBarController.swift */; };
3902F1052596F26D00A3DF8C /* CheeringMapViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3902F1042596F26D00A3DF8C /* CheeringMapViewController.swift */; };
3902F1132597049D00A3DF8C /* SendMessageViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3902F1122597049D00A3DF8C /* SendMessageViewController.swift */; };
3902F118259704AF00A3DF8C /* AboutViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3902F117259704AF00A3DF8C /* AboutViewController.swift */; };
3902F12425970E5600A3DF8C /* Int+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3902F12325970E5600A3DF8C /* Int+.swift */; };
3902F12425970E5600A3DF8C /* Number+.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3902F12325970E5600A3DF8C /* Number+.swift */; };
3902F12A259714D800A3DF8C /* RankerTableViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3902F129259714D800A3DF8C /* RankerTableViewCell.swift */; };
3958257B25948E41007325AB /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3958257A25948E41007325AB /* AppDelegate.swift */; };
3958258425948E43007325AB /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 3958258325948E43007325AB /* Assets.xcassets */; };
Expand All @@ -34,6 +33,7 @@
395826212596D0B0007325AB /* Alamofire in Frameworks */ = {isa = PBXBuildFile; productRef = 395826202596D0B0007325AB /* Alamofire */; };
395826272596D225007325AB /* SnapKit in Frameworks */ = {isa = PBXBuildFile; productRef = 395826262596D225007325AB /* SnapKit */; };
395826332596E693007325AB /* Logger.swift in Sources */ = {isa = PBXBuildFile; fileRef = 395826322596E693007325AB /* Logger.swift */; };
395A4177259DF9F900F10531 /* MainTabBarController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 395A4176259DF9F900F10531 /* MainTabBarController.swift */; };
39658F8D259AD9900050D180 /* SplashViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39658F8C259AD9900050D180 /* SplashViewController.swift */; };
39658F92259AD9B70050D180 /* SplashReactor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 39658F91259AD9B70050D180 /* SplashReactor.swift */; };
39658F9B259ADB130050D180 /* Lottie in Frameworks */ = {isa = PBXBuildFile; productRef = 39658F9A259ADB130050D180 /* Lottie */; };
Expand Down Expand Up @@ -90,7 +90,7 @@
/* End PBXContainerItemProxy section */

/* Begin PBXFileReference section */
121BDB292597259E0062B15A /* MessageCountBadgeView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = MessageCountBadgeView.swift; path = "Dear-World.xcodeproj/MessageCountBadgeView.swift"; sourceTree = SOURCE_ROOT; };
121BDB292597259E0062B15A /* MessageCountBadgeView.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; name = MessageCountBadgeView.swift; path = "Dear-World.xcodeproj/MessageCountBadgeView.swift"; sourceTree = SOURCE_ROOT; tabWidth = 2; };
121BDB43259735200062B15A /* UIColor+.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = "UIColor+.swift"; sourceTree = "<group>"; tabWidth = 2; };
121BDB582597652A0062B15A /* MessageTableViewCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageTableViewCell.swift; sourceTree = "<group>"; };
121BDB662597982F0062B15A /* DiscoverReactor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverReactor.swift; sourceTree = "<group>"; };
Expand All @@ -99,11 +99,10 @@
121BDB8D259829840062B15A /* CountrySelectController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CountrySelectController.swift; sourceTree = "<group>"; };
128313E22598A08700BDF8A3 /* Message.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; name = Message.swift; path = "Dear-World/Source/Domain/Message/Message.swift"; sourceTree = SOURCE_ROOT; tabWidth = 2; };
128313ED2598A14E00BDF8A3 /* List.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = List.swift; sourceTree = "<group>"; };
128313F32598CDA900BDF8A3 /* MainTabBarController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = "<group>"; };
3902F1042596F26D00A3DF8C /* CheeringMapViewController.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = CheeringMapViewController.swift; sourceTree = "<group>"; tabWidth = 2; };
3902F1122597049D00A3DF8C /* SendMessageViewController.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = SendMessageViewController.swift; sourceTree = "<group>"; tabWidth = 2; };
3902F117259704AF00A3DF8C /* AboutViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutViewController.swift; sourceTree = "<group>"; };
3902F12325970E5600A3DF8C /* Int+.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = "Int+.swift"; sourceTree = "<group>"; tabWidth = 2; };
3902F12325970E5600A3DF8C /* Number+.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = "Number+.swift"; sourceTree = "<group>"; tabWidth = 2; };
3902F129259714D800A3DF8C /* RankerTableViewCell.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = RankerTableViewCell.swift; sourceTree = "<group>"; tabWidth = 2; };
3958257725948E41007325AB /* Dear-World.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Dear-World.app"; sourceTree = BUILT_PRODUCTS_DIR; };
3958257A25948E41007325AB /* AppDelegate.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; tabWidth = 2; };
Expand All @@ -119,6 +118,7 @@
395825B625948EE4007325AB /* Colors.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Colors.xcassets; sourceTree = "<group>"; };
395826112596322B007325AB /* DiscoverViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DiscoverViewController.swift; sourceTree = "<group>"; };
395826322596E693007325AB /* Logger.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = Logger.swift; sourceTree = "<group>"; tabWidth = 2; };
395A4176259DF9F900F10531 /* MainTabBarController.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = MainTabBarController.swift; sourceTree = "<group>"; tabWidth = 2; };
39658F8C259AD9900050D180 /* SplashViewController.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = SplashViewController.swift; sourceTree = "<group>"; tabWidth = 2; };
39658F91259AD9B70050D180 /* SplashReactor.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = SplashReactor.swift; sourceTree = "<group>"; tabWidth = 2; };
39658F9F259ADE770050D180 /* splash_1x.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = splash_1x.json; sourceTree = "<group>"; };
Expand Down Expand Up @@ -230,14 +230,6 @@
path = Model;
sourceTree = "<group>";
};
128313F22598CD6800BDF8A3 /* Container */ = {
isa = PBXGroup;
children = (
128313F32598CDA900BDF8A3 /* MainTabBarController.swift */,
);
path = Container;
sourceTree = "<group>";
};
3902F128259714AB00A3DF8C /* Cell */ = {
isa = PBXGroup;
children = (
Expand All @@ -249,7 +241,7 @@
3902F14F2597531600A3DF8C /* Extension */ = {
isa = PBXGroup;
children = (
3902F12325970E5600A3DF8C /* Int+.swift */,
3902F12325970E5600A3DF8C /* Number+.swift */,
121BDB43259735200062B15A /* UIColor+.swift */,
39F0C1622597B34F00A7001F /* UIView+.swift */,
39F0C16A2597C7DF00A7001F /* UIImage+.swift */,
Expand Down Expand Up @@ -381,8 +373,8 @@
395825B525948ECE007325AB /* Scene */ = {
isa = PBXGroup;
children = (
128313F22598CD6800BDF8A3 /* Container */,
39658F8B259AD9760050D180 /* Splash */,
395A4170259DF99300F10531 /* Main */,
3958260025962F77007325AB /* Discover */,
3958260125962F7E007325AB /* Cheering Map */,
3958260225962F94007325AB /* Send Message */,
Expand Down Expand Up @@ -430,6 +422,14 @@
path = About;
sourceTree = "<group>";
};
395A4170259DF99300F10531 /* Main */ = {
isa = PBXGroup;
children = (
395A4176259DF9F900F10531 /* MainTabBarController.swift */,
);
path = Main;
sourceTree = "<group>";
};
39658F8B259AD9760050D180 /* Splash */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -689,11 +689,12 @@
121BDB712597A5D60062B15A /* APIMock.swift in Sources */,
39672DB32598D139001D7E69 /* SelectCountryView.swift in Sources */,
3902F118259704AF00A3DF8C /* AboutViewController.swift in Sources */,
3902F12425970E5600A3DF8C /* Int+.swift in Sources */,
3902F12425970E5600A3DF8C /* Number+.swift in Sources */,
39EED23C259D00F8007452E1 /* CheeringMapReactor.swift in Sources */,
39F0C18B2598799200A7001F /* Network.swift in Sources */,
3971EB37259A9C550084E6DC /* Message.API.SendMessage.swift in Sources */,
395826122596322B007325AB /* DiscoverViewController.swift in Sources */,
395A4177259DF9F900F10531 /* MainTabBarController.swift in Sources */,
3971EB18259A7BC10084E6DC /* Emoji.swift in Sources */,
39EED22E259CFEB8007452E1 /* World.Model.Ranker.swift in Sources */,
3902F1132597049D00A3DF8C /* SendMessageViewController.swift in Sources */,
Expand Down Expand Up @@ -722,7 +723,6 @@
39F0C1B72598927C00A7001F /* ErrorView.swift in Sources */,
39672DC12598E95A001D7E69 /* TextView.swift in Sources */,
39F0C176259860D700A7001F /* UIControl+Rx.swift in Sources */,
128313F42598CDA900BDF8A3 /* MainTabBarController.swift in Sources */,
121BDB2A2597259E0062B15A /* MessageCountBadgeView.swift in Sources */,
39F0C16B2597C7DF00A7001F /* UIImage+.swift in Sources */,
121BDB6C2597A49B0062B15A /* MessageMock.swift in Sources */,
Expand Down
17 changes: 0 additions & 17 deletions Dear-World/Dear-World/Source/Common/Extension/Int+.swift

This file was deleted.

41 changes: 41 additions & 0 deletions Dear-World/Dear-World/Source/Common/Extension/Number+.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// Number+.swift
// Dear-World
//
// Created by dongyoung.lee on 2020/12/26.
//

import Foundation

extension Int {
var formatted: String? {
if self >= 100_000 {
return self.kFormat
} else {
return self.decimalFormat
}
}

var kFormat: String? {
guard let number = (Double(self) / 1_000).decimalFormat else { return nil }
return "\(number)K"
}

var decimalFormat: String? {
let numberFormatter: NumberFormatter = NumberFormatter().then {
$0.numberStyle = .decimal
}
return numberFormatter.string(from: NSNumber(value: self))
}
}
extension Double {
var decimalFormat: String? {
let numberFormatter: NumberFormatter = NumberFormatter().then {
$0.roundingMode = .halfEven
$0.minimumFractionDigits = 0
$0.maximumFractionDigits = 1
$0.numberStyle = .decimal
}
return numberFormatter.string(from: NSNumber(value: self))
}
}
49 changes: 2 additions & 47 deletions Dear-World/Dear-World/Source/Core/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
//
// Created by dongyoung.lee on 2020/12/24.
//
import RxSwift
import SnapKit
import Then
import UIKit
import RxSwift

@main
final class AppDelegate: UIResponder, UIApplicationDelegate {
Expand All @@ -20,53 +20,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate {

let mainWindow: UIWindow = UIWindow()
window = mainWindow
mainWindow.rootViewController = makeTabBarController()
mainWindow.rootViewController = MainTabBarController()
mainWindow.makeKeyAndVisible()
return true
}
func makeTabBarController() -> UITabBarController {
return UITabBarController().then {
$0.addChild(DiscoverViewController().then {
$0.tabBarItem.image = UIImage(named: "message_default")?
.withRenderingMode(.alwaysOriginal)
$0.tabBarItem.selectedImage = UIImage(named: "message")?
.withRenderingMode(.alwaysOriginal)
})
$0.addChild(SendMessageViewController().then {
$0.tabBarItem.image = UIImage(named: "add")?
.withRenderingMode(.alwaysOriginal)
})
$0.addChild(CheeringMapViewController().then {
$0.tabBarItem.image = UIImage(named: "earth_default")?
.withRenderingMode(.alwaysOriginal)
$0.tabBarItem.selectedImage = UIImage(named: "earth_icon")?
.withRenderingMode(.alwaysOriginal)
})
$0.tabBar.barTintColor = .white
$0.tabBar.layer.masksToBounds = true
$0.tabBar.layer.cornerRadius = 10
$0.tabBar.layer.borderWidth = 0.02
//TODO: 그림자 넣기

$0.delegate = self
}
}
}
extension AppDelegate: UITabBarControllerDelegate {
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if let _ = viewController as? SendMessageViewController {
let vc = SendMessageViewController()
tabBarController.addChild(vc)
tabBarController.view.addSubview(vc.view)
vc.view.frame.origin.y = tabBarController.view.frame.height
UIView.animate(withDuration: 0.2) {
vc.view.frame.origin.y = 0
} completion: { (_) in
tabBarController.willMove(toParent: tabBarController)
}

return false
}
return true
}
}
Loading