|
| 1 | +// |
| 2 | +// RoutineEditAlertViewController.swift |
| 3 | +// Presentation |
| 4 | +// |
| 5 | +// Created by 최정인 on 8/21/25. |
| 6 | +// |
| 7 | + |
| 8 | +import Shared |
| 9 | +import SnapKit |
| 10 | +import UIKit |
| 11 | + |
| 12 | +final class RoutineEditAlertViewController: UIViewController { |
| 13 | + private enum Layout { |
| 14 | + static let horizontalMargin: CGFloat = 24 |
| 15 | + static let mainLabelTopSpacing: CGFloat = 26 |
| 16 | + static let mainLabelHeight: CGFloat = 24 |
| 17 | + static let subLabelTopSpacing: CGFloat = 10 |
| 18 | + static let applyTodayButtonTopSpacing: CGFloat = 24 |
| 19 | + static let applyTomorrowButtonTopSpacing: CGFloat = 12 |
| 20 | + static let buttonHeight: CGFloat = 54 |
| 21 | + } |
| 22 | + |
| 23 | + private let mainLabel = UILabel() |
| 24 | + private let subLabel = UILabel() |
| 25 | + private let applyTodayButton = UIButton() |
| 26 | + private let applyTomorrowButton = UIButton() |
| 27 | + var onDismiss: (() -> Void)? |
| 28 | + var goToRoutineCreationView: ((Bool) -> Void)? |
| 29 | + |
| 30 | + override func viewDidLoad() { |
| 31 | + super.viewDidLoad() |
| 32 | + configureAttribute() |
| 33 | + configureLayout() |
| 34 | + } |
| 35 | + |
| 36 | + override func viewDidDisappear(_ animated: Bool) { |
| 37 | + super.viewDidDisappear(animated) |
| 38 | + if isBeingDismissed { onDismiss?() } |
| 39 | + } |
| 40 | + |
| 41 | + private func configureAttribute() { |
| 42 | + mainLabel.text = "변경한 루틴, 언제 시작할까요?" |
| 43 | + mainLabel.font = BitnagilFont(style: .title3, weight: .semiBold).font |
| 44 | + mainLabel.textColor = BitnagilColor.gray10 |
| 45 | + |
| 46 | + subLabel.text = "변경된 루틴이 반영되는 시점을 선택해 주세요." |
| 47 | + subLabel.font = BitnagilFont(style: .body2, weight: .medium).font |
| 48 | + subLabel.textColor = BitnagilColor.gray40 |
| 49 | + |
| 50 | + var applyTodayButtonConfiguration = UIButton.Configuration.filled() |
| 51 | + applyTodayButtonConfiguration.baseBackgroundColor = BitnagilColor.gray10 |
| 52 | + applyTodayButtonConfiguration.background.cornerRadius = 12 |
| 53 | + applyTodayButtonConfiguration.attributedTitle = AttributedString( |
| 54 | + "당일부터 적용", |
| 55 | + attributes: .init([.font: BitnagilFont(style: .body2, weight: .medium).font])) |
| 56 | + applyTodayButtonConfiguration.baseForegroundColor = .white |
| 57 | + applyTodayButton.configuration = applyTodayButtonConfiguration |
| 58 | + applyTodayButton.addAction( |
| 59 | + UIAction { [weak self] _ in |
| 60 | + self?.dismiss(animated: true) { |
| 61 | + self?.goToRoutineCreationView?(false) |
| 62 | + } |
| 63 | + }, |
| 64 | + for: .touchUpInside) |
| 65 | + |
| 66 | + var applyTomorrowButtonConfiguration = UIButton.Configuration.filled() |
| 67 | + applyTomorrowButtonConfiguration.baseBackgroundColor = BitnagilColor.gray10 |
| 68 | + applyTomorrowButtonConfiguration.background.cornerRadius = 12 |
| 69 | + applyTomorrowButtonConfiguration.attributedTitle = AttributedString( |
| 70 | + "다음 날부터 적용", |
| 71 | + attributes: .init([.font: BitnagilFont(style: .body2, weight: .medium).font])) |
| 72 | + applyTomorrowButtonConfiguration.baseForegroundColor = .white |
| 73 | + applyTomorrowButton.configuration = applyTomorrowButtonConfiguration |
| 74 | + applyTomorrowButton.addAction( |
| 75 | + UIAction { [weak self] _ in |
| 76 | + self?.dismiss(animated: true) { |
| 77 | + self?.goToRoutineCreationView?(false) |
| 78 | + } |
| 79 | + }, |
| 80 | + for: .touchUpInside) |
| 81 | + } |
| 82 | + |
| 83 | + private func configureLayout() { |
| 84 | + view.backgroundColor = .systemBackground |
| 85 | + view.addSubview(mainLabel) |
| 86 | + view.addSubview(subLabel) |
| 87 | + view.addSubview(applyTodayButton) |
| 88 | + view.addSubview(applyTomorrowButton) |
| 89 | + |
| 90 | + mainLabel.snp.makeConstraints { make in |
| 91 | + make.top.equalToSuperview().offset(Layout.mainLabelTopSpacing) |
| 92 | + make.leading.equalToSuperview().offset(Layout.horizontalMargin) |
| 93 | + make.height.equalTo(Layout.mainLabelHeight) |
| 94 | + } |
| 95 | + |
| 96 | + subLabel.snp.makeConstraints { make in |
| 97 | + make.top.equalTo(mainLabel.snp.bottom).offset(Layout.subLabelTopSpacing) |
| 98 | + make.leading.equalToSuperview().offset(Layout.horizontalMargin) |
| 99 | + make.trailing.equalToSuperview().inset(Layout.horizontalMargin) |
| 100 | + } |
| 101 | + |
| 102 | + applyTodayButton.snp.makeConstraints { make in |
| 103 | + make.top.equalTo(subLabel.snp.bottom).offset(Layout.applyTodayButtonTopSpacing) |
| 104 | + make.leading.equalToSuperview().offset(Layout.horizontalMargin) |
| 105 | + make.trailing.equalToSuperview().inset(Layout.horizontalMargin) |
| 106 | + make.height.equalTo(Layout.buttonHeight) |
| 107 | + } |
| 108 | + |
| 109 | + applyTomorrowButton.snp.makeConstraints { make in |
| 110 | + make.top.equalTo(applyTodayButton.snp.bottom).offset(Layout.applyTomorrowButtonTopSpacing) |
| 111 | + make.leading.equalToSuperview().offset(Layout.horizontalMargin) |
| 112 | + make.trailing.equalToSuperview().inset(Layout.horizontalMargin) |
| 113 | + make.height.equalTo(Layout.buttonHeight) |
| 114 | + } |
| 115 | + } |
| 116 | +} |
0 commit comments