Skip to content
This repository has been archived by the owner on Aug 13, 2021. It is now read-only.

Commit

Permalink
Avoid excessive TransitionTween emissions when the transition directi…
Browse files Browse the repository at this point in the history
…on changes.

Summary: Was noticing that TransitionTween was re-emitting animations every time the transition direction was written to, even if it didn't change.

Reviewers: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, appsforartists

Reviewed By: O2 Material Motion, #material_motion, appsforartists

Tags: #material_motion

Differential Revision: http://codereview.cc/D3185
  • Loading branch information
jverkoey committed May 10, 2017
1 parent 7b5e51f commit 33f60d7
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/interactions/TransitionTween.swift
Expand Up @@ -68,8 +68,8 @@ public final class TransitionTween<T>: Tween<T> {

self.direction = direction

self.toggledValues = direction.rewrite([.backward: backwardValues, .forward: forwardValues])
self.toggledKeyPositions = direction.rewrite([.backward: backwardKeyPositions, .forward: forwardKeyPositions])
self.toggledValues = direction.dedupe().rewrite([.backward: backwardValues, .forward: forwardValues])
self.toggledKeyPositions = direction.dedupe().rewrite([.backward: backwardKeyPositions, .forward: forwardKeyPositions])
super.init(duration: duration, values: values, system: system, timeline: timeline)
}

Expand All @@ -92,7 +92,7 @@ public final class TransitionTween<T>: Tween<T> {
withRuntime runtime: MotionRuntime,
constraints: ConstraintApplicator<T>? = nil) {
let unlocked = createProperty("TransitionTween.unlocked", withInitialValue: false)
runtime.connect(direction.rewriteTo(false), to: unlocked)
runtime.connect(direction.dedupe().rewriteTo(false), to: unlocked)
runtime.connect(toggledValues, to: values)
runtime.connect(toggledKeyPositions, to: keyPositions)
super.add(to: property, withRuntime: runtime) {
Expand All @@ -102,7 +102,7 @@ public final class TransitionTween<T>: Tween<T> {
}
return stream.valve(openWhenTrue: unlocked)
}
runtime.connect(direction.rewriteTo(true), to: unlocked)
runtime.connect(direction.dedupe().rewriteTo(true), to: unlocked)
}

private let direction: ReactiveProperty<TransitionDirection>
Expand Down

0 comments on commit 33f60d7

Please sign in to comment.