This repository has been archived by the owner on Aug 30, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Only animate CGSize and CGPoint key paths additively if additive is e…
…nabled. (#72) Prior to this change, CGSize and CGPoint animations were being animated additively even if the additive property was disabled. Added tests to catch regressions in the future.
- Loading branch information
Showing
4 changed files
with
277 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/* | ||
Copyright 2017-present The Material Motion Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import XCTest | ||
#if IS_BAZEL_BUILD | ||
import _MotionAnimator | ||
#else | ||
import MotionAnimator | ||
#endif | ||
|
||
class AdditiveAnimationTests: XCTestCase { | ||
var animator: MotionAnimator! | ||
var timing: MotionTiming! | ||
var view: UIView! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
animator = MotionAnimator() | ||
|
||
animator.additive = true | ||
|
||
timing = MotionTiming(delay: 0, | ||
duration: 1, | ||
curve: MotionCurveMakeBezier(p1x: 0, p1y: 0, p2x: 1, p2y: 1), | ||
repetition: .init(type: .none, amount: 0, autoreverses: false)) | ||
|
||
let window = UIWindow() | ||
window.makeKeyAndVisible() | ||
view = UIView() // Need to animate a view's layer to get implicit animations. | ||
window.addSubview(view) | ||
|
||
// Connect our layers to the render server. | ||
CATransaction.flush() | ||
} | ||
|
||
override func tearDown() { | ||
animator = nil | ||
timing = nil | ||
view = nil | ||
|
||
super.tearDown() | ||
} | ||
|
||
func testNumericKeyPathsAnimateAdditively() { | ||
animator.animate(with: timing, to: view.layer, withValues: [1, 0], keyPath: .cornerRadius) | ||
|
||
XCTAssertNotNil(view.layer.animationKeys(), | ||
"Expected an animation to be added, but none were found.") | ||
guard let animationKeys = view.layer.animationKeys() else { | ||
return | ||
} | ||
XCTAssertEqual(animationKeys.count, 1, | ||
"Expected only one animation to be added, but the following were found: " | ||
+ "\(animationKeys).") | ||
guard let key = animationKeys.first, | ||
let animation = view.layer.animation(forKey: key) as? CABasicAnimation else { | ||
return | ||
} | ||
|
||
XCTAssertTrue(animation.isAdditive, "Animation is not additive when it should be.") | ||
} | ||
|
||
func testCGSizeKeyPathsAnimateAdditively() { | ||
animator.animate(with: timing, to: view.layer, | ||
withValues: [CGSize(width: 0, height: 0), | ||
CGSize(width: 1, height: 2)], keyPath: .shadowOffset) | ||
|
||
XCTAssertNotNil(view.layer.animationKeys(), | ||
"Expected an animation to be added, but none were found.") | ||
guard let animationKeys = view.layer.animationKeys() else { | ||
return | ||
} | ||
XCTAssertEqual(animationKeys.count, 1, | ||
"Expected only one animation to be added, but the following were found: " | ||
+ "\(animationKeys).") | ||
guard let key = animationKeys.first, | ||
let animation = view.layer.animation(forKey: key) as? CABasicAnimation else { | ||
return | ||
} | ||
|
||
XCTAssertTrue(animation.isAdditive, "Animation is not additive when it should be.") | ||
} | ||
|
||
func testCGPointKeyPathsAnimateAdditively() { | ||
animator.animate(with: timing, to: view.layer, | ||
withValues: [CGPoint(x: 0, y: 0), | ||
CGPoint(x: 1, y: 2)], keyPath: .position) | ||
|
||
XCTAssertNotNil(view.layer.animationKeys(), | ||
"Expected an animation to be added, but none were found.") | ||
guard let animationKeys = view.layer.animationKeys() else { | ||
return | ||
} | ||
XCTAssertEqual(animationKeys.count, 1, | ||
"Expected only one animation to be added, but the following were found: " | ||
+ "\(animationKeys).") | ||
guard let key = animationKeys.first, | ||
let animation = view.layer.animation(forKey: key) as? CABasicAnimation else { | ||
return | ||
} | ||
|
||
XCTAssertTrue(animation.isAdditive, "Animation is not additive when it should be.") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
/* | ||
Copyright 2017-present The Material Motion Authors. All Rights Reserved. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
import XCTest | ||
#if IS_BAZEL_BUILD | ||
import _MotionAnimator | ||
#else | ||
import MotionAnimator | ||
#endif | ||
|
||
class NonAdditiveAnimationTests: XCTestCase { | ||
var animator: MotionAnimator! | ||
var timing: MotionTiming! | ||
var view: UIView! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
animator = MotionAnimator() | ||
|
||
animator.additive = false | ||
|
||
timing = MotionTiming(delay: 0, | ||
duration: 1, | ||
curve: MotionCurveMakeBezier(p1x: 0, p1y: 0, p2x: 0, p2y: 0), | ||
repetition: .init(type: .none, amount: 0, autoreverses: false)) | ||
|
||
let window = UIWindow() | ||
window.makeKeyAndVisible() | ||
view = UIView() // Need to animate a view's layer to get implicit animations. | ||
window.addSubview(view) | ||
|
||
// Connect our layers to the render server. | ||
CATransaction.flush() | ||
} | ||
|
||
override func tearDown() { | ||
animator = nil | ||
timing = nil | ||
view = nil | ||
|
||
super.tearDown() | ||
} | ||
|
||
func testNumericKeyPathsDontAnimateAdditively() { | ||
animator.animate(with: timing, to: view.layer, withValues: [1, 0], keyPath: .cornerRadius) | ||
|
||
XCTAssertNotNil(view.layer.animationKeys(), | ||
"Expected an animation to be added, but none were found.") | ||
guard let animationKeys = view.layer.animationKeys() else { | ||
return | ||
} | ||
XCTAssertEqual(animationKeys.count, 1, | ||
"Expected only one animation to be added, but the following were found: " | ||
+ "\(animationKeys).") | ||
guard let key = animationKeys.first, | ||
let animation = view.layer.animation(forKey: key) as? CABasicAnimation else { | ||
return | ||
} | ||
|
||
XCTAssertFalse(animation.isAdditive, "Animation is additive when it shouldn't be.") | ||
} | ||
|
||
func testSizeKeyPathsDontAnimateAdditively() { | ||
animator.animate(with: timing, to: view.layer, | ||
withValues: [CGSize(width: 0, height: 0), | ||
CGSize(width: 1, height: 2)], keyPath: .shadowOffset) | ||
|
||
XCTAssertNotNil(view.layer.animationKeys(), | ||
"Expected an animation to be added, but none were found.") | ||
guard let animationKeys = view.layer.animationKeys() else { | ||
return | ||
} | ||
XCTAssertEqual(animationKeys.count, 1, | ||
"Expected only one animation to be added, but the following were found: " | ||
+ "\(animationKeys).") | ||
guard let key = animationKeys.first, | ||
let animation = view.layer.animation(forKey: key) as? CABasicAnimation else { | ||
return | ||
} | ||
|
||
XCTAssertFalse(animation.isAdditive, "Animation is additive when it shouldn't be.") | ||
} | ||
|
||
func testPositionKeyPathsDontAnimateAdditively() { | ||
animator.animate(with: timing, to: view.layer, | ||
withValues: [CGPoint(x: 0, y: 0), | ||
CGPoint(x: 1, y: 2)], keyPath: .position) | ||
|
||
XCTAssertNotNil(view.layer.animationKeys(), | ||
"Expected an animation to be added, but none were found.") | ||
guard let animationKeys = view.layer.animationKeys() else { | ||
return | ||
} | ||
XCTAssertEqual(animationKeys.count, 1, | ||
"Expected only one animation to be added, but the following were found: " | ||
+ "\(animationKeys).") | ||
guard let key = animationKeys.first, | ||
let animation = view.layer.animation(forKey: key) as? CABasicAnimation else { | ||
return | ||
} | ||
|
||
XCTAssertFalse(animation.isAdditive, "Animation is additive when it shouldn't be.") | ||
} | ||
|
||
func testRectKeyPathsDontAnimateAdditively() { | ||
animator.animate(with: timing, to: view.layer, | ||
withValues: [CGRect(x: 0, y: 0, width: 0, height: 0), | ||
CGRect(x: 0, y: 0, width: 100, height: 50)], keyPath: .bounds) | ||
|
||
XCTAssertNotNil(view.layer.animationKeys(), | ||
"Expected an animation to be added, but none were found.") | ||
guard let animationKeys = view.layer.animationKeys() else { | ||
return | ||
} | ||
XCTAssertEqual(animationKeys.count, 1, | ||
"Expected only one animation to be added, but the following were found: " | ||
+ "\(animationKeys).") | ||
guard let key = animationKeys.first, | ||
let animation = view.layer.animation(forKey: key) as? CABasicAnimation else { | ||
return | ||
} | ||
|
||
XCTAssertFalse(animation.isAdditive, "Animation is additive when it shouldn't be.") | ||
} | ||
} |