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

Commit

Permalink
Change runtime.interactions API to use an ofType: argument instead of…
Browse files Browse the repository at this point in the history
… a block.

Summary: This simplifies the API and reduces the syntactical overhead of using it.

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

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

Subscribers: markwei

Tags: #material_motion

Differential Revision: http://codereview.cc/D3099
  • Loading branch information
jverkoey committed Apr 25, 2017
1 parent dbff13d commit d6ab9d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
12 changes: 10 additions & 2 deletions src/MotionRuntime.swift
Expand Up @@ -83,13 +83,21 @@ public final class MotionRuntime {
Example usage:
let draggables = runtime.interactions(for: view) { $0 as? Draggable }
let draggables = runtime.interactions(for: view, type: Draggable.self)
*/
public func interactions<I>(for target: I.Target, ofType: I.Type) -> [I] where I: Interaction, I.Target: AnyObject {
guard let interactions = targets[ObjectIdentifier(target)] else {
return []
}
return interactions.flatMap { $0 as? I }
}

@available(*, deprecated, message: "Use interactions(for:ofType:) instead.")
public func interactions<I>(for target: I.Target, filter: (Any) -> I?) -> [I] where I: Interaction, I.Target: AnyObject {
guard let interactions = targets[ObjectIdentifier(target)] else {
return []
}
return interactions.flatMap(filter)
return interactions.flatMap { $0 as? I }
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/MotionRuntimeTests.swift
Expand Up @@ -34,7 +34,7 @@ class MotionRuntimeTests: XCTestCase {
func testInteractionsReturnsEmptyArrayWithoutAnyAddedInteractions() {
let runtime = MotionRuntime(containerView: UIView())

let results = runtime.interactions(for: UIView()) { $0 as? Draggable }
let results = runtime.interactions(for: UIView(), ofType: Draggable.self)
XCTAssertEqual(results.count, 0)
}

Expand All @@ -45,7 +45,7 @@ class MotionRuntimeTests: XCTestCase {
runtime.add(Draggable(), to: view)
runtime.add(Rotatable(), to: view)

let results = runtime.interactions(for: view) { $0 as? Draggable }
let results = runtime.interactions(for: view, ofType: Draggable.self)
XCTAssertEqual(results.count, 1)
}
}

0 comments on commit d6ab9d2

Please sign in to comment.