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 · translationAddedTo · interactions Draggable
Status Interface level Implementation level Library
Stable as of March 2, 2017 L1: App creator L2: Interaction creator material-motion
platformsrctests
Android View
iOS (Swift) View

Draggable specification

This is the engineering specification for the Draggable interaction.

Overview

Allows an element to be moved in reaction to a user’s gestural movement.

Example use:

runtime.add(Draggable(), to: view)

MVP

Expose a Draggable type

It conforms to the Interaction protocol.

public class Draggable: Interaction {
}

By default, create a new translation gesture recognizer for each target

When initialized with zero configuration arguments, a Draggable interaction will create a new TranslationGestureRecognizer for each target it’s associated with.

class Draggable {
  func add(...) {
    ...
    let gestureRecognizer = TranslationGestureRecognizer()
    target.addGestureRecognizer(gestureRecognizer)
    ...
  }
}

Fetch a reactive version of the gesture recognizer using runtime.get

This ensures that we’re using the same reactive instance across interactions.

class Draggable {
  func add(...) {
    ...
    let reactiveGesture = runtime.get(gesture)
    ...
  }
}

Connect translationAddedTo operator to the target’s position

Write a translationAddedTo stream to the target’s position.

class Draggable {
  func add(...) {
    ...
    var stream = reactiveGesture.translation(addedTo: position)
    runtime.connect(stream, to: runtime.get(target).position)
  }
}

Clearly document which property this interaction writes to

/**
 ...

 **Affected properties**

 - `view.layer.position`

 ...
 */
class Draggable {
}