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

MotionRuntime.toggle specification

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

Overview

Togglable objects can be toggled by Stateful objects whenever the Stateful object’s state changes.

When the stateful object is active, the togglable object is disabled.

When the stateful object is at rest, the togglable object is enabled.

This relationship is most commonly used with springs and gestures. When the gesture is active, the spring is disabled. When the gesture comes to rest, the spring is enabled.

MVP

Expose a toggle API

Accept two interactions: the first being Togglable and the second being Stateful.

class MotionRuntime {
  public func toggle(_ interaction: Togglable, inReactionTo otherInteraction: Stateful)
}

Connect state to enabled

Connect the stateful interaction’s state property to the togglable interaction’s enabled property.

When the state is atRest, set enabled to true.

When the state is active, set enabled to false.

class MotionRuntime {
  public func toggle(_ interaction: Togglable, inReactionTo otherInteraction: Stateful) {
    connect(otherInteraction.state.rewrite([.atRest: true, .active: false]), to: interaction.enabled)
  }
}