-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContentView.swift
135 lines (117 loc) · 3.99 KB
/
ContentView.swift
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
import SwiftUI
struct Flashcard: Identifiable {
let id = UUID()
var question: String
var answer: String
}
struct NeumorphicButton: View {
var title: String
var action: () -> Void
var body: some View {
Button(action: action) {
Text(title)
.font(.system(size: 20))
.foregroundColor(.white)
.padding(.horizontal, 30)
.padding(.vertical, 15)
.background(Color(.systemGray5))
.cornerRadius(10)
.shadow(color: Color.black.opacity(0.2), radius: 5, x: 5, y: 5)
.shadow(color: Color.white.opacity(0.7), radius: 5, x: -2, y: -2)
}
}
}
struct FlashcardView: View {
@State private var isFlipped = false
var flashcard: Flashcard
var body: some View {
VStack {
Spacer()
if isFlipped {
Text(flashcard.answer)
.font(.system(size: 25))
.padding()
} else {
Text(flashcard.question)
.font(.system(size: 25))
.padding()
}
Spacer()
}
.frame(width: 350, height: 200)
.background(Color(.systemGray5).opacity(isFlipped ? 0.6 : 1.0))
.cornerRadius(10)
.shadow(color: Color.black.opacity(0.2), radius: 10, x: 5, y: 5)
.shadow(color: Color.white.opacity(0.7), radius: 10, x: -5, y: -5)
.onTapGesture {
withAnimation(.easeInOut(duration: 0.3)) {
isFlipped.toggle()
}
}
}
}
struct NewFlashcardForm: View {
@Binding var flashcards: [Flashcard]
@Binding var showingForm: Bool
@State private var newQuestion = ""
@State private var newAnswer = ""
private func addFlashcard() {
flashcards.append(Flashcard(question: newQuestion, answer: newAnswer))
newQuestion = ""
newAnswer = ""
showingForm = false
}
var body: some View {
VStack {
TextField("Question", text: $newQuestion)
.padding()
.background(Color(.systemGray5))
.cornerRadius(10)
.shadow(color: Color.black.opacity(0.2), radius: 5, x: 5, y: 5)
.shadow(color: Color.white.opacity(0.7), radius: 5, x: -2, y: -2)
.padding()
TextField("Answer", text: $newAnswer)
.padding()
.background(Color(.systemGray5))
.cornerRadius(10)
.shadow(color: Color.black.opacity(0.2), radius: 5, x: 5, y: 5)
.shadow(color: Color.white.opacity(0.7), radius: 5, x: -2, y: -2)
.padding()
NeumorphicButton(title: "Add", action: addFlashcard)
.padding()
}
}
}
struct ContentView: View {
@State private var flashcards: [Flashcard] = []
@State private var showingForm = false
private func clearFlashCards() {
flashcards = []
}
var body: some View {
ZStack {
Color(.systemGray6)
.edgesIgnoringSafeArea(.all)
VStack {
ScrollView {
LazyVStack {
Spacer()
ForEach(flashcards) { flashcard in
FlashcardView(flashcard: flashcard)
.padding(.bottom)
}
}
}
HStack {
NeumorphicButton(title: "Clear", action: clearFlashCards)
NeumorphicButton(title: "New Flashcard", action: { showingForm = true })
}
.padding(.horizontal)
.sheet(isPresented: $showingForm) {
NewFlashcardForm(flashcards: $flashcards, showingForm: $showingForm)
}
.padding()
}
}
}
}