Skip to content

Commit dcab1c2

Browse files
stephencelismluisbrown
authored andcommitted
Stop using Form in Tic-Tac-Toe example (#448)
1 parent 0dc69e0 commit dcab1c2

File tree

3 files changed

+68
-61
lines changed

3 files changed

+68
-61
lines changed

Examples/TicTacToe/Sources/Views-SwiftUI/LoginSwiftView.swift

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,56 +34,59 @@ public struct LoginView: View {
3434

3535
public var body: some View {
3636
WithViewStore(self.store.scope(state: { $0.view }, action: LoginAction.view)) { viewStore in
37-
VStack {
38-
Form {
39-
Section(
40-
header: Text(
41-
"""
37+
ScrollView {
38+
VStack(spacing: 16) {
39+
Text(
40+
"""
4241
To login use any email and "password" for the password. If your email contains the \
4342
characters "2fa" you will be taken to a two-factor flow, and on that screen you can \
4443
use "1234" for the code.
4544
"""
46-
)
47-
) { EmptyView() }
45+
)
4846

49-
Section(header: Text("Email")) {
47+
VStack(alignment: .leading) {
48+
Text("Email")
5049
TextField(
5150
5251
text: viewStore.binding(get: { $0.email }, send: ViewAction.emailChanged)
5352
)
5453
.autocapitalization(.none)
5554
.keyboardType(.emailAddress)
5655
.textContentType(.emailAddress)
56+
.textFieldStyle(RoundedBorderTextFieldStyle())
5757
}
58-
Section(header: Text("Password")) {
58+
59+
VStack(alignment: .leading) {
60+
Text("Password")
5961
SecureField(
6062
"••••••••",
6163
text: viewStore.binding(get: { $0.password }, send: ViewAction.passwordChanged)
6264
)
65+
.textFieldStyle(RoundedBorderTextFieldStyle())
6366
}
64-
Section {
65-
NavigationLink(
66-
destination: IfLetStore(
67-
self.store.scope(state: { $0.twoFactor }, action: LoginAction.twoFactor),
68-
then: TwoFactorView.init(store:)
69-
),
70-
isActive: viewStore.binding(
71-
get: { $0.isTwoFactorActive },
72-
send: { $0 ? .loginButtonTapped : .twoFactorDismissed }
73-
)
74-
) {
75-
Text("Log in")
7667

77-
if viewStore.isActivityIndicatorVisible {
78-
ActivityIndicator()
79-
}
68+
NavigationLink(
69+
destination: IfLetStore(
70+
self.store.scope(state: { $0.twoFactor }, action: LoginAction.twoFactor),
71+
then: TwoFactorView.init(store:)
72+
),
73+
isActive: viewStore.binding(
74+
get: { $0.isTwoFactorActive },
75+
send: { $0 ? .loginButtonTapped : .twoFactorDismissed }
76+
)
77+
) {
78+
Text("Log in")
79+
80+
if viewStore.isActivityIndicatorVisible {
81+
ActivityIndicator()
8082
}
81-
.disabled(viewStore.isLoginButtonDisabled)
8283
}
84+
.disabled(viewStore.isLoginButtonDisabled)
8385
}
86+
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
8487
.disabled(viewStore.isFormDisabled)
88+
.padding(.horizontal)
8589
}
86-
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
8790
}
8891
.navigationBarTitle("Login")
8992
// NB: This is necessary to clear the bar items from the game.

Examples/TicTacToe/Sources/Views-SwiftUI/NewGameSwiftView.swift

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,42 +29,47 @@ public struct NewGameView: View {
2929

3030
public var body: some View {
3131
WithViewStore(self.store.scope(state: { $0.view }, action: NewGameAction.view)) { viewStore in
32-
VStack {
33-
Form {
34-
Section(header: Text("X Player Name")) {
32+
ScrollView {
33+
VStack(spacing: 16) {
34+
VStack(alignment: .leading) {
35+
Text("X Player Name")
3536
TextField(
3637
"Blob Sr.",
3738
text: viewStore.binding(get: { $0.xPlayerName }, send: ViewAction.xPlayerNameChanged)
3839
)
3940
.autocapitalization(.words)
4041
.disableAutocorrection(true)
4142
.textContentType(.name)
43+
.textFieldStyle(RoundedBorderTextFieldStyle())
4244
}
43-
Section(header: Text("O Player Name")) {
45+
46+
VStack(alignment: .leading) {
47+
Text("O Player Name")
4448
TextField(
4549
"Blob Jr.",
4650
text: viewStore.binding(get: { $0.oPlayerName }, send: ViewAction.oPlayerNameChanged)
4751
)
4852
.autocapitalization(.words)
4953
.disableAutocorrection(true)
5054
.textContentType(.name)
55+
.textFieldStyle(RoundedBorderTextFieldStyle())
5156
}
52-
Section {
53-
NavigationLink(
54-
destination: IfLetStore(
55-
self.store.scope(state: { $0.game }, action: NewGameAction.game),
56-
then: GameView.init(store:)
57-
),
58-
isActive: viewStore.binding(
59-
get: { $0.isGameActive },
60-
send: { $0 ? .letsPlayButtonTapped : .gameDismissed }
61-
)
62-
) {
63-
Text("Let's play!")
64-
}
65-
.disabled(viewStore.isLetsPlayButtonDisabled)
57+
58+
NavigationLink(
59+
destination: IfLetStore(
60+
self.store.scope(state: { $0.game }, action: NewGameAction.game),
61+
then: GameView.init(store:)
62+
),
63+
isActive: viewStore.binding(
64+
get: { $0.isGameActive },
65+
send: { $0 ? .letsPlayButtonTapped : .gameDismissed }
66+
)
67+
) {
68+
Text("Let's play!")
6669
}
70+
.disabled(viewStore.isLetsPlayButtonDisabled)
6771
}
72+
.padding(.horizontal)
6873
}
6974
.navigationBarTitle("New Game")
7075
.navigationBarItems(trailing: Button("Logout") { viewStore.send(.logoutButtonTapped) })

Examples/TicTacToe/Sources/Views-SwiftUI/TwoFactorSwiftView.swift

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -28,22 +28,20 @@ public struct TwoFactorView: View {
2828

2929
public var body: some View {
3030
WithViewStore(self.store.scope(state: { $0.view }, action: TwoFactorAction.view)) { viewStore in
31-
Form {
32-
Section(
33-
header: Text(#"To confirm the second factor enter "1234" into the form."#)
34-
) {
35-
EmptyView()
36-
}
31+
ScrollView {
32+
VStack(spacing: 16) {
33+
Text(#"To confirm the second factor enter "1234" into the form."#)
3734

38-
Section(header: Text("Code")) {
39-
TextField(
40-
"1234",
41-
text: viewStore.binding(get: { $0.code }, send: ViewAction.codeChanged)
42-
)
43-
.keyboardType(.numberPad)
44-
}
35+
VStack(alignment: .leading) {
36+
Text("Code")
37+
TextField(
38+
"1234",
39+
text: viewStore.binding(get: { $0.code }, send: ViewAction.codeChanged)
40+
)
41+
.keyboardType(.numberPad)
42+
.textFieldStyle(RoundedBorderTextFieldStyle())
43+
}
4544

46-
Section {
4745
HStack {
4846
Button("Submit") {
4947
viewStore.send(.submitButtonTapped)
@@ -55,11 +53,12 @@ public struct TwoFactorView: View {
5553
}
5654
}
5755
}
56+
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
57+
.disabled(viewStore.isFormDisabled)
58+
.padding(.horizontal)
5859
}
59-
.disabled(viewStore.isFormDisabled)
60-
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
6160
}
62-
.navigationBarTitle("Two Factor Confirmation")
61+
.navigationBarTitle("Confirmation Code")
6362
}
6463
}
6564

0 commit comments

Comments
 (0)