Skip to content

Commit 6fd917b

Browse files
authored
Stop using Form in Tic-Tac-Toe example (#448)
1 parent 1d1ce31 commit 6fd917b

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
@@ -33,56 +33,59 @@ public struct LoginView: View {
3333

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

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

76-
if viewStore.isActivityIndicatorVisible {
77-
ActivityIndicator()
78-
}
67+
NavigationLink(
68+
destination: IfLetStore(
69+
self.store.scope(state: { $0.twoFactor }, action: LoginAction.twoFactor),
70+
then: TwoFactorView.init(store:)
71+
),
72+
isActive: viewStore.binding(
73+
get: { $0.isTwoFactorActive },
74+
send: { $0 ? .loginButtonTapped : .twoFactorDismissed }
75+
)
76+
) {
77+
Text("Log in")
78+
79+
if viewStore.isActivityIndicatorVisible {
80+
ActivityIndicator()
7981
}
80-
.disabled(viewStore.isLoginButtonDisabled)
8182
}
83+
.disabled(viewStore.isLoginButtonDisabled)
8284
}
85+
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
8386
.disabled(viewStore.isFormDisabled)
87+
.padding(.horizontal)
8488
}
85-
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
8689
}
8790
.navigationBarTitle("Login")
8891
// 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
@@ -27,22 +27,20 @@ public struct TwoFactorView: View {
2727

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

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

45-
Section {
4644
HStack {
4745
Button("Submit") {
4846
viewStore.send(.submitButtonTapped)
@@ -54,11 +52,12 @@ public struct TwoFactorView: View {
5452
}
5553
}
5654
}
55+
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
56+
.disabled(viewStore.isFormDisabled)
57+
.padding(.horizontal)
5758
}
58-
.disabled(viewStore.isFormDisabled)
59-
.alert(self.store.scope(state: { $0.alert }), dismiss: .alertDismissed)
6059
}
61-
.navigationBarTitle("Two Factor Confirmation")
60+
.navigationBarTitle("Confirmation Code")
6261
}
6362
}
6463

0 commit comments

Comments
 (0)