Skip to content

Commit 8e78c6d

Browse files
committed
implemented allowing maxLenth of 255 characters in TextEntry filed.
1 parent d33fd6e commit 8e78c6d

File tree

2 files changed

+20
-11
lines changed

2 files changed

+20
-11
lines changed

GoInfoGame/GoInfoGame/quests/LongQuests/Components/QuestOptions.swift

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -224,27 +224,35 @@ private extension QuestOptions {
224224

225225
struct TextEntryView: View {
226226
@Binding var selectedChoice: QuestAnswerChoice?
227-
227+
let maxLenth: Int = 255
228+
229+
private var currentValue: String {
230+
selectedChoice?.value ?? ""
231+
}
232+
228233
var body: some View {
229-
HStack {
230-
TextEditor( text: Binding(
234+
ZStack(alignment: .bottomTrailing) {
235+
TextEditor(text: Binding(
231236
get: { selectedChoice?.value ?? "" },
232237
set: { newValue in
233-
if newValue.isEmpty {
238+
let truncatedValue = String(newValue.prefix(maxLenth))
239+
if truncatedValue.isEmpty {
234240
selectedChoice = nil
235241
} else {
236-
if selectedChoice?.value != newValue {
237-
let answer = QuestAnswerChoice(value: newValue, choiceText: newValue, imageURL: nil, choiceFollowUp: nil)
238-
selectedChoice = answer
239-
}
242+
let answer = QuestAnswerChoice(value: truncatedValue, choiceText: truncatedValue, imageURL: nil, choiceFollowUp: nil)
243+
selectedChoice = answer
240244
}
241245
}
242246
))
243-
.padding(1)
244247
.frame(height: 100)
245-
.textFieldStyle(PlainTextFieldStyle())
246248
.keyboardType(UIKeyboardType.default)
247249
.border(Color.gray)
250+
251+
Text("\(currentValue.count) / \(maxLenth)")
252+
.font(.caption)
253+
.foregroundColor(.gray)
254+
.padding(5)
255+
.background(Color.white.opacity(0.5))
248256
}
249257
}
250258
}

GoInfoGame/GoInfoGame/quests/LongQuests/View/LongQuestView.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ struct LongQuestView: View {
6060
"quest_title": "Additional crossing notes...",
6161
"quest_description": "Add any additional observations you'd like to record about this crossing",
6262
"quest_type": "TextEntry",
63-
"quest_tag": "ext:crossing:description"
63+
"quest_tag": "ext:crossing:description",
64+
"quest_image_url": "https://raw.githubusercontent.com/TaskarCenterAtUW/tdei-tools/main/images/kerb/lowered_landscape.png"
6465
}
6566
"""
6667
if let longQeust = try? JSONDecoder().decode(LongQuest.self, from: jsonString.data(using: .utf8)!) {

0 commit comments

Comments
 (0)