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
$._nextOperator rewrite MotionRuntime-toggle · slop
Status Interface level Implementation level Library
Stable as of February 21, 2016 L2: Interaction creator L3: Stream creator material-motion
Android View
iOS (Swift) View View
upstream (T)
(U) downstream

rewrite specification

This is the engineering specification for the MotionObservable operator: rewrite.


rewrite transforms incoming values into new outgoing values using a dictionary of key-value pairs.

Example usage:

stream.rewrite([.state1: 100, .state2: 0])

upstream  values                      |  downstream
.state1   [.state1: 100, .state2: 0]  |  100
.state2   [.state1: 100, .state2: 0]  |  0
.state3   [.state1: 100, .state2: 0]  |  


Expose rewrite operator API

Return a new MotionObservable of type U.

class MotionObservable<T> {

  public func rewrite<U>(values: [T: U]) -> MotionObservable<U>

Only emit when a transformation is possible

class MotionObservable<T> {

  func rewrite<U>(_ values: [T: U]) -> MotionObservable<U> {
    return _nextOperator { value, next in
      if let rewritten = values[value] {