@@ -44,10 +44,12 @@ struct ExamView: View {
44
44
}
45
45
. padding ( . horizontal)
46
46
47
- ExamQuestion (
47
+ QuestionView (
48
+ mode: . exam,
48
49
question: questions [ currentQuestionIndex] ,
49
50
selectedChoices: selectedChoices [ questions [ currentQuestionIndex] . id] ?? [ ] ,
50
51
isMultipleResponse: questions [ currentQuestionIndex] . multipleResponse,
52
+ isResultShown: false , // Exam mode does not show result immediately
51
53
onChoiceSelected: { choiceId in
52
54
if questions [ currentQuestionIndex] . multipleResponse {
53
55
if selectedChoices [ questions [ currentQuestionIndex] . id] ? . contains ( choiceId) == true {
@@ -60,6 +62,7 @@ struct ExamView: View {
60
62
}
61
63
}
62
64
)
65
+
63
66
Button ( action: {
64
67
if currentQuestionIndex < questions. count - 1 {
65
68
currentQuestionIndex += 1
@@ -86,7 +89,7 @@ struct ExamView: View {
86
89
}
87
90
. padding ( )
88
91
} else {
89
- Text ( " No que " )
92
+ Text ( " No Questions available! Please download course " )
90
93
}
91
94
}
92
95
. navigationDestination ( isPresented: $navigateToSummary) {
@@ -164,96 +167,3 @@ struct ExamView: View {
164
167
return String ( format: " %02d:%02d " , minutes, seconds)
165
168
}
166
169
}
167
-
168
- struct ExamQuestion : View {
169
- let question : Question
170
- let selectedChoices : Set < UUID > ?
171
- let isMultipleResponse : Bool
172
- let onChoiceSelected : ( UUID ) -> Void
173
-
174
- var body : some View {
175
- ScrollView {
176
- VStack ( alignment: . leading, spacing: 16 ) {
177
- Text ( question. question)
178
- . font ( . system( size: adjustedFontSize ( for: question. question) , weight: . bold) )
179
- . minimumScaleFactor ( 0.5 )
180
- . lineLimit ( nil ) // Allow text to wrap as needed
181
- . fixedSize ( horizontal: false , vertical: true )
182
- . padding ( . horizontal)
183
- . multilineTextAlignment ( . leading) // Justify the text
184
- . lineSpacing ( 2 )
185
-
186
- if let imagePath = question. imagePath,
187
- let image = loadImage ( from: imagePath) {
188
- Image ( uiImage: image)
189
- . resizable ( )
190
- . cornerRadius ( 2 )
191
- . aspectRatio ( contentMode: . fit)
192
- . frame ( maxWidth: . infinity)
193
- . padding ( . horizontal)
194
- }
195
-
196
- if isMultipleResponse {
197
- VStack {
198
- Text ( " Multiple response - Pick \( question. responseCount) " )
199
- . font ( . subheadline)
200
- . multilineTextAlignment ( . center)
201
- . opacity ( 0.7 )
202
- . padding ( . vertical, 5 )
203
- . frame ( minWidth: 0 , maxWidth: . infinity)
204
- }
205
- . background ( Color . gray. opacity ( 0.2 ) )
206
- . cornerRadius ( 10 )
207
- . padding ( . horizontal)
208
- }
209
-
210
- ForEach ( question. choices) { choice in
211
- ExamChoice ( choice: choice, isSelected: selectedChoices? . contains ( choice. id) == true , onChoiceSelected: onChoiceSelected)
212
- }
213
- }
214
- . padding ( )
215
- }
216
- }
217
-
218
- private func loadImage( from imagePath: String ) -> UIImage ? {
219
- let fileManager = FileManager . default
220
- let documentsURL = fileManager. urls ( for: . documentDirectory, in: . userDomainMask) . first!
221
- let imageURL = documentsURL. appendingPathComponent ( imagePath)
222
- return UIImage ( contentsOfFile: imageURL. path)
223
- }
224
-
225
- private func adjustedFontSize( for text: String ) -> CGFloat {
226
- let maxWidth = UIScreen . main. bounds. width - 32
227
- let baseFontSize : CGFloat = 24
228
- let minFontSize : CGFloat = 14
229
-
230
- // Scale the font size based on the text length
231
- let lengthFactor = CGFloat ( text. count) / 100.0
232
- let scaledFontSize = max ( baseFontSize - lengthFactor, minFontSize)
233
-
234
- return scaledFontSize
235
- }
236
- }
237
-
238
- struct ExamChoice : View {
239
- let choice : Choice
240
- let isSelected : Bool
241
- let onChoiceSelected : ( UUID ) -> Void
242
-
243
- var body : some View {
244
- Button ( action: {
245
- onChoiceSelected ( choice. id)
246
- } ) {
247
- Text ( choice. text)
248
- . padding ( )
249
- . frame ( minWidth: 0 , maxWidth: . infinity, alignment: . center)
250
- . multilineTextAlignment ( . center)
251
- }
252
- . background ( isSelected ? Color . gray. opacity ( 0.3 ) : Color . clear)
253
- . cornerRadius ( 10 )
254
- . padding ( . horizontal)
255
- . foregroundColor ( . white)
256
-
257
- Divider ( )
258
- }
259
- }
0 commit comments