Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feat] #68 - CustomAlert창 구현 #76

Merged
merged 14 commits into from
Jul 15, 2022
Merged
44 changes: 44 additions & 0 deletions HealthFoodMe/HealthFoodMe.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@
A93252B7287F3272001EDF50 /* Scrap.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A93252B6287F3272001EDF50 /* Scrap.storyboard */; };
A93252BA287F3E73001EDF50 /* ScrapEmptyView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252B9287F3E73001EDF50 /* ScrapEmptyView.swift */; };
A93252BD287F52E4001EDF50 /* ScrapDataModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252BC287F52E4001EDF50 /* ScrapDataModel.swift */; };
A93252C628808B82001EDF50 /* ReviewDeleteAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252C528808B82001EDF50 /* ReviewDeleteAlertView.swift */; };
A93252CD28808BE2001EDF50 /* LogoutAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252CC28808BE2001EDF50 /* LogoutAlertView.swift */; };
A93252CF2880913F001EDF50 /* HelfmeAlertVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252CE2880913F001EDF50 /* HelfmeAlertVC.swift */; };
A93252D428809BBC001EDF50 /* WithdrawalAlertView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A93252D328809BBC001EDF50 /* WithdrawalAlertView.swift */; };
A93252E22880CBB9001EDF50 /* HelfmeAlert.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A93252E12880CBB9001EDF50 /* HelfmeAlert.storyboard */; };
A938BB8E287D221200B8DE07 /* Search.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A938BB8D287D221200B8DE07 /* Search.storyboard */; };
A938BB90287D222800B8DE07 /* MainDetail.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A938BB8F287D222800B8DE07 /* MainDetail.storyboard */; };
A9525F712873E1750065EB1D /* SearchVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9525F702873E1750065EB1D /* SearchVC.swift */; };
Expand Down Expand Up @@ -208,6 +213,11 @@
A93252B6287F3272001EDF50 /* Scrap.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Scrap.storyboard; sourceTree = "<group>"; };
A93252B9287F3E73001EDF50 /* ScrapEmptyView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrapEmptyView.swift; sourceTree = "<group>"; };
A93252BC287F52E4001EDF50 /* ScrapDataModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScrapDataModel.swift; sourceTree = "<group>"; };
A93252C528808B82001EDF50 /* ReviewDeleteAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReviewDeleteAlertView.swift; sourceTree = "<group>"; };
A93252CC28808BE2001EDF50 /* LogoutAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LogoutAlertView.swift; sourceTree = "<group>"; };
A93252CE2880913F001EDF50 /* HelfmeAlertVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HelfmeAlertVC.swift; sourceTree = "<group>"; };
A93252D328809BBC001EDF50 /* WithdrawalAlertView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WithdrawalAlertView.swift; sourceTree = "<group>"; };
A93252E12880CBB9001EDF50 /* HelfmeAlert.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = HelfmeAlert.storyboard; sourceTree = "<group>"; };
A938BB8D287D221200B8DE07 /* Search.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Search.storyboard; sourceTree = "<group>"; };
A938BB8F287D222800B8DE07 /* MainDetail.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = MainDetail.storyboard; sourceTree = "<group>"; };
A9525F702873E1750065EB1D /* SearchVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchVC.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -580,6 +590,34 @@
path = Model;
sourceTree = "<group>";
};
A93252BE288086BA001EDF50 /* HelpmeAlerts */ = {
isa = PBXGroup;
children = (
A93252D72880B13A001EDF50 /* VC */,
A93252D028809144001EDF50 /* Views */,
);
path = HelpmeAlerts;
sourceTree = "<group>";
};
A93252D028809144001EDF50 /* Views */ = {
isa = PBXGroup;
children = (
A93252CC28808BE2001EDF50 /* LogoutAlertView.swift */,
A93252C528808B82001EDF50 /* ReviewDeleteAlertView.swift */,
A93252D328809BBC001EDF50 /* WithdrawalAlertView.swift */,
);
path = Views;
sourceTree = "<group>";
};
A93252D72880B13A001EDF50 /* VC */ = {
isa = PBXGroup;
children = (
A93252CE2880913F001EDF50 /* HelfmeAlertVC.swift */,
A93252E12880CBB9001EDF50 /* HelfmeAlert.storyboard */,
);
path = VC;
sourceTree = "<group>";
};
A9525F6A2873DCD30065EB1D /* SearchScene */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -1182,6 +1220,7 @@
EBF66A9F287227F500DE0ED1 /* Common */ = {
isa = PBXGroup;
children = (
A93252BE288086BA001EDF50 /* HelpmeAlerts */,
EB033E82287B5B6E00C48FB9 /* UI Components */,
EBF66AA0287227F500DE0ED1 /* Base */,
);
Expand Down Expand Up @@ -1427,6 +1466,7 @@
3B089C4B287D877F00DA80B9 /* GodoB.otf in Resources */,
A938BB90287D222800B8DE07 /* MainDetail.storyboard in Resources */,
695758BD287DA4CD00E36789 /* ReviewWrite.storyboard in Resources */,
A93252E22880CBB9001EDF50 /* HelfmeAlert.storyboard in Resources */,
3BCC442028745FE500661A12 /* SocialLogin.storyboard in Resources */,
3B089C4A287D877B00DA80B9 /* GodoB.ttf in Resources */,
3B0B25562876BBE400950539 /* Pretendard-Regular.otf in Resources */,
Expand Down Expand Up @@ -1538,6 +1578,7 @@
EBF66AE4287227F500DE0ED1 /* HeaderType.swift in Sources */,
FD58291A287DC39A00CE62E8 /* mapContainerViewDelegateProxy.swift in Sources */,
EBF66ADB287227F500DE0ED1 /* LaunchInstructor.swift in Sources */,
A93252D428809BBC001EDF50 /* WithdrawalAlertView.swift in Sources */,
EBF66B01287227F500DE0ED1 /* PostDetail.swift in Sources */,
EBF66ABC287227F500DE0ED1 /* UserDefaults+.swift in Sources */,
695758C3287DF04400E36789 /* AddPhotoCVC.swift in Sources */,
Expand All @@ -1558,8 +1599,10 @@
EB6A44D228737CC400749582 /* MainDetailRepository.swift in Sources */,
FDC1028B2880B133001F0125 /* CTAButton.swift in Sources */,
EBF66B0C2872B4FE00DE0ED1 /* StoryboardLiterals.swift in Sources */,
A93252CD28808BE2001EDF50 /* LogoutAlertView.swift in Sources */,
EBF66AF7287227F500DE0ED1 /* manageObserverAction.swift in Sources */,
EBF66B05287227F500DE0ED1 /* GeneralResponse.swift in Sources */,
A93252CF2880913F001EDF50 /* HelfmeAlertVC.swift in Sources */,
EBF66AC1287227F500DE0ED1 /* UIStackView+.swift in Sources */,
EBF66AF1287227F500DE0ED1 /* ShowToast.swift in Sources */,
EBF66AC4287227F500DE0ED1 /* UIButton+.swift in Sources */,
Expand Down Expand Up @@ -1602,6 +1645,7 @@
EBF66AFD287227F500DE0ED1 /* calculateTopInset.swift in Sources */,
EBF66ADE287227F500DE0ED1 /* HomeRouter.swift in Sources */,
EBF66ACF287227F500DE0ED1 /* Result+.swift in Sources */,
A93252C628808B82001EDF50 /* ReviewDeleteAlertView.swift in Sources */,
EBF66AD7287227F500DE0ED1 /* Presentable.swift in Sources */,
A932527E287DD261001EDF50 /* SearchResultVC.swift in Sources */,
EBD19275287F256000EA053E /* EncodeURLKorean.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class ModuleFactory: ModuleFactoryProtocol {

return vc
}

// MARK: - HelfmeAlert
func makeHelfmeAlertVC() -> HelfmeAlertVC {
let vc = HelfmeAlertVC.controllerFromStoryboard(.helfmeAlert)

return vc
}

// MARK: - Plan

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,24 @@ extension UIViewController {
func dismissKeyboard() {
view.endEditing(true)
}

func makeAlert(alertType: AlertType = .logoutAlert,
title: String?,
subtitle: String?,
okAction: (() -> Void)? ) {

let alertVC = ModuleFactory.resolve().makeHelfmeAlertVC()

alertVC.alertType = alertType
if let title = title {
alertVC.alertTitle = title
}
if let subtitle = subtitle {
alertVC.alertContent = subtitle
}
alertVC.okAction = okAction
alertVC.modalTransitionStyle = .crossDissolve
alertVC.modalPresentationStyle = .overCurrentContext
present(alertVC, animated: true)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ enum Storyboards: String {
case search = "Search"
case searchResult = "SearchResult"
case scrap = "Scrap"
case helfmeAlert = "HelfmeAlert"

case menuTab = "MenuTab"
case reviewWrite = "ReviewWrite"
Expand Down
25 changes: 25 additions & 0 deletions HealthFoodMe/HealthFoodMe/Global/Literals/StringLiterals.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,29 @@ struct I18N {
static let dietStore = "다이어터도 즐길 수 있는 식당"
static let goScrap = "스크랩하러 가기"
}

struct HelfmeAlert {
static let logout = "정말 로그아웃 하시겠어요?"
static let logoutContent =
"""
로그아웃 시 헬푸미의 업데이트 내용을
보실 수 없습니다.
"""
static let yes = "네"
static let no = "아니요"

static let reviewDelete =
"""
작성한 리뷰를
삭제하실 건가요?
"""

static let withdrawal = "정말로 탈퇴하실건가요?"
static let withdrawalContent =
"""
탈퇴 시 헬푸미의 새로운 정보를
얻을 수 없습니다.
"""
static let withdrawalYes = "네 탈퇴할게요"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="20037" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="Y6W-OH-hqX">
<device id="retina6_1" orientation="portrait" appearance="light"/>
<dependencies>
<deployment identifier="iOS"/>
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="20020"/>
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
<capability name="System colors in document resources" minToolsVersion="11.0"/>
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
</dependencies>
<scenes>
<!--Helfme AlertVC-->
<scene sceneID="s0d-6b-0kx">
<objects>
<viewController storyboardIdentifier="HelfmeAlertVC" id="Y6W-OH-hqX" customClass="HelfmeAlertVC" customModule="HealthFoodMe" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" contentMode="scaleToFill" id="5EZ-qb-Rvc">
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<viewLayoutGuide key="safeArea" id="vDu-zF-Fre"/>
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
</view>
</viewController>
<placeholder placeholderIdentifier="IBFirstResponder" id="Ief-a0-LHa" userLabel="First Responder" customClass="UIResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="-25" y="56"/>
</scene>
</scenes>
<resources>
<systemColor name="systemBackgroundColor">
<color white="1" alpha="1" colorSpace="custom" customColorSpace="genericGamma22GrayColorSpace"/>
</systemColor>
</resources>
</document>
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
//
// HelfmeAlertVC.swift
// HealthFoodMe
//
// Created by 김영인 on 2022/07/15.
//

import UIKit

import SnapKit

enum AlertType {
case logoutAlert
case deleteReviewAlert
case withdrawalAlert
}

final class HelfmeAlertVC: UIViewController {

// MARK: - Properties

let width = UIScreen.main.bounds.width
var alertType: AlertType = .logoutAlert
var alertTitle: String?
var alertContent: String?
var okAction: (() -> Void)?

// MARK: - UI Components

private let logoutAlertView: LogoutAlertView = {
let view = LogoutAlertView()
view.layer.cornerRadius = 15
return view
}()

private let reviewDeleteAlertView: ReviewDeleteAlertView = {
let view = ReviewDeleteAlertView()
view.layer.cornerRadius = 15
return view
}()

private let withdrawalAlertView: WithdrawalAlertView = {
let view = WithdrawalAlertView()
view.layer.cornerRadius = 15
return view
}()

// MARK: - View Life Cycle

override func viewDidLoad() {
super.viewDidLoad()
setAlert()
setUI()
setLayout()
setDelegate()
}
}

// MARK: - Methods

extension HelfmeAlertVC {
private func setAlert() {
switch alertType {
case .logoutAlert:
logoutAlertView.setData(title: alertTitle, subtitle: alertContent)
setAlertView(logout: false, deleteReview: true, withdrawal: true)
case .deleteReviewAlert:
reviewDeleteAlertView.setData(title: alertTitle)
setAlertView(logout: true, deleteReview: false, withdrawal: true)
case .withdrawalAlert:
withdrawalAlertView.setData(title: alertTitle, subtitle: alertContent)
setAlertView(logout: true, deleteReview: true, withdrawal: false)
}
}

private func setAlertView(logout: Bool, deleteReview: Bool, withdrawal: Bool) {
logoutAlertView.isHidden = logout
reviewDeleteAlertView.isHidden = deleteReview
withdrawalAlertView.isHidden = withdrawal
}

private func setUI() {
view.backgroundColor = .black.withAlphaComponent(0.4)
}

private func setLayout() {
view.addSubviews(logoutAlertView,
reviewDeleteAlertView,
withdrawalAlertView)

view.addSubviews(withdrawalAlertView)

logoutAlertView.snp.makeConstraints {
let logoutWidth = width * (288/375)
$0.center.equalToSuperview()
$0.width.equalTo(logoutWidth)
$0.height.equalTo(logoutWidth * (241/288))
}

reviewDeleteAlertView.snp.makeConstraints {
let reviewDeleteWidth = width * (288/375)
$0.center.equalToSuperview()
$0.width.equalTo(reviewDeleteWidth)
$0.height.equalTo(reviewDeleteWidth * (223/288))
}

withdrawalAlertView.snp.makeConstraints {
let withdrawalWidth = width * (288/375)
$0.center.equalToSuperview()
$0.width.equalTo(withdrawalWidth)
$0.height.equalTo(withdrawalWidth * (222/288))
}
}

private func setDelegate() {
logoutAlertView.delegate = self
reviewDeleteAlertView.delegate = self
withdrawalAlertView.delegate = self
}

private func emptyActions() {

}
}

// MARK: - AlertDelegate

extension HelfmeAlertVC: AlertDelegate {
func alertDidTap() {
dismiss(animated: false) {
(self.okAction ?? self.emptyActions)()
}
}

func alertDismiss() {
dismiss(animated: true)
}
}
Loading