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: giveup Alert custom Alert으로 변경 #102

Merged
merged 1 commit into from
Oct 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Pickle/Pickle.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
96CF08EE2AD933A400648B59 /* DotCircleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96CF08ED2AD933A400648B59 /* DotCircleView.swift */; };
A0052FB42ACD48A3005B3263 /* TimerReportView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A0052FB32ACD48A3005B3263 /* TimerReportView.swift */; };
A072B9482AE0460E001C3DAF /* TimerViewModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = A072B9472AE0460E001C3DAF /* TimerViewModel.swift */; };
A08EF5412AE265C900349A58 /* GiveupAlert.swift in Sources */ = {isa = PBXBuildFile; fileRef = A08EF5402AE265C900349A58 /* GiveupAlert.swift */; };
B063F5CE2ADD02DB008EF304 /* HealthKitStore.swift in Sources */ = {isa = PBXBuildFile; fileRef = B063F5CD2ADD02DB008EF304 /* HealthKitStore.swift */; };
B0C158DA2AC1647D003B00E6 /* MissionStyleView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C158D92AC1647D003B00E6 /* MissionStyleView.swift */; };
B0C158DC2AC1759D003B00E6 /* MissionSettingView.swift in Sources */ = {isa = PBXBuildFile; fileRef = B0C158DB2AC1759D003B00E6 /* MissionSettingView.swift */; };
Expand Down Expand Up @@ -203,6 +204,7 @@
96CF08ED2AD933A400648B59 /* DotCircleView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DotCircleView.swift; sourceTree = "<group>"; };
A0052FB32ACD48A3005B3263 /* TimerReportView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerReportView.swift; sourceTree = "<group>"; };
A072B9472AE0460E001C3DAF /* TimerViewModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TimerViewModel.swift; sourceTree = "<group>"; };
A08EF5402AE265C900349A58 /* GiveupAlert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = GiveupAlert.swift; sourceTree = "<group>"; };
B063F5CD2ADD02DB008EF304 /* HealthKitStore.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HealthKitStore.swift; sourceTree = "<group>"; };
B0B5E6BB2ADA5A360096F677 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist; path = Info.plist; sourceTree = "<group>"; };
B0B5E6BC2ADA5B820096F677 /* Pickle.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = Pickle.entitlements; sourceTree = "<group>"; };
Expand Down Expand Up @@ -532,6 +534,7 @@
96A1E4AA2AD4DD0A001B2960 /* FaildAlert.swift */,
965C9BEA2ADBAF7E0015ABBE /* PizzaAlert.swift */,
B0C74AE72ACFC7A100A14A8B /* RewardAlert.swift */,
A08EF5402AE265C900349A58 /* GiveupAlert.swift */,
);
path = Alert;
sourceTree = "<group>";
Expand Down Expand Up @@ -823,6 +826,7 @@
965C9B9A2ADA866E0015ABBE /* PizzaSelectedView.swift in Sources */,
960C41A62ACEF4F1009A0093 /* Repository+Extension.swift in Sources */,
B0C158DC2AC1759D003B00E6 /* MissionSettingView.swift in Sources */,
A08EF5412AE265C900349A58 /* GiveupAlert.swift in Sources */,
960C419D2ACE8276009A0093 /* TodoStore.swift in Sources */,
960C418C2ACE3969009A0093 /* RealmStore.swift in Sources */,
96A1E4AB2AD4DD0A001B2960 /* FaildAlert.swift in Sources */,
Expand Down
154 changes: 154 additions & 0 deletions Pickle/Pickle/Global/Common/Alert/GiveupAlert.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
//
// GiveupAlert.swift
// Pickle
//
// Created by 여성은 on 2023/10/20.
//

import SwiftUI

extension View {
func showGiveupAlert (
isPresented: Binding<Bool>,
title: String,
contents: String,
primaryButtonTitle: String,
primaryAction: @escaping (Double) -> Void,
primaryparameter: TimeInterval,
secondaryButton: String,
secondaryAction: @escaping () -> Void
) -> some View {
return modifier(
GiveupAlertModifier(isPresented: isPresented,
title: title,
contents: contents,
primaryButtonTitle: primaryButtonTitle,
primaryAction: primaryAction,
primaryparameter: primaryparameter,
secondaryButton: secondaryButton,
secondaryAction: secondaryAction)
)
}
}

struct GiveupAlertModifier: ViewModifier {

@Binding var isPresented: Bool

let title: String
let contents: String
let primaryButtonTitle: String
let primaryAction: (Double) -> Void
let primaryparameter: TimeInterval
let secondaryButton: String
let secondaryAction: () -> Void

func body(content: Content) -> some View {
ZStack {
content
ZStack {
if isPresented {
Rectangle()
.fill(.primary.opacity(0.3))
.blur(radius: isPresented ? 2 : 0)
.ignoresSafeArea()
.onTapGesture {
self.isPresented = false // 외부 영역 터치 시 내려감
}

GiveupAlert(isPresented: $isPresented,
title: title,
contents: contents,
primaryButtonTitle: primaryButtonTitle,
primaryAction: primaryAction,
primaryparameter: primaryparameter,
secondaryButton: secondaryButton,
secondaryAction: secondaryAction)
.transition(.move(edge: .bottom).combined(with: .opacity))
}
}
.animation(
isPresented
? .spring(response: 0.3)
: .none,
value: isPresented
)
}
}
}

struct GiveupAlert: View {

@Binding var isPresented: Bool

let title: String
let contents: String
let primaryButtonTitle: String
let primaryAction: (_ timeInterval: TimeInterval) -> Void
let primaryparameter: TimeInterval
let secondaryButton: String
let secondaryAction: () -> Void

var body: some View {
VStack(alignment: .center, spacing: 30) {
Text(title)
.font(.pizzaRegularTitle)

Text(contents)
.minimumScaleFactor(0.8)
.lineLimit(1)
.font(.pizzaBody)
.foregroundColor(.secondary)

HStack {

Button {
secondaryAction()
isPresented = false
} label: {
Text(secondaryButton)
.foregroundColor(.textGray)
.frame(maxWidth: .infinity)
.padding(.vertical, 2)
}

Button {
primaryAction(primaryparameter)
isPresented = false
} label: {
Text(primaryButtonTitle)
.foregroundColor(.pepperoniRed)
.frame(maxWidth: .infinity)
.padding(.vertical, 2)
}
}
.font(.pizzaBoldButton15)
.buttonStyle(.borderedProminent)
.tint(.lightGray)

}
.padding(.horizontal, 25)
.frame(width: .screenWidth * 0.85, height: .screenWidth * 0.5)
.background(
RoundedRectangle(cornerRadius: 30)
.stroke(.black.opacity(0.5))
.background(
RoundedRectangle(cornerRadius: 30)
.fill(.primary)
.colorInvert()
)
)
}
}

#Preview {
Text("포기하기 alert Test")
.modifier(GiveupAlertModifier(isPresented: .constant(true),
title: "포기하시겠어요?",
contents: "지금 포기하면 피자조각을 얻지 못해요",
primaryButtonTitle: "포기하기",
primaryAction: { _ in },
primaryparameter: 20,
secondaryButton: "돌아가기",
secondaryAction: { }))
}
4 changes: 4 additions & 0 deletions Pickle/Pickle/Global/Extension/Color.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ extension Color {
return Color.init(hex: 0xE62E2E)
}

static var pepperoniRed: Color {
return Color.init(hex: 0xFF4145)
}

}

extension Color {
Expand Down
2 changes: 2 additions & 0 deletions Pickle/Pickle/Global/Extension/Font.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ extension Font {
static let pizzaStoreSmall = makeFont(name: "NanumSquareNeo-aLt", size: 14, style: .body)
static let pizzaTimerNum = makeFont(name: "LOTTERIACHAB", size: 44, style: .title)
static let pizzaRegularTitle = makeFont(name: "NanumSquareNeo-cBd", size: 24, style: .title)
static let pizzaBoldTitle = makeFont(name: "NanumSquareNeo-dEb", size: 24, style: .title)
static let pizzaBoldButtonTitle = makeFont(name: "NanumSquareNeo-cBd", size: 14, style: .title)
static let pizzaBoldButton15 = makeFont(name: "NanumSquareNeo-cBd", size: 14, style: .title)

static let pizzaFootnote = Font.system(size: 13, weight: .regular)
static let pizzaFootnoteBold = Font.system(size: 13, weight: .bold)
Expand Down
47 changes: 32 additions & 15 deletions Pickle/Pickle/Screen/Home/TimerView/TimerView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ struct TimerView: View {
@State private var isStart: Bool = true // 3,2,1,시작 보여줄지 아닐지
@State private var isShowingReportSheet: Bool = false
@State private var isComplete: Bool = false // '완료'버튼 누를때 시간 멈추기 확인용
@State private var showingAlert: Bool = false

@Binding var isShowingTimerView: Bool


var body: some View {
VStack {
// 멘트부분
Expand Down Expand Up @@ -155,7 +158,8 @@ struct TimerView: View {
Button(action: {
isComplete = true
isGiveupSign = true
isShowGiveupAlert = true // 포기 alert띄우기
// isShowGiveupAlert = true // 포기 alert띄우기
showingAlert = true
}, label: {
Text("포기")
.font(.pizzaHeadline)
Expand Down Expand Up @@ -184,24 +188,36 @@ struct TimerView: View {
startTodo()
}
.navigationBarBackButtonHidden(true)
.alert(isPresented: $isShowGiveupAlert) {
Alert(title: Text("정말 포기하시겠습니까?"),
message: Text("지금 포기하면 피자조각을 얻지 못해요"),
primaryButton: .destructive(Text("포기하기")) {
// 포기하기 함수
print(timerVM.spendTime)
updateGiveup(spendTime: timerVM.spendTime)
isShowingReportSheet = true
}, secondaryButton: .cancel(Text("취소")) {
isGiveupSign = false
isComplete = false
})

}
// .alert(isPresented: $isShowGiveupAlert) {
// Alert(title: Text("정말 포기하시겠습니까?"),
// message: Text("지금 포기하면 피자조각을 얻지 못해요"),
// primaryButton: .destructive(Text("포기하기")) {
// // 포기하기 함수
// print(timerVM.spendTime)
// updateGiveup(spendTime: timerVM.spendTime)
// isShowingReportSheet = true
// }, secondaryButton: .cancel(Text("취소")) {
// isGiveupSign = false
// isComplete = false
// })
//
// }
.sheet(isPresented: $isShowingReportSheet) {
TimerReportView(isShowingReportSheet: $isShowingReportSheet, isComplete: $isComplete, isShowingTimerView: $isShowingTimerView, todo: todo)
.interactiveDismissDisabled()
}
.showGiveupAlert(isPresented: $showingAlert,
title: "포기하시겠어요?",
contents: "지금 포기하면 피자조각을 얻지 못해요",
primaryButtonTitle: "포기하기",
primaryAction: updateGiveup,
primaryparameter: timerVM.spendTime,
secondaryButton: "돌아가기",
secondaryAction: giveupSecondary)
}
func giveupSecondary() {
isGiveupSign = false
isComplete = false
}
// 시작 시 시간시간 업데이트, status ongoing으로
func updateStart() {
Expand All @@ -225,6 +241,7 @@ struct TimerView: View {
status: .giveUp)
todoStore.update(todo: todo)
timerVM.timerVMreset()
isShowingReportSheet = true
}
// 완료 + 피자겟챠
func updateDone(spendTime: TimeInterval) {
Expand Down