-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feat/#19-challengeViewUI
- Loading branch information
Showing
8 changed files
with
401 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// | ||
// AlertDelegate.swift | ||
// HMH_iOS | ||
// | ||
// Created by 김보연 on 1/7/24. | ||
// | ||
|
||
import Foundation | ||
|
||
protocol AlertDelegate: AnyObject { | ||
func enabledButtonTapped() | ||
func alertDismissTapped() | ||
} |
This file was deleted.
Oops, something went wrong.
94 changes: 94 additions & 0 deletions
94
HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/AlertViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
// | ||
// AlertViewController.swift | ||
// HMH_iOS | ||
// | ||
// Created by 김보연 on 1/6/24. | ||
// | ||
|
||
import UIKit | ||
|
||
enum AlertType { | ||
case HMHLogoutAlert | ||
case HMHQuitALert | ||
} | ||
|
||
final class AlertViewController: UIViewController { | ||
var alertType: AlertType? | ||
var okAction: (() -> Void)? | ||
|
||
private let logoutAlert = HMHLogoutAlert() | ||
private let quitAlert = HMHQuitAlert() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
view.backgroundColor = .black.withAlphaComponent(0.7) | ||
|
||
setDelegate() | ||
setAlertType() | ||
setUI() | ||
} | ||
|
||
private func setUI() { | ||
setHierarchy() | ||
setConstraint() | ||
} | ||
|
||
private func setHierarchy() { | ||
view.addSubviews(logoutAlert, quitAlert) | ||
} | ||
|
||
private func setConstraint() { | ||
logoutAlert.snp.makeConstraints { | ||
$0.center.equalToSuperview() | ||
$0.height.equalTo(177.adjusted) | ||
$0.width.equalTo(293.adjusted) | ||
} | ||
|
||
quitAlert.snp.makeConstraints { | ||
$0.center.equalToSuperview() | ||
$0.height.equalTo(203.adjusted) | ||
$0.width.equalTo(293.adjusted) | ||
} | ||
} | ||
|
||
private func setAlertType() { | ||
switch alertType { | ||
case .HMHLogoutAlert: | ||
setAlertView(logout: true, quit: false) | ||
case .HMHQuitALert: | ||
setAlertView(logout: false, quit: true) | ||
default: | ||
break | ||
} | ||
} | ||
|
||
private func setAlertView(logout: Bool, quit: Bool) { | ||
logoutAlert.isHidden = !logout | ||
quitAlert.isHidden = !quit | ||
} | ||
|
||
func setDelegate() { | ||
logoutAlert.delegate = self | ||
quitAlert.delegate = self | ||
} | ||
|
||
func emptyActions() { | ||
|
||
} | ||
|
||
func setAlertType(_ type: AlertType) { | ||
self.alertType = type | ||
} | ||
} | ||
|
||
extension AlertViewController: AlertDelegate { | ||
func enabledButtonTapped() { | ||
dismiss(animated: false) { | ||
(self.okAction ?? self.emptyActions)() | ||
} | ||
} | ||
|
||
func alertDismissTapped() { | ||
dismiss(animated: true) | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/CustomAlertButton.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// | ||
// CustomAlertButton.swift | ||
// HMH_iOS | ||
// | ||
// Created by 김보연 on 1/6/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
final class CustomAlertButton: UIButton { | ||
@frozen | ||
enum HMHAlertButtonType { | ||
case disabled | ||
case enabled | ||
} | ||
|
||
private var alertButtonType: HMHAlertButtonType = .disabled | ||
private let buttonTitleLabel = UILabel().then { | ||
$0.textColor = .whiteText | ||
$0.font = .iosText6Medium14 | ||
} | ||
|
||
init(buttonType: HMHAlertButtonType, buttonText: String) { | ||
super.init(frame: .zero) | ||
self.alertButtonType = buttonType | ||
buttonTitleLabel.text = buttonText | ||
|
||
configureButton() | ||
setUI() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setUI() { | ||
setHierarchy() | ||
setConstraints() | ||
} | ||
|
||
private func setHierarchy() { | ||
self.addSubview(buttonTitleLabel) | ||
} | ||
|
||
private func setConstraints() { | ||
self.snp.makeConstraints { | ||
$0.height.equalTo(44.adjustedHeight) | ||
} | ||
|
||
buttonTitleLabel.snp.makeConstraints { | ||
$0.center.equalToSuperview() | ||
} | ||
} | ||
|
||
private func configureButton() { | ||
self.layer.cornerRadius = 6.adjusted | ||
self.layer.masksToBounds = true | ||
|
||
switch alertButtonType { | ||
case .enabled: | ||
self.isEnabled = true | ||
self.backgroundColor = .bluePurpleButton | ||
|
||
case .disabled: | ||
self.isEnabled = false | ||
self.backgroundColor = .gray4 | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
HMH_iOS/HMH_iOS/Presentation/Common/CustomAlert/HMHLogoutAlert.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
// | ||
// HMHLogoutAlert.swift | ||
// HMH_iOS | ||
// | ||
// Created by 김보연 on 1/6/24. | ||
// | ||
|
||
import UIKit | ||
|
||
import SnapKit | ||
import Then | ||
|
||
final class HMHLogoutAlert: UIView { | ||
weak var delegate: AlertDelegate? | ||
|
||
private let titleLabel = UILabel().then { | ||
$0.text = StringLiteral.AlertTitle.logout | ||
$0.textColor = .whiteText | ||
$0.font = .iosText5Medium16 | ||
$0.textAlignment = .center | ||
} | ||
|
||
private let buttonStackView = UIStackView().then { | ||
$0.axis = .horizontal | ||
$0.distribution = .fillEqually | ||
$0.spacing = 7 | ||
} | ||
|
||
private let leftButton = CustomAlertButton(buttonType: .disabled, buttonText: StringLiteral.AlertButton.close) | ||
private let rightButton = CustomAlertButton(buttonType: .enabled, buttonText: StringLiteral.AlertButton.confirm) | ||
|
||
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
setAddTarget() | ||
configureView() | ||
setUI() | ||
} | ||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
private func setUI() { | ||
setHierarchy() | ||
setConstraints() | ||
} | ||
|
||
private func setHierarchy() { | ||
self.addSubviews(titleLabel, buttonStackView) | ||
buttonStackView.addArrangeSubViews([leftButton, rightButton]) | ||
} | ||
|
||
private func setConstraints() { | ||
titleLabel.snp.makeConstraints { | ||
$0.top.equalToSuperview().inset(50.adjusted) | ||
$0.horizontalEdges.equalToSuperview() | ||
} | ||
|
||
buttonStackView.snp.makeConstraints { | ||
$0.horizontalEdges.equalToSuperview().inset(20.adjustedWidth) | ||
$0.bottom.equalToSuperview().inset(19.adjusted) | ||
} | ||
} | ||
|
||
private func setAddTarget() { | ||
leftButton.addTarget(self, action: #selector(exitButtonTapped), for: .touchUpInside) | ||
rightButton.addTarget(self, action: #selector(logoutButtonTapped), for: .touchUpInside) | ||
} | ||
|
||
private func configureView() { | ||
self.do { | ||
$0.makeCornerRound(radius: 10.adjusted) | ||
$0.backgroundColor = .gray7 | ||
} | ||
} | ||
|
||
@objc func exitButtonTapped() { | ||
delegate?.alertDismissTapped() | ||
} | ||
|
||
@objc func logoutButtonTapped() { | ||
delegate?.enabledButtonTapped() | ||
} | ||
} |
Oops, something went wrong.