Skip to content

Commit 5d0797f

Browse files
committed
Add RepeatAnimationExample
1 parent 672955d commit 5d0797f

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

Example/HostingExample/ViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,6 @@ class ViewController: NSViewController {
6666

6767
struct ContentView: View {
6868
var body: some View {
69-
ToggleExample()
69+
RepeatAnimationExample()
7070
}
7171
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// RepeatAnimationExample.swift
3+
// SharedExample
4+
5+
#if OPENSWIFTUI
6+
import OpenSwiftUI
7+
#else
8+
import SwiftUI
9+
#endif
10+
11+
struct RepeatAnimationExample: View {
12+
@State private var smaller = false
13+
14+
var body: some View {
15+
VStack {
16+
HStack {
17+
Color.red
18+
.frame(width: smaller ? 50 : 100, height: smaller ? 50 : 100)
19+
.animation(
20+
.linear(duration: 1).repeatCount(2, autoreverses: false),
21+
value: smaller,
22+
)
23+
Color.green
24+
.frame(width: smaller ? 50 : 100, height: smaller ? 50 : 100)
25+
.animation(
26+
.linear(duration: 1).repeatCount(2, autoreverses: true),
27+
value: smaller,
28+
)
29+
}
30+
HStack {
31+
Color.red
32+
.frame(width: smaller ? 50 : 100, height: smaller ? 50 : 100)
33+
.animation(
34+
.linear(duration: 1).repeatForever(autoreverses: false),
35+
value: smaller,
36+
)
37+
Color.green
38+
.frame(width: smaller ? 50 : 100, height: smaller ? 50 : 100)
39+
.animation(
40+
.linear(duration: 1).repeatForever(autoreverses: true),
41+
value: smaller,
42+
)
43+
}
44+
}
45+
.onAppear {
46+
smaller.toggle()
47+
}
48+
}
49+
}

0 commit comments

Comments
 (0)