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

Commit

Permalink
Add MotionAggregator delegate.
Browse files Browse the repository at this point in the history
Summary: This will allow external clients to observe aggregate state changes to a motion aggregator.

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

Reviewed By: chuga, O4 Material Apple platform reviewers

Tags: #material_motion

Differential Revision: http://codereview.cc/D2393
  • Loading branch information
jverkoey committed Dec 20, 2016
1 parent 5898add commit 86f209e
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/MotionAggregator.swift
Expand Up @@ -42,14 +42,28 @@ public class MotionAggregator {
strongSelf.activeSubscriptions.remove(token)
}

strongSelf.aggregateState = strongSelf.activeSubscriptions.count > 0 ? .active : .atRest
let oldState = strongSelf.aggregateState
let newState: MotionState = strongSelf.activeSubscriptions.count > 0 ? .active : .atRest
strongSelf.aggregateState = newState
if oldState != newState {
strongSelf.delegate?.motionAggregateStateDidChange(strongSelf)
}
}))
}

public private(set) var aggregateState = MotionState.atRest

/** The delegate to which state change updates should be sent. */
public weak var delegate: MotionAggregatorDelegate?

private var subscriptions: [Subscription] = []

typealias Token = String
private var activeSubscriptions = Set<Token>()
}

/** A motion aggregator delegate is able to receive updates about changes of the aggregate state. */
public protocol MotionAggregatorDelegate: NSObjectProtocol {
/** Invoked each time the aggregate state changes. */
func motionAggregateStateDidChange(_ motionAggregate: MotionAggregator)
}

0 comments on commit 86f209e

Please sign in to comment.