Skip to content

Commit

Permalink
Merge pull request #28 from U-is-Ni-in-Korea/feat_27_ryu
Browse files Browse the repository at this point in the history
✨[FEAT] : UIKit NavigationView 디자인시스템 추가
  • Loading branch information
ryuchanghwi authored Dec 26, 2023
2 parents 8797e01 + ebd682f commit 1a991a2
Show file tree
Hide file tree
Showing 3 changed files with 219 additions and 11 deletions.
11 changes: 11 additions & 0 deletions Sources/SDSKit/Component/NavigationBar/SDSNavigationStyle.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#if canImport(UIKit)
import UIKit
#endif

public enum SDSNavigationStyle {
case leftTitleRightDismissButton(title: String, dismissImage: UIImage, action: () -> Void)
case leftPopButtonMiddleTitle(title: String, action: () -> Void)
case titleRightDismissButton(title: String, dismissImage: UIImage, action: () -> Void)
case leftPopButtonMiddleTitleRightDismissButton(title: String, dismissImage: UIImage, popAction: () -> Void, dismissAction: () -> Void)
case leftPopButtonMiddleTitleRightCustomButton(title: String, customButtonTitle: String, popAction: () -> Void, dismissAction: () -> Void)
}
205 changes: 205 additions & 0 deletions Sources/SDSKit/Component/NavigationBar/SDSNavigationUIView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
#if canImport(UIKit)
import UIKit
import SnapKit
#endif


public final class SDSNavigationUIView: UIView {
let style: SDSNavigationStyle
public init(style: SDSNavigationStyle) {
self.style = style
super.init(frame: .zero)
setup()
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private func setup() {
switch style {
case .leftTitleRightDismissButton(let title, let dismissImage, _):
let titleLabel: UILabel = {
let label = UILabel()
label.textColor = .gray600
label.text = title
label.font = SDSFont.title1.font
return label
}()
let dismissButton: UIButton = {
let button = UIButton()
button.setImage(dismissImage, for: .normal)
button.addTarget(self, action: #selector(dismissButtonTapped), for: .touchUpInside)
return button
}()
[titleLabel, dismissButton].forEach { addSubview($0) }
self.snp.makeConstraints {
$0.height.equalTo(52)
}
titleLabel.snp.makeConstraints {
$0.leading.equalToSuperview().inset(20)
$0.centerY.equalToSuperview()
}
dismissButton.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(10)
$0.height.width.equalTo(36)
$0.centerY.equalToSuperview()
}
case .leftPopButtonMiddleTitle(let title, _):
let popButton: UIButton = {
let button = UIButton()
button.setImage(SDSIcon.icNavigationBarLeft, for: .normal)
button.addTarget(self, action: #selector(popButtonTapped), for: .touchUpInside)
return button
}()
let middleTitleLabel: UILabel = {
let label = UILabel()
label.text = title
label.font = SDSFont.subTitle.font
label.textColor = .gray600
return label
}()
[popButton, middleTitleLabel].forEach { addSubview($0) }
self.snp.makeConstraints {
$0.height.equalTo(52)
}
popButton.snp.makeConstraints {
$0.leading.equalToSuperview().inset(10)
$0.height.width.equalTo(24)
$0.centerY.equalToSuperview()
}
middleTitleLabel.snp.makeConstraints {
$0.centerX.centerY.equalToSuperview()
}
case .titleRightDismissButton(let title, let dismissImage, _):
let middleTitleLabel: UILabel = {
let label = UILabel()
label.text = title
label.font = SDSFont.subTitle.font
label.textColor = .gray600
return label
}()
let dismissButton: UIButton = {
let button = UIButton()
button.setImage(dismissImage, for: .normal)
button.addTarget(self, action: #selector(dismissButtonTapped), for: .touchUpInside)
return button
}()
[middleTitleLabel, dismissButton].forEach { addSubview($0) }
self.snp.makeConstraints {
$0.height.equalTo(52)
}
dismissButton.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(10)
$0.height.width.equalTo(36)
$0.centerY.equalToSuperview()
}
middleTitleLabel.snp.makeConstraints {
$0.centerX.centerY.equalToSuperview()
}
case .leftPopButtonMiddleTitleRightDismissButton(let title, let dismissImage, _, _):
let popButton: UIButton = {
let button = UIButton()
button.setImage(SDSIcon.icNavigationBarLeft, for: .normal)
button.addTarget(self, action: #selector(popButtonTapped), for: .touchUpInside)
return button
}()
let middleTitleLabel: UILabel = {
let label = UILabel()
label.text = title
label.font = SDSFont.subTitle.font
label.textColor = .gray600
return label
}()
let dismissButton: UIButton = {
let button = UIButton()
button.setImage(dismissImage, for: .normal)
button.addTarget(self, action: #selector(dismissButtonTapped), for: .touchUpInside)
return button
}()
[popButton, middleTitleLabel, dismissButton].forEach { addSubview($0) }
self.snp.makeConstraints {
$0.height.equalTo(52)
}
popButton.snp.makeConstraints {
$0.leading.equalToSuperview().inset(10)
$0.height.width.equalTo(24)
$0.centerY.equalToSuperview()
}
middleTitleLabel.snp.makeConstraints {
$0.centerX.centerY.equalToSuperview()
}
dismissButton.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(10)
$0.height.width.equalTo(36)
$0.centerY.equalToSuperview()
}
case .leftPopButtonMiddleTitleRightCustomButton(let title, let customButtonTitle, _, _):
let popButton: UIButton = {
let button = UIButton()
button.setImage(SDSIcon.icNavigationBarLeft, for: .normal)
button.addTarget(self, action: #selector(popButtonTapped), for: .touchUpInside)
return button
}()
let middleTitleLabel: UILabel = {
let label = UILabel()
label.text = title
label.font = SDSFont.subTitle.font
label.textColor = .gray600
return label
}()
let dismissButton: UIButton = {
let button = UIButton()
button.setTitle(customButtonTitle, for: .normal)
button.setTitleColor(.lightBlue600, for: .normal)
button.titleLabel?.font = SDSFont.subTitle.font
button.addTarget(self, action: #selector(dismissButtonTapped), for: .touchUpInside)
return button
}()
[popButton, middleTitleLabel, dismissButton].forEach { addSubview($0) }
self.snp.makeConstraints {
$0.height.equalTo(52)
}
popButton.snp.makeConstraints {
$0.leading.equalToSuperview().inset(10)
$0.height.width.equalTo(24)
$0.centerY.equalToSuperview()
}
middleTitleLabel.snp.makeConstraints {
$0.centerX.centerY.equalToSuperview()
}
dismissButton.snp.makeConstraints {
$0.trailing.equalToSuperview().inset(10)
$0.height.width.equalTo(36)
$0.centerY.equalToSuperview()
}
}
}
@objc private func dismissButtonTapped() {
switch style {
case .leftTitleRightDismissButton(_, _, let action):
action()
case .leftPopButtonMiddleTitle(_, _):
return
case .titleRightDismissButton(_, _, let action):
action()
case .leftPopButtonMiddleTitleRightDismissButton(_, _, _, let dismissAction):
dismissAction()
case .leftPopButtonMiddleTitleRightCustomButton(_, _, _, let dismissAction):
dismissAction()
}
}
@objc private func popButtonTapped() {
switch style {
case .leftTitleRightDismissButton(_, _, _):
return
case .leftPopButtonMiddleTitle(_, let action):
action()
case .titleRightDismissButton(_, _, _):
return
case .leftPopButtonMiddleTitleRightDismissButton(_, _, let popAction, _):
popAction()
case .leftPopButtonMiddleTitleRightCustomButton(_, _, let popAction, _):
popAction()
}
}
}

14 changes: 3 additions & 11 deletions Sources/SDSKit/Component/NavigationBar/SDSNavigationView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,6 @@
import SwiftUI
#endif

public enum SDSNavigationStyle {
case leftTitleRightDismissButton(title: String, dismissImage: Image, action: () -> Void)
case leftPopButtonMiddleTitle(title: String, action: () -> Void)
case titleRightDismissButton(title: String, dismissImage: Image, action: () -> Void)
case leftPopButtonMiddleTitleRightDismissButton(title: String, dismissImage: Image, popAction: () -> Void, dismissAction: () -> Void)
case leftPopButtonMiddleTitleRightCustomButton(title: String, customButtonTitle: String, popAction: () -> Void, dismissAction: () -> Void)
}

public struct SDSNavigationView: View {
let style: SDSNavigationStyle
public init(style: SDSNavigationStyle) {
Expand All @@ -27,7 +19,7 @@ public struct SDSNavigationView: View {
Button {
action()
} label: {
dismissImage
Image(uiImage: dismissImage)
.resizable()
.frame(width: 36, height: 36)
}
Expand Down Expand Up @@ -71,7 +63,7 @@ public struct SDSNavigationView: View {
Button {
action()
} label: {
dismissImage
Image(uiImage: dismissImage)
.resizable()
.frame(width: 36, height: 36)
}
Expand All @@ -98,7 +90,7 @@ public struct SDSNavigationView: View {
Button {
dismissAction()
} label: {
dismissImage
Image(uiImage: dismissImage)
.resizable()
.frame(width: 36, height: 36)
}
Expand Down

0 comments on commit 1a991a2

Please sign in to comment.