diff --git a/VDS/Components/Selector/SelectorBase.swift b/VDS/Components/Selector/SelectorBase.swift index b3668fdf..0a496299 100644 --- a/VDS/Components/Selector/SelectorBase.swift +++ b/VDS/Components/Selector/SelectorBase.swift @@ -292,13 +292,5 @@ open class SelectorBase: Control, Changable setNeedsLayout() layoutIfNeeded() } - - public func selectedPublisher() -> AnyPublisher { - self.publisher(for: \.isSelected) - .map({ _ in - return self.model - }) - .eraseToAnyPublisher() - } } diff --git a/VDS/Components/Selector/SelectorGroupBase.swift b/VDS/Components/Selector/SelectorGroupBase.swift index 8dbacefc..8365b182 100644 --- a/VDS/Components/Selector/SelectorGroupBase.swift +++ b/VDS/Components/Selector/SelectorGroupBase.swift @@ -91,11 +91,11 @@ open class SelectorGroupBase 0 else { return } - self?.didSelect(selector: model) - } + self?.didSelect(selector: control.model) + }) .store(in: &subscribers) //add model update to the subscribers diff --git a/VDS/Publishers/UIControlPublisher.swift b/VDS/Publishers/UIControlPublisher.swift index 616bd8ca..f281215b 100644 --- a/VDS/Publishers/UIControlPublisher.swift +++ b/VDS/Publishers/UIControlPublisher.swift @@ -10,22 +10,22 @@ import UIKit import Combine /// A custom subscription to capture UIControl target events. -final class UIControlSubscription: Subscription where SubscriberType.Input == Control { +public final class UIControlSubscription: Subscription where SubscriberType.Input == Control { private var subscriber: SubscriberType? private let control: Control - init(subscriber: SubscriberType, control: Control, event: UIControl.Event) { + public init(subscriber: SubscriberType, control: Control, event: UIControl.Event) { self.subscriber = subscriber self.control = control control.addTarget(self, action: #selector(eventHandler), for: event) } - func request(_ demand: Subscribers.Demand) { + public func request(_ demand: Subscribers.Demand) { // We do nothing here as we only want to send events when they occur. // See, for more info: https://developer.apple.com/documentation/combine/subscribers/demand } - func cancel() { + public func cancel() { subscriber = nil } @@ -39,15 +39,15 @@ final class UIControlSubscription: Publisher { +public struct UIControlPublisher: Publisher { - typealias Output = Control - typealias Failure = Never + public typealias Output = Control + public typealias Failure = Never - let control: Control - let controlEvents: UIControl.Event + public let control: Control + public let controlEvents: UIControl.Event - init(control: Control, events: UIControl.Event) { + public init(control: Control, events: UIControl.Event) { self.control = control self.controlEvents = events } @@ -58,16 +58,16 @@ struct UIControlPublisher: Publisher { /// - Parameters: /// - subscriber: The subscriber to attach to this `Publisher`. /// once attached it can begin to receive values. - func receive(subscriber: S) where S : Subscriber, S.Failure == UIControlPublisher.Failure, S.Input == UIControlPublisher.Output { + public func receive(subscriber: S) where S : Subscriber, S.Failure == UIControlPublisher.Failure, S.Input == UIControlPublisher.Output { subscriber.receive(subscription: UIControlSubscription(subscriber: subscriber, control: control, event: controlEvents)) } } /// Extending the `UIControl` types to be able to produce a `UIControl.Event` publisher. -protocol CombineCompatible { } +public protocol CombineCompatible { } extension UIControl: CombineCompatible { } extension CombineCompatible where Self: UIControl { - func publisher(for events: UIControl.Event) -> UIControlPublisher { + public func publisher(for events: UIControl.Event) -> UIControlPublisher { return UIControlPublisher(control: self, events: events) } }