Skip to content

Commit

Permalink
Removing unnecessary Loop struct
Browse files Browse the repository at this point in the history
  • Loading branch information
PimCoumans committed Apr 24, 2023
1 parent 0c72550 commit 439f10b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 202 deletions.
130 changes: 0 additions & 130 deletions Sources/AnimationPlanner/Animations/Loop.swift

This file was deleted.

21 changes: 21 additions & 0 deletions Sources/AnimationPlanner/Animations/MapSequence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import Foundation

extension Swift.Sequence {
/// Maps values from the sequence to animations
/// - Parameter animations: Add each animation from within this closure. Animations should conform to ``GroupAnimatable``
/// - Returns: Sequence of all animations created in the `animation` closure
public func mapSequence(
@SequenceBuilder animations builder: (Element) -> [SequenceAnimatable]
) -> [SequenceAnimatable] {
flatMap(builder)
}

/// Maps values from the sequence to animations
/// - Parameter animations: Add each animation from within this closure. Animations added to this loop should conform to ``GroupAnimatable``
/// - Returns: Group of all animations created in the `animation` closure
public func mapGroup(
@GroupBuilder animations builder: (Element) -> [GroupAnimatable]
) -> [GroupAnimatable] {
flatMap(builder)
}
}
36 changes: 36 additions & 0 deletions Tests/AnimationPlannerTests/GroupTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,5 +143,41 @@ class GroupTests: AnimationPlannerTests {

}
}

func testGroupCountedLoop() {
let numberOfLoops: Int = 4
let animations = randomDelayedAnimations(amount: numberOfLoops)
let totalDuration: TimeInterval = animations.max { $0.totalDuration < $1.totalDuration }?.totalDuration ?? 0

runAnimationBuilderTest(duration: totalDuration) { _, _ in

AnimationPlanner.group {
for index in 0..<numberOfLoops {
Animate(duration: animations[index].duration) {
self.performRandomAnimation()
}.delayed(animations[index].delay)
}
}

}
}

func testGroupForLoop() {
let numberOfLoops: Int = 4
let animations = randomDelayedAnimations(amount: numberOfLoops)
let totalDuration: TimeInterval = animations.max { $0.totalDuration < $1.totalDuration }?.totalDuration ?? 0

runAnimationBuilderTest(duration: totalDuration) { _, _ in

AnimationPlanner.group {
for animation in animations {
Animate(duration: animation.duration) {
self.performRandomAnimation()
}.delayed(animation.delay)
}
}

}
}

}
73 changes: 1 addition & 72 deletions Tests/AnimationPlannerTests/SequenceTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class SequenceTests: AnimationPlannerTests {
runAnimationBuilderTest(duration: totalDuration, precision: precision) { _, _ in

AnimationPlanner.plan {
Loop(for: numberOfLoops) { index in
for _ in 0..<numberOfLoops {
Animate(duration: duration / 2) {
self.performRandomAnimation()
}
Expand All @@ -133,23 +133,6 @@ class SequenceTests: AnimationPlannerTests {
}
}

func testSequenceElementLoop() {
let numberOfLoops: Int = 4
let durations = randomDurations(amount: numberOfLoops)
let totalDuration: TimeInterval = durations.reduce(0, +)
runAnimationBuilderTest(duration: totalDuration) { _, _ in

AnimationPlanner.plan {
Loop.through(durations) { duration in
Animate(duration: duration) {
self.performRandomAnimation()
}
}
}

}
}

func testSequenceForLoop() {
let numberOfLoops: Int = 4
let durations = randomDurations(amount: numberOfLoops)
Expand All @@ -166,58 +149,4 @@ class SequenceTests: AnimationPlannerTests {

}
}

func testGroupCountedLoop() {
let numberOfLoops: Int = 4
let animations = randomDelayedAnimations(amount: numberOfLoops)
let totalDuration: TimeInterval = animations.max { $0.totalDuration < $1.totalDuration }?.totalDuration ?? 0

runAnimationBuilderTest(duration: totalDuration) { _, _ in

AnimationPlanner.group {
Loop(for: numberOfLoops) { index in
Animate(duration: animations[index].duration) {
self.performRandomAnimation()
}.delayed(animations[index].delay)
}
}

}
}

func testGroupElementLoop() {
let numberOfLoops: Int = 4
let animations = randomDelayedAnimations(amount: numberOfLoops)
let totalDuration: TimeInterval = animations.max { $0.totalDuration < $1.totalDuration }?.totalDuration ?? 0

runAnimationBuilderTest(duration: totalDuration) { _, _ in

AnimationPlanner.group {
Loop.through(animations) { animation in
Animate(duration: animation.duration) {
self.performRandomAnimation()
}.delayed(animation.delay)
}
}

}
}

func testGroupForLoop() {
let numberOfLoops: Int = 4
let animations = randomDelayedAnimations(amount: numberOfLoops)
let totalDuration: TimeInterval = animations.max { $0.totalDuration < $1.totalDuration }?.totalDuration ?? 0

runAnimationBuilderTest(duration: totalDuration) { _, _ in

AnimationPlanner.group {
for animation in animations {
Animate(duration: animation.duration) {
self.performRandomAnimation()
}.delayed(animation.delay)
}
}

}
}
}

0 comments on commit 439f10b

Please sign in to comment.