-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reviewers: O4 Material Motion Apple platform reviewers, O2 Material Motion, featherless Reviewed By: O4 Material Motion Apple platform reviewers, O2 Material Motion, featherless Subscribers: featherless Tags: #material_motion Differential Revision: http://codereview.cc/D1757
- Loading branch information
Showing
6 changed files
with
401 additions
and
12 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,76 @@ | ||
/* | ||
Copyright 2016-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 | ||
import MaterialMotionRuntime | ||
import MaterialMotionDirectManipulationFamily | ||
|
||
class AnchorPointTests: XCTestCase { | ||
func testThatAnchorPointIsModifiedByDraggablePerformer() { | ||
let pan = TestablePanGestureRecognizer() | ||
let draggable = Draggable(withGestureRecognizer: pan) | ||
draggable.shouldAdjustAnchorPointOnGestureStart = true | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(draggable, to: view) | ||
|
||
pan.performTouch(location: CGPoint(x: 10, y: 20), state: .began) | ||
|
||
XCTAssertEqual(view.layer.anchorPoint, CGPoint(x: 0.1, y: 0.2)) | ||
} | ||
|
||
func testThatAnchorPointIsModifiedByPinchablePerformer() { | ||
let pinch = TestablePinchGestureRecognizer() | ||
let pinchable = Pinchable(withGestureRecognizer: pinch) | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(pinchable, to: view) | ||
|
||
pinch.performTouch(location: CGPoint(x: 10, y: 20), state: .began) | ||
|
||
XCTAssertEqual(view.layer.anchorPoint, CGPoint(x: 0.1, y: 0.2)) | ||
} | ||
|
||
func testThatAnchorPointIsModifiedByRotatablePerformer() { | ||
let rotate = TestableRotationGestureRecognizer() | ||
let rotatable = Rotatable(withGestureRecognizer: rotate) | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(rotatable, to: view) | ||
|
||
rotate.performTouch(location: CGPoint(x: 10, y: 20), state: .began) | ||
|
||
XCTAssertEqual(view.layer.anchorPoint, CGPoint(x: 0.1, y: 0.2)) | ||
} | ||
|
||
func testThatPinchableAnchorPointFlagPreventsModification() { | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) | ||
|
||
let pinch = TestablePinchGestureRecognizer() | ||
let pinchable = Pinchable(withGestureRecognizer: pinch) | ||
pinchable.shouldAdjustAnchorPointOnGestureStart = false | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(pinchable, to: view) | ||
|
||
pinch.performTouch(location: CGPoint(x: 10, y: 20), state: .began) | ||
|
||
XCTAssertEqual(view.layer.anchorPoint, CGPoint(x: 0.5, y: 0.5)) | ||
} | ||
} |
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,79 @@ | ||
/* | ||
Copyright 2016-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 | ||
import MaterialMotionRuntime | ||
import MaterialMotionDirectManipulationFamily | ||
|
||
class GestureActionTests: XCTestCase { | ||
func testThatDraggableDrags() { | ||
let pan = TestablePanGestureRecognizer() | ||
let draggable = Draggable(withGestureRecognizer: pan) | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(draggable, to: view) | ||
|
||
pan.performTouch(state: .began) | ||
pan.performTouch(translation: CGPoint(x: 25, y: -50), state: .changed) | ||
|
||
let newCenter = CGPoint(x: 25+25, y: 25-50) | ||
XCTAssertEqual(newCenter, view.center, "View's center (\(view.center.x), \(view.center.y)) should be (\(newCenter.x), \(newCenter.y))") | ||
} | ||
|
||
func testThatPinchableScales() { | ||
let pinch = TestablePinchGestureRecognizer() | ||
let pinchable = Pinchable(withGestureRecognizer: pinch) | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 80)) | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(pinchable, to: view) | ||
|
||
pinch.performTouch(scale: 1, state: .began) | ||
pinch.performTouch(scale: 0.50, state: .changed) | ||
|
||
XCTAssertEqual(view.frame.width, 50, "View's width (\(view.bounds.width)) should equal 50") | ||
XCTAssertEqual(view.frame.height, 40, "View's height (\(view.bounds.height)) should equal 40") | ||
} | ||
|
||
func testThatRotatableRotates() { | ||
let rotateGesture = TestableRotationGestureRecognizer() | ||
let rotatable = Rotatable(withGestureRecognizer: rotateGesture) | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 100, height: 80)) | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(rotatable, to: view) | ||
|
||
rotateGesture.performTouch(state: .began) | ||
rotateGesture.performTouch(rotation: CGFloat.pi / 2, state: .changed) | ||
|
||
let rotation = atan2(view.transform.b, view.transform.a) | ||
|
||
XCTAssertEqual(rotation, CGFloat.pi / 2, "View's rotation (\(rotation) should equal Pi / 2") | ||
} | ||
|
||
func testThatAnchorPointIsModified() { | ||
let view = UIView(frame: CGRect(x: 0, y: 0, width: 50, height: 50)) | ||
let newAnchorPoint = CGPoint(x: 0.33, y: 0.33) | ||
let changeAnchor = ChangeAnchorPoint(withAnchorPoint: newAnchorPoint) | ||
|
||
let scheduler = Scheduler() | ||
scheduler.addPlan(changeAnchor, to: view) | ||
|
||
XCTAssertEqual(view.layer.anchorPoint, newAnchorPoint, | ||
"View's anchor point (\(view.layer.anchorPoint.x), \(view.layer.anchorPoint.y)) should be (\(newAnchorPoint.x), \(newAnchorPoint.y))") | ||
} | ||
} |
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
Oops, something went wrong.