Skip to content

Commit

Permalink
[#74]Feat: 신고하기 팝업 커스텀
Browse files Browse the repository at this point in the history
- ContentView 자체를 커스텀해서 content view를 파라미터로 받아서 팝업에 표시하도록 구현
- left, right -> top, bottom으로 수정
- withSeprator 플래그를 만들어서 구분선 유뮤 구현
- bottom button(마지막 버튼)은 무조건 separator 있음
  • Loading branch information
Minny27 authored and ibcylon committed May 27, 2024
1 parent dd537d7 commit 0839c1f
Show file tree
Hide file tree
Showing 3 changed files with 187 additions and 68 deletions.
100 changes: 100 additions & 0 deletions Projects/Modules/DesignSystem/Src/UIComponent/TFAlertContentView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
//
// TFAlertContentView.swift
// DSKit
//
// Created by SeungMin on 4/29/24.
//

import UIKit

public final class TFAlertContentView: TFBaseView {
private lazy var stackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = 24
return stackView
}()

lazy var titleLabel: UILabel = {
let label = UILabel()
label.text = "어떤 문제가 있나요?"
label.font = UIFont.thtH5Sb
label.textAlignment = .center
label.textColor = DSKitAsset.Color.neutral50.color
label.numberOfLines = 0
return label
}()

let buttonStackView: UIStackView = {
let stackView = UIStackView()
stackView.axis = .vertical
stackView.spacing = 20
return stackView
}()

public let unpleasantPhotoButton: UIButton = {
let button = UIButton()
button.titleLabel?.font = UIFont.thtSubTitle2R
button.setTitle("불괘한 사진", for: .normal)
button.setTitleColor(DSKitAsset.Color.neutral50.color, for: .normal)
button.setBackgroundColor(DSKitAsset.Color.neutral600.color, for: .normal)
return button
}()

public let fakeProfileButton: UIButton = {
let button = UIButton()
button.titleLabel?.font = UIFont.thtSubTitle2R
button.setTitle("허위 프로필", for: .normal)
button.setTitleColor(DSKitAsset.Color.neutral50.color, for: .normal)
button.setBackgroundColor(DSKitAsset.Color.neutral600.color, for: .normal)
return button
}()

public let photoTheftButton: UIButton = {
let button = UIButton()
button.titleLabel?.font = UIFont.thtSubTitle2R
button.setTitle("사진 도용", for: .normal)
button.setTitleColor(DSKitAsset.Color.neutral50.color, for: .normal)
button.setBackgroundColor(DSKitAsset.Color.neutral600.color, for: .normal)
return button
}()

public let profanityButton: UIButton = {
let button = UIButton()
button.titleLabel?.font = UIFont.thtSubTitle2R
button.setTitle("욕설 및 비방", for: .normal)
button.setTitleColor(DSKitAsset.Color.neutral50.color, for: .normal)
button.setBackgroundColor(DSKitAsset.Color.neutral600.color, for: .normal)
return button
}()

public let sharingIllegalFootageButton: UIButton = {
let button = UIButton()
button.titleLabel?.font = UIFont.thtSubTitle2R
button.setTitle("불법 촬영물 공유", for: .normal)
button.setTitleColor(DSKitAsset.Color.neutral50.color, for: .normal)
button.setBackgroundColor(DSKitAsset.Color.neutral600.color, for: .normal)
return button
}()

public override func makeUI() {
addSubview(stackView)
stackView.addArrangedSubviews([titleLabel, buttonStackView])

stackView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

buttonStackView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview()
}

buttonStackView.addArrangedSubviews([
unpleasantPhotoButton,
fakeProfileButton,
photoTheftButton,
profanityButton,
sharingIllegalFootageButton
])
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public enum ReportAction {
var title: String {
switch self {
case .complaints:
return "차단할까요?"
case .block:
return "어떤 문제가 있나요?"
case .block:
return "차단할까요?"
case .withdraw:
return "계정 탈퇴하기"
}
Expand All @@ -32,7 +32,7 @@ public enum ReportAction {
}
}

var leftActionTitle: String {
var topActionTitle: String {
switch self {
case .complaints:
return "차단할까요?"
Expand All @@ -43,7 +43,7 @@ public enum ReportAction {
}
}

var rightActionTitle: String {
var bottomActionTitle: String {
switch self {
default:
return "취소"
Expand Down Expand Up @@ -122,19 +122,21 @@ public final class TFAlertViewController: TFBaseViewController {

init(
titleText: String? = nil,
messageText: String? = nil
messageText: String? = nil,
dimColor: UIColor = DSKitAsset.Color.DimColor.default.color
) {
super.init(nibName: nil, bundle: nil)
self.titleText = titleText
self.messageText = messageText

self.dimView.backgroundColor = dimColor
modalPresentationStyle = .overFullScreen
}

convenience init(contentView: UIView) {
convenience init(contentView: UIView, dimColor: UIColor) {
self.init()

self.contentView = contentView
self.dimView.backgroundColor = dimColor
modalPresentationStyle = .overFullScreen
}

Expand Down Expand Up @@ -164,36 +166,44 @@ public final class TFAlertViewController: TFBaseViewController {

public override func makeUI() {
view.addSubviews([dimView, containerStackView])
containerStackView.addArrangedSubviews([labelStackView, buttonStackView])

dimView.snp.makeConstraints {
$0.edges.equalToSuperview()
if let contentView = contentView {
containerStackView.addArrangedSubview(contentView)
contentView.snp.makeConstraints {
$0.leading.trailing.equalToSuperview()
}
}

containerStackView.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.trailing.equalToSuperview().inset(28)
if let titleLabel = titleLabel {
labelStackView.addArrangedSubview(titleLabel)

containerStackView.addArrangedSubview(labelStackView)
labelStackView.snp.makeConstraints {
$0.width.equalToSuperview()
}

if let messageLabel = messageLabel {
labelStackView.addArrangedSubview(messageLabel)
}
}

labelStackView.snp.makeConstraints {
$0.width.equalToSuperview()
if let lastView = containerStackView.subviews.last {
containerStackView.setCustomSpacing(20, after: lastView)
}

buttonStackView.snp.makeConstraints {
$0.width.equalToSuperview()
}
containerStackView.addArrangedSubview(buttonStackView)

if let titleLabel = titleLabel {
labelStackView.addArrangedSubview(titleLabel)

dimView.snp.makeConstraints {
$0.edges.equalToSuperview()
}

if let messageLabel = messageLabel {
labelStackView.addArrangedSubview(messageLabel)
containerStackView.snp.makeConstraints {
$0.centerY.equalToSuperview()
$0.leading.trailing.equalToSuperview().inset(28)
}

if !labelStackView.subviews.isEmpty {
containerStackView.setCustomSpacing(20, after: labelStackView)
buttonStackView.snp.makeConstraints {
$0.width.equalToSuperview()
}

separatorView.snp.makeConstraints {
Expand All @@ -204,10 +214,11 @@ public final class TFAlertViewController: TFBaseViewController {

public func addActionToButton(
title: String? = nil,
withSeparator: Bool = false,
completion: (() -> Void)? = nil
) {
guard let title = title else { return }

let button = UIButton()
button.titleLabel?.font = UIFont.thtSubTitle2Sb

Expand All @@ -224,12 +235,13 @@ public final class TFAlertViewController: TFBaseViewController {
completion?()
}

if let _ = buttonStackView.subviews.first {
buttonStackView.addArrangedSubview(separatorView)
}
if withSeparator { buttonStackView.addArrangedSubview(separatorView) }

buttonStackView.addArrangedSubview(button)
button.snp.makeConstraints { $0.width.equalToSuperview() }
button.snp.makeConstraints {
$0.width.equalToSuperview()
$0.height.equalTo(21)
}
}

public func addActionToDim(completion: (() -> Void)? = nil) {
Expand Down
83 changes: 45 additions & 38 deletions Projects/Modules/DesignSystem/Src/Util/UIVIewControler+Utils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,71 +10,78 @@ import UIKit
extension UIViewController {
public func showAlert(title: String? = nil,
message: String? = nil,
attributedMessage: NSAttributedString? = nil,
leftActionTitle: String? = "확인",
rightActionTitle: String = "취소",
leftActionCompletion: (() -> Void)? = nil,
rightActionCompletion: (() -> Void)? = nil,
topActionTitle: String? = "확인",
bottomActionTitle: String = "취소",
dimColor: UIColor = DSKitAsset.Color.DimColor.default.color,
topActionCompletion: (() -> Void)? = nil,
bottomActionCompletion: (() -> Void)? = nil,
dimActionCompletion: (() -> Void)? = nil) {
let alertViewController = TFAlertViewController(titleText: title,
messageText: message)
messageText: message,
dimColor: dimColor)
showAlert(alertViewController: alertViewController,
leftActionTitle: leftActionTitle,
rightActionTitle: rightActionTitle,
leftActionCompletion: leftActionCompletion,
rightActionCompletion: rightActionCompletion,
topActionTitle: topActionTitle,
bottomActionTitle: bottomActionTitle,
topActionCompletion: topActionCompletion,
bottomActionCompletion: bottomActionCompletion,
dimActionCompletion: dimActionCompletion)
}

public func showAlert(contentView: UIView,
leftActionTitle: String? = "확인",
rightActionTitle: String = "취소",
leftActionCompletion: (() -> Void)? = nil,
rightActionCompletion: (() -> Void)? = nil,
topActionTitle: String? = "확인",
bottomActionTitle: String = "취소",
dimColor: UIColor = DSKitAsset.Color.DimColor.default.color,
topActionCompletion: (() -> Void)? = nil,
bottomActionCompletion: (() -> Void)? = nil,
dimActionCompletion: (() -> Void)? = nil) {
let alertViewController = TFAlertViewController(contentView: contentView)
let alertViewController = TFAlertViewController(contentView: contentView,
dimColor: dimColor)

showAlert(alertViewController: alertViewController,
leftActionTitle: leftActionTitle,
rightActionTitle: rightActionTitle,
leftActionCompletion: leftActionCompletion,
rightActionCompletion: rightActionCompletion,
topActionTitle: topActionTitle,
bottomActionTitle: bottomActionTitle,
topActionCompletion: topActionCompletion,
bottomActionCompletion: bottomActionCompletion,
dimActionCompletion: dimActionCompletion)
}

public func showAlert(action: ReportAction,
leftActionCompletion: (() -> Void)? = nil,
rightActionCompletion: (() -> Void)? = nil,
dimColor: UIColor = DSKitAsset.Color.DimColor.default.color,
topActionCompletion: (() -> Void)? = nil,
bottomActionCompletion: (() -> Void)? = nil,
dimActionCompletion: (() -> Void)? = nil) {
let alertViewController = TFAlertViewController(
titleText: action.title,
messageText: action.message
)
let alertViewController = TFAlertViewController(titleText: action.title,
messageText: action.message,
dimColor: dimColor)

showAlert(alertViewController: alertViewController,
leftActionTitle: action.leftActionTitle,
rightActionTitle: action.rightActionTitle,
leftActionCompletion: leftActionCompletion,
rightActionCompletion: rightActionCompletion,
topActionTitle: action.topActionTitle,
bottomActionTitle: action.bottomActionTitle,
topActionCompletion: topActionCompletion,
bottomActionCompletion: bottomActionCompletion,
dimActionCompletion: dimActionCompletion)
}

private func showAlert(alertViewController: TFAlertViewController,
leftActionTitle: String?,
rightActionTitle: String,
leftActionCompletion: (() -> Void)?,
rightActionCompletion: (() -> Void)?,
topActionTitle: String?,
bottomActionTitle: String,
topActionCompletion: (() -> Void)?,
bottomActionCompletion: (() -> Void)?,
dimActionCompletion: (() -> Void)?) {
alertViewController.addActionToButton(title: leftActionTitle) {
alertViewController.dismiss(animated: false, completion: leftActionCompletion)
alertViewController.addActionToButton(title: topActionTitle) {
alertViewController.dismiss(animated: false,
completion: topActionCompletion)
}

alertViewController.addActionToButton(title: rightActionTitle) {
alertViewController.dismiss(animated: false, completion: rightActionCompletion)
alertViewController.addActionToButton(title: bottomActionTitle,
withSeparator: true) {
alertViewController.dismiss(animated: false,
completion: bottomActionCompletion)
}

alertViewController.addActionToDim() {
alertViewController.dismiss(animated: false, completion: dimActionCompletion)
alertViewController.dismiss(animated: false,
completion: dimActionCompletion)
}

present(alertViewController, animated: false, completion: nil)
Expand Down

0 comments on commit 0839c1f

Please sign in to comment.