@@ -5,11 +5,6 @@ import ObjectiveC
55
66public 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!
5462private 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