|
| 1 | +// |
| 2 | +// RoutineDeleteAlertView.swift |
| 3 | +// Presentation |
| 4 | +// |
| 5 | +// Created by 최정인 on 8/4/25. |
| 6 | +// |
| 7 | + |
| 8 | +import SnapKit |
| 9 | +import UIKit |
| 10 | + |
| 11 | +protocol RoutineDeleteAlertViewDelegate: AnyObject { |
| 12 | + func routineDeleteAlertViewDidTapDeleteAllRoutine(_ sender: RoutineDeleteAlertView) |
| 13 | + func routineDeleteAlertViewDidTapDeleteDailyRoutine(_ sender: RoutineDeleteAlertView) |
| 14 | +} |
| 15 | + |
| 16 | +final class RoutineDeleteAlertView: UIView { |
| 17 | + private enum Layout { |
| 18 | + static let deleteLabelHeight: CGFloat = 48 |
| 19 | + static let deleteLabelTopSpacing: CGFloat = 23 |
| 20 | + static let buttonHorizontalMargin: CGFloat = 23 |
| 21 | + static let buttonHeight: CGFloat = 44 |
| 22 | + static let deleteDailyRoutineButtonTopSpacing: CGFloat = 22 |
| 23 | + static let deleteAllRoutineButtonTopSpacing: CGFloat = 10 |
| 24 | + } |
| 25 | + |
| 26 | + private let contentView = UIView() |
| 27 | + private let deleteLabel = UILabel() |
| 28 | + private let deleteDailyRoutineButton = UIButton() |
| 29 | + private let deleteAllRoutineButton = UIButton() |
| 30 | + weak var delegate: RoutineDeleteAlertViewDelegate? |
| 31 | + |
| 32 | + init() { |
| 33 | + super.init(frame: .zero) |
| 34 | + configureAttribute() |
| 35 | + configureLayout() |
| 36 | + } |
| 37 | + |
| 38 | + required init?(coder: NSCoder) { |
| 39 | + fatalError("init(coder:) has not been implemented") |
| 40 | + } |
| 41 | + |
| 42 | + private func configureAttribute() { |
| 43 | + contentView.backgroundColor = .white |
| 44 | + contentView.layer.masksToBounds = true |
| 45 | + contentView.layer.cornerRadius = 20 |
| 46 | + |
| 47 | + deleteLabel.text = "해당 루틴은\n반복 루틴으로 설정되어 있어요" |
| 48 | + deleteLabel.numberOfLines = 2 |
| 49 | + deleteLabel.textAlignment = .center |
| 50 | + deleteLabel.font = BitnagilFont(style: .body1, weight: .semiBold).font |
| 51 | + deleteLabel.textColor = BitnagilColor.gray10 |
| 52 | + |
| 53 | + var deleteDailyRoutineButtonConfiguration = UIButton.Configuration.filled() |
| 54 | + deleteDailyRoutineButtonConfiguration.baseBackgroundColor = .white |
| 55 | + deleteDailyRoutineButtonConfiguration.background.cornerRadius = 8 |
| 56 | + deleteDailyRoutineButtonConfiguration.attributedTitle = AttributedString( |
| 57 | + "당일만 삭제", |
| 58 | + attributes: .init([.font: BitnagilFont(style: .body2, weight: .medium).font])) |
| 59 | + deleteDailyRoutineButtonConfiguration.baseForegroundColor = BitnagilColor.navy500 |
| 60 | + deleteDailyRoutineButtonConfiguration.background.strokeColor = BitnagilColor.navy500 |
| 61 | + deleteDailyRoutineButtonConfiguration.background.strokeWidth = 1 |
| 62 | + deleteDailyRoutineButton.configuration = deleteDailyRoutineButtonConfiguration |
| 63 | + deleteDailyRoutineButton.addAction( |
| 64 | + UIAction { [weak self] _ in |
| 65 | + guard let self else { return } |
| 66 | + self.delegate?.routineDeleteAlertViewDidTapDeleteDailyRoutine(self) |
| 67 | + }, |
| 68 | + for: .touchUpInside) |
| 69 | + |
| 70 | + var deleteAllRoutineButtonConfiguration = UIButton.Configuration.filled() |
| 71 | + deleteAllRoutineButtonConfiguration.baseBackgroundColor = .white |
| 72 | + deleteAllRoutineButtonConfiguration.background.cornerRadius = 8 |
| 73 | + deleteAllRoutineButtonConfiguration.attributedTitle = AttributedString( |
| 74 | + "전체 루틴 삭제", |
| 75 | + attributes: .init([.font: BitnagilFont(style: .body2, weight: .medium).font])) |
| 76 | + deleteAllRoutineButtonConfiguration.baseForegroundColor = BitnagilColor.navy500 |
| 77 | + deleteAllRoutineButtonConfiguration.background.strokeColor = BitnagilColor.navy500 |
| 78 | + deleteAllRoutineButtonConfiguration.background.strokeWidth = 1 |
| 79 | + deleteAllRoutineButton.configuration = deleteAllRoutineButtonConfiguration |
| 80 | + deleteAllRoutineButton.addAction( |
| 81 | + UIAction { [weak self] _ in |
| 82 | + guard let self else { return } |
| 83 | + self.delegate?.routineDeleteAlertViewDidTapDeleteAllRoutine(self) |
| 84 | + }, |
| 85 | + for: .touchUpInside) |
| 86 | + } |
| 87 | + |
| 88 | + private func configureLayout() { |
| 89 | + addSubview(contentView) |
| 90 | + |
| 91 | + contentView.snp.makeConstraints { make in |
| 92 | + make.edges.equalToSuperview() |
| 93 | + } |
| 94 | + |
| 95 | + [deleteLabel, deleteDailyRoutineButton, deleteAllRoutineButton].forEach { |
| 96 | + contentView.addSubview($0) |
| 97 | + } |
| 98 | + |
| 99 | + deleteLabel.snp.makeConstraints { make in |
| 100 | + make.height.equalTo(Layout.deleteLabelHeight) |
| 101 | + make.centerX.equalToSuperview() |
| 102 | + make.top.equalToSuperview().offset(Layout.deleteLabelTopSpacing) |
| 103 | + } |
| 104 | + |
| 105 | + deleteDailyRoutineButton.snp.makeConstraints { make in |
| 106 | + make.top.equalTo(deleteLabel.snp.bottom).offset(Layout.deleteDailyRoutineButtonTopSpacing) |
| 107 | + make.leading.equalToSuperview().offset(Layout.buttonHorizontalMargin) |
| 108 | + make.trailing.equalToSuperview().inset(Layout.buttonHorizontalMargin) |
| 109 | + make.height.equalTo(Layout.buttonHeight) |
| 110 | + } |
| 111 | + |
| 112 | + deleteAllRoutineButton.snp.makeConstraints { make in |
| 113 | + make.top.equalTo(deleteDailyRoutineButton.snp.bottom).offset(Layout.deleteAllRoutineButtonTopSpacing) |
| 114 | + make.leading.equalToSuperview().offset(Layout.buttonHorizontalMargin) |
| 115 | + make.trailing.equalToSuperview().inset(Layout.buttonHorizontalMargin) |
| 116 | + make.height.equalTo(Layout.buttonHeight) |
| 117 | + } |
| 118 | + } |
| 119 | + |
| 120 | + private func scrollCollectionViewToEnd() { |
| 121 | + |
| 122 | + } |
| 123 | +} |
0 commit comments