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
GestureRecognizer · $._map centroid
Status Interface level Implementation level Library
Stable as of February 21, 2016 L2: Interaction creator L3: Stream creator material-motion
iOS (Swift) View
upstream (GestureRecognizer)
(Point) downstream

centroid specification

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


Calculate the centroid of touch events in relation to the provided element. If element is not provided, the values should be relative to the top-left corner of the viewport (JavaScript’s pageX and pageY).

Example usage:

gestureStream.centroid(in: element)


Expose centroid API

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

The output of this operator should be a Point.

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