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
MotionObservable · dedupe · rewrite · thresholdRange · ignoreUntil slop
Status Interface level Implementation level Library
Stable as of February 21, 2016 L2: Interaction creator L3: Stream creator material-motion
platformsrctests
Android View
iOS (Swift) View View
slop
upstream (number)
size (number)
(SlopEvent) downstream

slop specification

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

Overview

slop emits events in reaction to exiting and re-entering a slop region.

The slop region is centered around 0 and has a given size. This operator will not emit any events until the upstream value exits this slop region, at which point onExit will be emitted. If the upstream returns to the slop region then onReturn will be emitted.

Example usage

stream.slop(size: 50)

upstream size  |  downstream
20       50    |
10       50    |
60       50    |  .onExit
70       50    |
10       50    |  .onReturn
20       50    |
80       50    |  .onExit

MVP

Expose a SlopEvent type

public enum SlopEvent {
  case onExit
  case onReturn
}

Expose a slop operator API

Accept a single argument defining the size of the slop region, centered around 0.

class MotionObservable<number> {
  public func slop(size: number) -> MotionObservable<SlopEvent>

Calculate and emit the new slop event

class MotionObservable<number> {
  func slop(size: number) -> MotionObservable<SlopEvent> {
    return self
      .thresholdRange(min: -size, max: size)
      .rewrite([.whenBelow: .onExit, .whenWithin: .onReturn, .whenAbove: .onExit])
      .dedupe()
      .ignoreUntil(.onExit)