Skip to content

Commit 437f065

Browse files
tgrapperonmluisbrown
authored andcommitted
Set the circle in the center of the view in the animation's study (#1203)
* Set the circle in the center of the view in the animation's study * Modernize Animation study's layout * Put the gesture back on the Text only
1 parent 9f226d9 commit 437f065

File tree

1 file changed

+35
-35
lines changed

1 file changed

+35
-35
lines changed

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ extension Effect where Error == Never {
3939

4040
struct AnimationsState: Equatable {
4141
var alert: AlertState<AnimationsAction>?
42-
var circleCenter = CGPoint(x: 175, y: 300)
42+
var circleCenter: CGPoint?
4343
var circleColor = Color.black
4444
var isCircleScaled = false
4545
}
@@ -110,48 +110,48 @@ struct AnimationsView: View {
110110

111111
var body: some View {
112112
WithViewStore(self.store) { viewStore in
113-
GeometryReader { proxy in
114-
VStack(alignment: .leading) {
115-
ZStack(alignment: .center) {
116-
Text(template: readMe, .body)
117-
.padding()
118-
119-
Circle()
120-
.fill(viewStore.circleColor)
121-
.colorInvert()
122-
.blendMode(.difference)
123-
.frame(width: 50, height: 50)
124-
.scaleEffect(viewStore.isCircleScaled ? 2 : 1)
125-
.offset(
126-
x: viewStore.circleCenter.x - proxy.size.width / 2,
127-
y: viewStore.circleCenter.y - proxy.size.height / 2
128-
)
129-
}
130-
.frame(maxWidth: .infinity, maxHeight: .infinity)
131-
.background(self.colorScheme == .dark ? Color.black : .white)
132-
.simultaneousGesture(
113+
VStack(alignment: .leading) {
114+
Text(template: readMe, .body)
115+
.padding()
116+
.gesture(
133117
DragGesture(minimumDistance: 0).onChanged { gesture in
134118
viewStore.send(
135119
.tapped(gesture.location),
136120
animation: .interactiveSpring(response: 0.25, dampingFraction: 0.1)
137121
)
138122
}
139123
)
140-
Toggle(
141-
"Big mode",
142-
isOn:
143-
viewStore
144-
.binding(get: \.isCircleScaled, send: AnimationsAction.circleScaleToggleChanged)
145-
.animation(.interactiveSpring(response: 0.25, dampingFraction: 0.1))
146-
)
147-
.padding()
148-
Button("Rainbow") { viewStore.send(.rainbowButtonTapped, animation: .linear) }
149-
.padding([.horizontal, .bottom])
150-
Button("Reset") { viewStore.send(.resetButtonTapped) }
151-
.padding([.horizontal, .bottom])
152-
}
153-
.alert(self.store.scope(state: \.alert), dismiss: .dismissAlert)
124+
.overlay {
125+
GeometryReader { proxy in
126+
Circle()
127+
.fill(viewStore.circleColor)
128+
.colorInvert()
129+
.blendMode(.difference)
130+
.frame(width: 50, height: 50)
131+
.scaleEffect(viewStore.isCircleScaled ? 2 : 1)
132+
.position(
133+
x: viewStore.circleCenter?.x ?? proxy.size.width / 2,
134+
y: viewStore.circleCenter?.y ?? proxy.size.height / 2
135+
)
136+
.offset(y: viewStore.circleCenter == nil ? 0 : -44)
137+
}
138+
.allowsHitTesting(false)
139+
}
140+
Toggle(
141+
"Big mode",
142+
isOn:
143+
viewStore
144+
.binding(get: \.isCircleScaled, send: AnimationsAction.circleScaleToggleChanged)
145+
.animation(.interactiveSpring(response: 0.25, dampingFraction: 0.1))
146+
)
147+
.padding()
148+
Button("Rainbow") { viewStore.send(.rainbowButtonTapped, animation: .linear) }
149+
.padding([.horizontal, .bottom])
150+
Button("Reset") { viewStore.send(.resetButtonTapped) }
151+
.padding([.horizontal, .bottom])
154152
}
153+
.background(self.colorScheme == .dark ? Color.black : .white)
154+
.alert(self.store.scope(state: \.alert), dismiss: .dismissAlert)
155155
.navigationBarTitleDisplayMode(.inline)
156156
}
157157
}

0 commit comments

Comments
 (0)