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

Commit

Permalink
Add repeat APIs to Tween
Browse files Browse the repository at this point in the history
Summary:
Added API to Tween to allow animations to repeat

Fixes #116

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

Reviewed By: O2 Material Motion, O4 Material Apple platform reviewers, #material_motion, featherless

Subscribers: featherless

Tags: #material_motion

Differential Revision: http://codereview.cc/D3111
  • Loading branch information
randcode-generator committed Apr 25, 2017
1 parent d6ab9d2 commit 5022aad
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/interactions/Tween.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,33 @@ public class Tween<T>: Interaction, Togglable, Stateful {
*/
public let duration: ReactiveProperty<CGFloat>

/**
The number of times the animation will repeat.

If the repeatCount is 0, it is ignored. If both repeatDuration and repeatCount are specified the behavior is undefined.

Setting this property to greatestFiniteMagnitude will cause the animation to repeat forever.

See https://developer.apple.com/reference/quartzcore/camediatiming/1427666-repeatcount for more information.
*/
public let repeatCount: ReactiveProperty<CGFloat> = createProperty("Tween.repeatCount", withInitialValue: 0)

/**
The number of seconds the animation will repeat for.

If the repeatDuration is 0, it is ignored. If both repeatDuration and repeatCount are specified the behavior is undefined.

See https://developer.apple.com/reference/quartzcore/camediatiming/1427643-repeatduration for more information.
*/
public let repeatDuration: ReactiveProperty<CGFloat> = createProperty("Tween.repeatDuration", withInitialValue: 0)

/**
Will the animation play in the reverse upon completion.

See https://developer.apple.com/reference/quartzcore/camediatiming/1427645-autoreverses for more information.
*/
public let autoreverses: ReactiveProperty<Bool> = createProperty("Tween.autoreverses", withInitialValue: false)

/**
The delay of the animation in seconds.
*/
Expand Down Expand Up @@ -137,6 +164,9 @@ public struct TweenShadow<T> {
public let state: ReactiveProperty<MotionState>
public let duration: ReactiveProperty<CGFloat>
public let delay: ReactiveProperty<CGFloat>
public let repeatCount: ReactiveProperty<CGFloat>
public let repeatDuration: ReactiveProperty<CGFloat>
public let autoreverses: ReactiveProperty<Bool>
public let values: ReactiveProperty<[T]>
public let keyPositions: ReactiveProperty<[CGFloat]>
public let timingFunctions: ReactiveProperty<[CAMediaTimingFunction]>
Expand All @@ -146,6 +176,9 @@ public struct TweenShadow<T> {
self.enabled = tween.enabled
self.state = tween._state
self.duration = tween.duration
self.repeatCount = tween.repeatCount
self.repeatDuration = tween.repeatDuration
self.autoreverses = tween.autoreverses
self.delay = tween.delay
self.values = tween.values
self.keyPositions = tween.keyPositions
Expand Down
3 changes: 3 additions & 0 deletions src/systems/coreAnimationTweenToStream.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private func streamFromTween<T>(_ tween: TweenShadow<T>, configureEvent: @escapi
}
animation.beginTime = CFTimeInterval(tween.delay.value)
animation.duration = CFTimeInterval(duration)
animation.repeatCount = Float(tween.repeatCount.value)
animation.repeatDuration = CFTimeInterval(tween.repeatDuration.value)
animation.autoreverses = tween.autoreverses.value

let key = NSUUID().uuidString
activeAnimations.insert(key)
Expand Down

0 comments on commit 5022aad

Please sign in to comment.