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
runtime · interactions MotionRuntime.addInteraction
Status Interface level Implementation level Library
Stable as of March 29, 2017 L1: App creator L4: Runtime engineering material-motion
UpdatesCurrent StatusInitiation dateCompletion date
Introduced spec. Stable March 29, 2017
platformsrctests
Android View
iOS (Swift) View

MotionRuntime.addInteraction specification

This is the engineering specification for the MotionRuntime’s addInteraction API.

Overview

Interactions can be added to a MotionRuntime using the add/addInteraction API.

MVP

Expose an add API

This API may alternatively be called addInteraction.

Accept an interaction, a target, and an optional constraint. The target and constraints should be typed according to the interaction’s generic type definitions.

class MotionRuntime {
  public func add<I: Interaction>(_ interaction: I, to target: I.Target, constraints: I.Constraints? = nil)
}

Create private storage for interactions

An array is adequate because we currently have no mechanism for removing interactions once they are added. The array may need to store typeless object references due to Interaction’s generic typing.

Storing the interactions allows interactions to be delegates of objects they create.

class MotionRuntime {
  private var interactions: [Any] = []
}

Store all interactions

An array is adequate because we currently have no mechanism for removing interactions once they are made.

Store the interaction before invoking its add API in case the interaction adds other interactions.

class MotionRuntime {
  func add<I: Interaction>(_ interaction: I, to target: I.Target, constraints: I.Constraints? = nil) {
    interactions.append(interaction)
    ...
  }
}

Invoke the interaction’s add API

Provide the target, runtime, and constraints.

class MotionRuntime {
  func add<I: Interaction>(_ interaction: I, to target: I.Target, constraints: I.Constraints? = nil) {
    ...
    interaction.add(to: target, withRuntime: self, constraints: constraints)
  }
}