diff --git a/src/operators/foundation/_map.swift b/src/operators/foundation/_map.swift index edfd70a..5ddaed2 100644 --- a/src/operators/foundation/_map.swift +++ b/src/operators/foundation/_map.swift @@ -24,7 +24,7 @@ extension MotionObservableConvertible { This operator is meant to be used when building other operators. */ - public func _map(_ name: String? = nil, args: [Any]? = nil, transform: @escaping (T) -> U) -> MotionObservable { + public func _map(_ name: String? = nil, args: [Any]? = nil, transformVelocity: Bool = false, transform: @escaping (T) -> U) -> MotionObservable { return _nextOperator(name, args: args, operation: { value, next in next(transform(value)) @@ -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 } diff --git a/src/operators/x.swift b/src/operators/x.swift index d311942..4dc9561 100644 --- a/src/operators/x.swift +++ b/src/operators/x.swift @@ -23,7 +23,7 @@ extension MotionObservableConvertible where T == CGPoint { Extract the x value from a CGPoint. */ public func x() -> MotionObservable { - return _map(#function) { + return _map(#function, transformVelocity: true) { $0.x } } diff --git a/src/operators/y.swift b/src/operators/y.swift index ea21183..6c1d205 100644 --- a/src/operators/y.swift +++ b/src/operators/y.swift @@ -23,7 +23,7 @@ extension MotionObservableConvertible where T == CGPoint { Extract the y value from a CGPoint. */ public func y() -> MotionObservable { - return _map(#function) { + return _map(#function, transformVelocity: true) { $0.y } } diff --git a/tests/unit/operator/foundation/_mapTests.swift b/tests/unit/operator/foundation/_mapTests.swift index d3d9a2f..e97b4bc 100644 --- a/tests/unit/operator/foundation/_mapTests.swift +++ b/tests/unit/operator/foundation/_mapTests.swift @@ -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