Skip to content

Commit 76a3dca

Browse files
committed
Merge pull request #6 from ashfurrow/tv
Added tvOS support
2 parents 0397867 + c0366ac commit 76a3dca

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed

Action.podspec

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,4 @@ Pod::Spec.new do |s|
2525

2626
s.watchos.exclude_files = "UIButton+Rx.swift"
2727
s.osx.exclude_files = "UIButton+Rx.swift"
28-
s.tvos.exclude_files = "UIButton+Rx.swift"
2928
end

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Changelog
44
Current master
55
--------------
66

7-
Nothing yet!
7+
- Added tvOS support to UIButton extension.
88

99
0.1.0
1010
-----

UIButton+Rx.swift

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@ import ObjectiveC
55

66
public extension UIButton {
77

8-
private struct AssociatedKeys {
9-
static var Action = "rx_action"
10-
static var DisposeBag = "rx_diposeBag"
11-
}
12-
138
/// Binds enabled state of action to button, and subscribes to rx_tap to execute action.
149
/// These subscriptions are managed in a private, inaccessible dispose bag. To cancel
1510
/// them, set the rx_action to nil or another action.
@@ -37,8 +32,21 @@ public extension UIButton {
3732
.bindTo(self.rx_enabled)
3833
.addDisposableTo(self.actionDisposeBag)
3934

40-
self
41-
.rx_tap
35+
// Technically, this file is only included on tv/iOS platforms,
36+
// so this optional will never be nil. But let's be safe 😉
37+
let lookupControlEvent: ControlEvent<Void>?
38+
39+
#if os(tvOS)
40+
lookupControlEvent = self.rx_primaryAction
41+
#elseif os(iOS)
42+
lookupControlEvent = self.rx_tap
43+
#endif
44+
45+
guard let controlEvent = lookupControlEvent else {
46+
return
47+
}
48+
49+
controlEvent
4250
.subscribeNext { _ -> Void in
4351
action.execute()
4452
}
@@ -52,6 +60,10 @@ public extension UIButton {
5260
// Note: Actions performed in this extension are _not_ locked
5361
// So be careful!
5462
private extension UIButton {
63+
private struct AssociatedKeys {
64+
static var Action = "rx_action"
65+
static var DisposeBag = "rx_disposeBag"
66+
}
5567

5668
// A dispose bag to be used exclusively for the instance's rx_action.
5769
private var actionDisposeBag: DisposeBag {

0 commit comments

Comments
 (0)