Material Motion Exploring solutions that will empower creators with the tools needed to describe and implement rich, interactive motion on any platform. Edit this page · History
TranslationGestureRecognizer · RotationGestureRecognizer · ScaleGestureRecognizer · $._map velocity
Status Interface level Implementation level Library
Stable as of February 21, 2016 L2: Interaction creator L3: Stream creator material-motion
platformsrctests
iOS (Swift) View
velocity
upstream (GestureRecognizer)
(Point|Float) downstream

velocity specification

This is the engineering specification for the MotionObservable operator velocity that operates on GestureRecognizer value types.

Overview

Calculate the velocity of pointer events. If element is provided, the output units are relative to that element.

Example usage:

gestureSource(gesture).velocity(in: element?)

MVP

Expose drag velocity API

Should delegate to _map. This API should only be available for streams emitting TranslationGestureRecognizer values.

extension MotionObservable where T: TranslationGestureRecognizer {
  public func velocity(in element: Element) -> MotionObservable<Point> {
    return _map { gestureRecognizer in
      return gestureRecognizer.velocity(in: element)
    }
  }
}

Expose rotation velocity API

Should delegate to _map. This API should only be available for streams emitting RotationGestureRecognizer values.

extension MotionObservable where T: RotationGestureRecognizer {
  public func velocity() -> MotionObservable<Float> {
    return _map { gestureRecognizer in
      return gestureRecognizer.velocity()
    }
  }
}

Expose scale velocity API

Should delegate to _map. This API should only be available for streams emitting ScaleGestureRecognizer values.

extension MotionObservable where T: ScaleGestureRecognizer {
  public func velocity() -> MotionObservable<Float> {
    return _map { gestureRecognizer in
      return gestureRecognizer.velocity()
    }
  }
}