@@ -22,7 +22,8 @@ struct FocusEnvironment {
2222 var randomElement : ( ) -> Int = { ( 1 ..< 11 ) . randomElement ( ) ! }
2323}
2424
25- let focusReducer = Reducer < FocusState , FocusAction , FocusEnvironment > { state, action, environment in
25+ let focusReducer = Reducer < FocusState , FocusAction , FocusEnvironment > {
26+ state, action, environment in
2627 switch action {
2728 case . randomButtonClicked:
2829 state. currentFocus = environment. randomElement ( )
@@ -31,51 +32,51 @@ let focusReducer = Reducer<FocusState, FocusAction, FocusEnvironment> { state, a
3132}
3233
3334#if swift(>=5.3)
34- @available ( tvOS 14 . 0 , * )
35- struct FocusView : View {
36- let store : Store < FocusState , FocusAction >
35+ @available ( tvOS 14 . 0 , * )
36+ struct FocusView : View {
37+ let store : Store < FocusState , FocusAction >
3738
38- @Environment ( \. resetFocus) var resetFocus
39- @Namespace private var namespace
39+ @Environment ( \. resetFocus) var resetFocus
40+ @Namespace private var namespace
4041
41- var body : some View {
42- WithViewStore ( self . store) { viewStore in
43- VStack ( spacing: 100 ) {
44- Text ( readMe)
45- . font ( . headline)
46- . multilineTextAlignment ( . leading)
47- . padding ( )
42+ var body : some View {
43+ WithViewStore ( self . store) { viewStore in
44+ VStack ( spacing: 100 ) {
45+ Text ( readMe)
46+ . font ( . headline)
47+ . multilineTextAlignment ( . leading)
48+ . padding ( )
4849
49- HStack ( spacing: 40 ) {
50- ForEach ( 1 ..< 11 ) { index in
51- Button ( numbers [ index] ) { }
52- . prefersDefaultFocus ( viewStore. currentFocus == index, in: self . namespace)
50+ HStack ( spacing: 40 ) {
51+ ForEach ( 1 ..< 11 ) { index in
52+ Button ( numbers [ index] ) { }
53+ . prefersDefaultFocus ( viewStore. currentFocus == index, in: self . namespace)
54+ }
5355 }
54- }
5556
56- Button ( " Focus Random " ) { viewStore. send ( . randomButtonClicked) }
57- }
58- . onChange ( of: viewStore. currentFocus) { _ in
59- // Update the view's focus when the state tells us the focus changed.
60- self . resetFocus ( in: self . namespace)
57+ Button ( " Focus Random " ) { viewStore. send ( . randomButtonClicked) }
58+ }
59+ . onChange ( of: viewStore. currentFocus) { _ in
60+ // Update the view's focus when the state tells us the focus changed.
61+ self . resetFocus ( in: self . namespace)
62+ }
63+ . focusScope ( self . namespace)
6164 }
62- . focusScope ( self . namespace)
6365 }
6466 }
65- }
6667
67- @available ( tvOS 14 . 0 , * )
68- struct FocusView_Previews : PreviewProvider {
69- static var previews : some View {
70- FocusView (
71- store: . init(
72- initialState: . init( ) ,
73- reducer: focusReducer,
74- environment: . init( )
68+ @available ( tvOS 14 . 0 , * )
69+ struct FocusView_Previews : PreviewProvider {
70+ static var previews : some View {
71+ FocusView (
72+ store: . init(
73+ initialState: . init( ) ,
74+ reducer: focusReducer,
75+ environment: . init( )
76+ )
7577 )
76- )
78+ }
7779 }
78- }
7980#endif
8081
8182private let numbers = [
@@ -89,5 +90,5 @@ private let numbers = [
8990 " Seven " ,
9091 " Eight " ,
9192 " Nine " ,
92- " Ten "
93+ " Ten " ,
9394]
0 commit comments