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
Property · Interaction Tap
Status Library
Draft as of December 20, 2016 interactions

Tap specification

This is the engineering specification for the Tap interaction.

Overview

The tap interaction writes to a position property when a tap gesture is recognized.

Example use:

let tap = Tap(sets: tossable.destination, containerView: view)

MVP

Expose a Tap type

public class Tap: Interaction

Expose configurable values

All property values should be readonly, all stream values should be settable.

class Tap {

  /** The position to which the position stream is expected to write. */
  public let position: ReactiveProperty<CGPoint>

  /** A stream that emits positional values to be written to the view. */
  public var positionStream: MotionObservable<CGPoint>

Expose an initializer

class Tap {
  public init(sets position: ReactiveProperty<CGPoint>,
                containerView: UIView,
                tapGestureRecognizer: UITapGestureRecognizer? = nil)

Store the position

class Tap {
  init(...) {
    self.position = position

    ...

Create a tap gesture recognizer if one was not provided

class Tap {
  init(...) {
    ...

    let tapGestureRecognizer = tapGestureRecognizer ?? UITapGestureRecognizer()
    if tapGestureRecognizer.view == nil {
      containerView.addGestureRecognizer(tapGestureRecognizer)
    }

    ...

Create the position stream

class Tap {
  init(...) {
    ...

    self.positionStream = gestureSource(tapGestureRecognizer)
      .onRecognitionState(.recognized)
      .centroid(in: containerView)