@@ -17,6 +17,24 @@ private let readMe = """
17
17
toggle at the bottom of the screen.
18
18
"""
19
19
20
+ extension Effect where Error == Never {
21
+ public static func keyFrames(
22
+ values: [ ( output: Value , duration: TimeInterval ) ] ,
23
+ scheduler: DateScheduler
24
+ ) -> Effect {
25
+ . concatenate(
26
+ values
27
+ . enumerated ( )
28
+ . map { index, animationState in
29
+ index == 0
30
+ ? Effect ( value: animationState. output)
31
+ : Effect ( value: animationState. output)
32
+ . delay ( values [ index - 1 ] . duration, on: scheduler)
33
+ }
34
+ )
35
+ }
36
+ }
37
+
20
38
struct AnimationsState : Equatable {
21
39
var circleCenter = CGPoint . zero
22
40
var circleColor = Color . white
@@ -43,15 +61,10 @@ let animationsReducer = Reducer<AnimationsState, AnimationsAction, AnimationsEnv
43
61
return . none
44
62
45
63
case . rainbowButtonTapped:
46
- return . concatenate(
47
- [ Color . red, . blue, . green, . orange, . pink, . purple, . yellow, . white]
48
- . enumerated ( )
49
- . map { index, color in
50
- index == 0
51
- ? Effect ( value: . setColor( color) )
52
- : Effect ( value: . setColor( color) )
53
- . delay ( 1 , on: environment. mainQueue)
54
- }
64
+ return . keyFrames(
65
+ values: [ Color . red, . blue, . green, . orange, . pink, . purple, . yellow, . white]
66
+ . map { ( output: . setColor( $0) , duration: 1 ) } ,
67
+ scheduler: environment. mainQueue
55
68
)
56
69
57
70
case let . setColor( color) :
0 commit comments