Skip to content

Commit 5ddefea

Browse files
committed
Update BlocContentView.swift
1 parent 58072b9 commit 5ddefea

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

Example/SwiftBloc/BlocContentView.swift

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,14 @@ struct BlocContentView: View {
1313
var body: some View {
1414
NavigationView {
1515
BlocView(builder: { (bloc) in
16-
VStack {
17-
if bloc.state.count > 5 {
18-
LimitView()
19-
} else {
20-
OperationView()
16+
CounterView()
17+
.alert(isPresented: bloc.shouldShowAlertBinding) {
18+
Alert(
19+
title: Text("Hi"),
20+
message: Text("Message"),
21+
dismissButton: .cancel {}
22+
)
2123
}
22-
}
23-
.alert(isPresented: bloc.shouldShowAlertBinding) {
24-
Alert(
25-
title: Text("Hi"),
26-
message: Text("Message"),
27-
dismissButton: .cancel {}
28-
)
29-
}
3024
}, action: { (bloc) in
3125
if bloc.state.count < -5 {
3226
for _ in 0..<6 {
@@ -39,19 +33,28 @@ struct BlocContentView: View {
3933
}
4034
}
4135

36+
struct CounterView: View {
37+
@EnvironmentObject var bloc: CounterBloc
38+
39+
var body: some View {
40+
if bloc.state.count > 5 {
41+
LimitView()
42+
} else {
43+
OperationView()
44+
}
45+
}
46+
}
47+
4248
struct LimitView: View {
4349
@EnvironmentObject var bloc: CounterBloc
4450

4551
var body: some View {
4652
VStack {
4753
Text("Hooora")
4854
Button(action: {
49-
self.bloc.add(event: .decrement)
50-
self.bloc.add(event: .decrement)
51-
self.bloc.add(event: .decrement)
52-
self.bloc.add(event: .decrement)
53-
self.bloc.add(event: .decrement)
54-
self.bloc.add(event: .decrement)
55+
for _ in 0..<6 {
56+
bloc.add(event: .decrement)
57+
}
5558
}, label: {
5659
Text("Reset")
5760
})
@@ -65,12 +68,12 @@ struct OperationView: View {
6568
var body: some View {
6669
VStack {
6770
Button(action: {
68-
self.bloc.add(event: .increment)
71+
bloc.add(event: .increment)
6972
}, label: {
7073
Text("Send Increment event")
7174
})
7275
Button(action: {
73-
self.bloc.add(event: .decrement)
76+
bloc.add(event: .decrement)
7477
}, label: {
7578
Text("Send Decrement event")
7679
})

0 commit comments

Comments
 (0)