Skip to content

Commit 91315e6

Browse files
authored
Merge pull request #71 from TaskarCenterAtUW/feature-ui-fixes
Fixed UI issues in Yes/No and width views
2 parents ce4cd0a + fa56742 commit 91315e6

File tree

4 files changed

+82
-38
lines changed

4 files changed

+82
-38
lines changed

GoInfoGame/GoInfoGame/UI/CustomComponents/WidthView.swift

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,46 @@ enum LengthUnit {
1313
}
1414

1515
struct WidthView: View {
16-
@Binding var feet: Double
17-
@Binding var inches: Double
16+
@Binding var feet: Int
17+
@Binding var inches: Int
1818
@State private var isInputValid: Bool = false
1919
@Binding var isConfirmAlert: Bool
20-
var unit : LengthUnit = .feetInch
20+
var unit: LengthUnit = .feetInch
2121

2222
var body: some View {
23-
if(unit == .feetInch ) {
23+
if unit == .feetInch {
2424
VStack {
2525
HStack {
26-
TextField("Feet", value: $feet, formatter: NumberFormatter(), onEditingChanged: { _ in
27-
validateInput()
28-
})
26+
TextField("Feet", text: Binding(
27+
get: { "\(self.feet)" },
28+
set: {
29+
if let value = NumberFormatter().number(from: $0) {
30+
self.feet = value.intValue
31+
} else {
32+
self.feet = 0
33+
}
34+
validateInput()
35+
}
36+
))
2937
.frame(width: 20)
3038
.padding(.horizontal)
3139
.overlay(Rectangle().frame(height: 1).padding(.top, 25).foregroundColor(.orange), alignment: .bottom)
3240
.textFieldStyle(PlainTextFieldStyle())
3341
.keyboardType(UIKeyboardType.numberPad)
42+
3443
Text("'").font(.title)
35-
36-
TextField("Inches", value: $inches, formatter: NumberFormatter(), onEditingChanged: { _ in
37-
validateInput()
38-
})
44+
45+
TextField("Inches", text: Binding(
46+
get: { "\(self.inches)" },
47+
set: {
48+
if let value = NumberFormatter().number(from: $0) {
49+
self.inches = value.intValue
50+
} else {
51+
self.inches = 0
52+
}
53+
validateInput()
54+
}
55+
))
3956
.frame(width: 20)
4057
.padding(.horizontal)
4158
.overlay(Rectangle().frame(height: 1).padding(.top, 25).foregroundColor(.orange), alignment: .bottom)
@@ -45,39 +62,44 @@ struct WidthView: View {
4562
if isInputValid {
4663
Button() {
4764
isConfirmAlert = true
48-
}label: {
65+
} label: {
4966
Image(systemName: "checkmark.circle.fill")
5067
.font(Font.system(size: 40))
5168
.foregroundColor(.orange)
5269
}
5370
}
5471
}
5572
}
56-
57-
58-
}
59-
else if (unit == .meters) {
60-
HStack(content: {
61-
TextField("Inches", value: $inches, formatter: NumberFormatter(), onEditingChanged: { _ in
62-
validateInput()
63-
})
73+
} else if unit == .meters {
74+
HStack {
75+
TextField("Inches", text: Binding(
76+
get: { "\(self.inches)" },
77+
set: {
78+
if let value = NumberFormatter().number(from: $0) {
79+
self.inches = value.intValue
80+
} else {
81+
self.inches = 0
82+
}
83+
validateInput()
84+
}
85+
))
6486
.frame(width: 20)
6587
.padding(.horizontal)
6688
.overlay(Rectangle().frame(height: 1).padding(.top, 25).foregroundColor(.orange), alignment: .bottom)
6789
.textFieldStyle(PlainTextFieldStyle())
6890
.keyboardType(UIKeyboardType.numberPad)
69-
91+
7092
Text("m").font(.title)
71-
})
93+
}
7294
}
73-
7495
}
96+
7597
private func validateInput() {
7698
isInputValid = feet > 0 && inches >= 0
7799
}
78100
}
79101

80102
#Preview {
81-
WidthView(feet: .constant(0.0), inches: .constant(0.0), isConfirmAlert: .constant(false))
103+
WidthView(feet: .constant(0), inches: .constant(0), isConfirmAlert: .constant(false))
82104

83105
}

GoInfoGame/GoInfoGame/UI/CustomComponents/YesNoView.swift

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,40 @@ struct YesNoView: View {
2727
var body: some View {
2828
HStack(spacing: 0) {
2929
Spacer()
30-
Button {
30+
Button(action: {
3131
action?(.other)
32-
} label: {
32+
}) {
3333
Text(actionBtnLabel)
34-
.foregroundColor(.orange).font(.body)
34+
.foregroundColor(.orange)
35+
.font(.caption)
36+
.fontWeight(.bold)
3537
.frame(maxWidth: .infinity)
3638
}
3739
.frame(minHeight: 50)
38-
Spacer()
40+
Spacer().frame(width: 0)
3941
Divider().background(Color.gray).frame(height: 30)
40-
Button(LocalizedStrings.questGenericHasFeatureYes.localized) {
42+
Button(action: {
4143
action?(.yes)
44+
}) {
45+
Text(LocalizedStrings.questGenericHasFeatureYes.localized)
46+
.foregroundColor(.orange)
47+
.font(.caption)
48+
.fontWeight(.bold)
49+
.frame(maxWidth: 80)
4250
}
43-
.foregroundColor(.orange)
44-
.frame(minWidth: 20, maxWidth: 80, minHeight: 50)
51+
.frame(minHeight: 50)
52+
Spacer().frame(width: 4)
4553
Divider().background(Color.gray).frame(height: 30)
46-
Button {
54+
Button(action: {
4755
action?(.no)
48-
} label: {
56+
}) {
4957
Text(LocalizedStrings.questGenericHasFeatureNo.localized)
50-
.foregroundColor(.orange).font(.body)
58+
.foregroundColor(.orange)
59+
.font(.caption)
60+
.fontWeight(.bold)
5161
.frame(maxWidth: .infinity)
5262
}
63+
.frame(minHeight: 50)
5364
}
5465
}
5566
}

GoInfoGame/GoInfoGame/quests/CrossingIsland/CrossingIslandForm.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ struct CrossingIslandForm: View, QuestForm {
3535
RoundedRectangle(cornerRadius: 10)
3636
.fill(Color.white)
3737
.shadow(color: .gray, radius: 2, x: 0, y: 2))
38+
.padding(.bottom,20)
3839
}.padding()
3940
if isShowingAreYouSure {
4041
CustomSureAlert(alertTitle: LocalizedStrings.questSourceDialogTitle.localized, content: LocalizedStrings.questSourceDialogNote.localized,leftBtnLabel: LocalizedStrings.undoConfirmNegative.localized, rightBtnLabel:LocalizedStrings.questGenericConfirmationYes.localized, isDontShowCheckVisible: true,onCancel: {

GoInfoGame/GoInfoGame/quests/SidewalkWidth/SideWalkWidthForm.swift

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@
66
//
77

88
import SwiftUI
9+
import UIKit
10+
import Combine
11+
912

1013
struct SideWalkWidthForm: View, QuestForm {
1114
typealias AnswerClass = WidthAnswer
1215
@State private var showAlert = false
13-
@State private var feet: Double = 0.0
14-
@State private var inches: Double = 0.0
16+
@State private var feet: Int = 0
17+
@State private var inches: Int = 0
1518
@State private var isConfirmAlert: Bool = false
19+
@State private var isKeyboardVisible: Bool = false // Track keyboard visibility
1620
var action: ((WidthAnswer) -> Void)?
1721

1822
var body: some View {
@@ -26,6 +30,12 @@ struct SideWalkWidthForm: View, QuestForm {
2630
.foregroundColor(.gray)
2731
.padding(.top,10)
2832
WidthView(feet: $feet, inches: $inches, isConfirmAlert: $isConfirmAlert)
33+
.onReceive(Just(isConfirmAlert)) { isAlert in
34+
if isAlert {
35+
// Dismiss the keyboard when confirmation is given
36+
UIApplication.shared.sendAction(#selector(UIResponder.resignFirstResponder), to: nil, from: nil, for: nil)
37+
}
38+
}
2939
Divider()
3040
Button {
3141
showAlert = true
@@ -57,8 +67,8 @@ struct SideWalkWidthForm: View, QuestForm {
5767
action?(answer)
5868
}
5969

60-
func convertFeetToMeter(feet: Double, inches: Double)-> String {
61-
let meters = (feet * 12 + inches) * 0.0254
70+
func convertFeetToMeter(feet: Int, inches: Int)-> String {
71+
let meters = Double((feet * 12 + inches)) * 0.0254
6272
return String(format: "%.2f", meters)
6373
}
6474
}

0 commit comments

Comments
 (0)