-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModeSelectSheet.swift
More file actions
187 lines (163 loc) · 6.24 KB
/
Copy pathModeSelectSheet.swift
File metadata and controls
187 lines (163 loc) · 6.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import SwiftUI
enum PracticeMode {
case script
case prompt
}
struct ModeSelectSheet: View {
@Binding var isPresented: Bool
@State private var selectedMode: PracticeMode = .script
@State private var navigate = false
// 드래그 관련 상태
@State private var dragOffset: CGFloat = 0
@State private var appeared = false
private let primaryIndigo = Color.indigo
private let sheetHeight: CGFloat = UIScreen.main.bounds.height * 0.50
var body: some View {
ZStack(alignment: .bottom) {
// 바깥 영역 탭 → 시트 내려감
Color.black.opacity(0.01)
.ignoresSafeArea()
.onTapGesture { dismiss() }
VStack(spacing: 0) {
// Grabber
RoundedRectangle(cornerRadius: 3)
.fill(Color(UIColor.systemGray4))
.frame(width: 48, height: 5)
.padding(.top, 12)
.padding(.bottom, 8)
// MARK: - Title
Text("Practice mode")
.font(.system(size: 28, weight: .semibold))
.foregroundColor(.primary)
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, 24)
.padding(.top, 15)
.padding(.bottom, 21)
// MARK: - Mode Cards
HStack(spacing: 12) {
ModeCard(
icon: "text.quote",
title: "Script",
description: "Read your lines",
isSelected: selectedMode == .script
) {
withAnimation(.easeInOut(duration: 0.05)) {
selectedMode = .script
}
}
ModeCard(
icon: "bubble.left.and.text.bubble.right.fill",
title: "Prompt",
description: "Speak from hints",
isSelected: selectedMode == .prompt
) {
withAnimation(.easeInOut(duration: 0.05)) {
selectedMode = .prompt
}
}
}
.padding(.horizontal, 24)
.padding(.top, 8)
Spacer()
// SummaryView로 push (시트 닫힘과 동시에)
NavigationLink(
destination: SummaryView(mode: selectedMode),
isActive: $navigate
) { EmptyView() }
// MARK: - Confirm Button
Button(action: {
dismiss()
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
navigate = true
}
}) {
Text("Confirm")
.font(.system(size: 17, weight: .semibold))
.foregroundColor(.white)
.frame(maxWidth: .infinity)
.frame(height: 56)
.background(primaryIndigo)
.clipShape(RoundedRectangle(cornerRadius: 16, style: .continuous))
}
.padding(.horizontal, 24)
.padding(.bottom, 36)
}
.frame(height: sheetHeight)
.frame(maxWidth: .infinity)
.background(Color.white)
.clipShape(RoundedRectangle(cornerRadius: 20, style: .continuous))
.shadow(color: .black.opacity(0.18), radius: 37.5, x: 0, y: -15)
.offset(y: max(dragOffset, 0))
.offset(y: appeared ? 0 : sheetHeight)
.gesture(
DragGesture()
.onChanged { value in dragOffset = value.translation.height }
.onEnded { value in
if value.translation.height > 100 {
dismiss()
} else {
withAnimation(.spring(response: 0.3, dampingFraction: 0.8)) {
dragOffset = 0
}
}
}
)
}
.ignoresSafeArea()
.onAppear {
withAnimation(.spring(response: 0.4, dampingFraction: 0.85)) {
appeared = true
}
}
}
private func dismiss() {
withAnimation(.spring(response: 0.3, dampingFraction: 0.9)) {
appeared = false
}
DispatchQueue.main.asyncAfter(deadline: .now() + 0.3) {
isPresented = false
}
}
}
// MARK: - Mode Card
struct ModeCard: View {
let icon: String
let title: String
let description: String
let isSelected: Bool
let action: () -> Void
private let primaryIndigo = Color.indigo
var body: some View {
Button(action: action) {
VStack(alignment: .center, spacing: 12) {
Image(systemName: icon)
.font(.system(size: 22, weight: .medium))
.foregroundStyle(primaryIndigo)
Text(title)
.font(.system(size: 20, weight: .semibold))
.foregroundColor(.primary)
Text(description)
.font(.system(size: 12, weight: .regular))
.foregroundColor(.black)
.multilineTextAlignment(.center)
.lineSpacing(2)
.fixedSize(horizontal: false, vertical: true)
}
.frame(maxWidth: .infinity)
.frame(height: 190)
.background(
RoundedRectangle(cornerRadius: 16, style: .continuous)
.fill(isSelected ? primaryIndigo.opacity(0.10) : Color(UIColor.systemGray6))
)
.overlay(
RoundedRectangle(cornerRadius: 16, style: .continuous)
.stroke(
isSelected ? primaryIndigo : Color(UIColor.systemGray5),
lineWidth: 1
)
.padding(0.5)
)
}
.buttonStyle(.plain)
}
}