Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Operators that use _map no longer transform velocity by default.
Browse files Browse the repository at this point in the history
Summary: Velocity transformation is now opt in. Only x() and y() opt in to this behavior.

Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, markwei

Reviewed By: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, markwei

Tags: #material_motion

Differential Revision: http://codereview.cc/D3078
  • Loading branch information
Jeff Verkoeyen committed Apr 21, 2017
1 parent d43a5f6 commit dab2e7d
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/operators/foundation/_map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension MotionObservableConvertible {

This operator is meant to be used when building other operators.
*/
public func _map<U>(_ name: String? = nil, args: [Any]? = nil, transform: @escaping (T) -> U) -> MotionObservable<U> {
public func _map<U>(_ name: String? = nil, args: [Any]? = nil, transformVelocity: Bool = false, transform: @escaping (T) -> U) -> MotionObservable<U> {
return _nextOperator(name, args: args, operation: { value, next in
next(transform(value))

Expand All @@ -33,7 +33,7 @@ extension MotionObservableConvertible {
switch event {
case .add(let info):
if let initialVelocity = info.initialVelocity {
transformedInitialVelocity = transform(initialVelocity as! T)
transformedInitialVelocity = transformVelocity ? transform(initialVelocity as! T) : initialVelocity
} else {
transformedInitialVelocity = nil
}
Expand Down
2 changes: 1 addition & 1 deletion src/operators/x.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension MotionObservableConvertible where T == CGPoint {
Extract the x value from a CGPoint.
*/
public func x() -> MotionObservable<CGFloat> {
return _map(#function) {
return _map(#function, transformVelocity: true) {
$0.x
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/operators/y.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension MotionObservableConvertible where T == CGPoint {
Extract the y value from a CGPoint.
*/
public func y() -> MotionObservable<CGFloat> {
return _map(#function) {
return _map(#function, transformVelocity: true) {
$0.y
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/operator/foundation/_mapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class _mapTests: XCTestCase {
}

let eventReceived = expectation(description: "Event was received")
let _ = observable._map { value in
let _ = observable._map(transformVelocity: true) { value in
return value * scalar

}.subscribe(next: { _ in }, coreAnimation: { event in
Expand Down

0 comments on commit dab2e7d

Please sign in to comment.