Skip to content

Commit a422b09

Browse files
committed
[SwiftUI Case Studies] Revise initialState and layout in Animations (#1195)
* Remove some unnecessary 'nil' literals in State structs. * Revise initialState and layout - move Circle's initial location to center of the screen for better visibility - align 'circleColor' property's value with actual color using colorInvert() - remove top margin to display more text because we cannot apply ScrollView in this case * Update AnimationTests
1 parent 011d8bb commit a422b09

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-Animations.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ extension Effect where Error == Never {
3838
}
3939

4040
struct AnimationsState: Equatable {
41-
var alert: AlertState<AnimationsAction>? = nil
42-
var circleCenter = CGPoint(x: 50, y: 50)
43-
var circleColor = Color.white
41+
var alert: AlertState<AnimationsAction>?
42+
var circleCenter = CGPoint(x: UIScreen.main.bounds.width / 2, y: UIScreen.main.bounds.height / 2)
43+
var circleColor = Color.black
4444
var isCircleScaled = false
4545
}
4646

@@ -72,7 +72,7 @@ let animationsReducer = Reducer<AnimationsState, AnimationsAction, AnimationsEnv
7272

7373
case .rainbowButtonTapped:
7474
return .keyFrames(
75-
values: [Color.red, .blue, .green, .orange, .pink, .purple, .yellow, .white]
75+
values: [Color.red, .blue, .green, .orange, .pink, .purple, .yellow, .black]
7676
.map { (output: .setColor($0), duration: 1) },
7777
scheduler: environment.mainQueue.animation(.linear)
7878
)
@@ -116,6 +116,7 @@ struct AnimationsView: View {
116116

117117
Circle()
118118
.fill(viewStore.circleColor)
119+
.colorInvert()
119120
.blendMode(.difference)
120121
.frame(width: 50, height: 50)
121122
.scaleEffect(viewStore.isCircleScaled ? 2 : 1)
@@ -149,6 +150,7 @@ struct AnimationsView: View {
149150
}
150151
.alert(self.store.scope(state: \.alert), dismiss: .dismissAlert)
151152
}
153+
.navigationBarTitleDisplayMode(.inline)
152154
}
153155
}
154156
}

Examples/CaseStudies/SwiftUICaseStudies/01-GettingStarted-FocusState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ private let readMe = """
77
"""
88

99
struct FocusDemoState: Equatable {
10-
@BindableState var focusedField: Field? = nil
10+
@BindableState var focusedField: Field?
1111
@BindableState var password: String = ""
1212
@BindableState var username: String = ""
1313

Examples/CaseStudies/SwiftUICaseStudiesTests/01-GettingStarted-AnimationsTests.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ class AnimationTests: XCTestCase {
5353
}
5454

5555
self.mainQueue.advance(by: 1)
56-
store.receive(.setColor(.white)) {
57-
$0.circleColor = .white
56+
store.receive(.setColor(.black)) {
57+
$0.circleColor = .black
5858
}
5959

6060
self.mainQueue.run()

0 commit comments

Comments
 (0)