mirror of
https://github.com/ReactiveX/RxSwift.git
synced 2024-10-05 06:27:29 +03:00
implement DelegateProxy factory
This commit is contained in:
parent
16eabd5ea4
commit
3fba185b96
@ -188,13 +188,6 @@ open class DelegateProxy : _RXDelegateProxy {
|
||||
return delegateAssociatedTag
|
||||
}
|
||||
|
||||
/// Initializes new instance of delegate proxy.
|
||||
///
|
||||
/// - returns: Initialized instance of `self`.
|
||||
open class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
return self.init(parentObject: object)
|
||||
}
|
||||
|
||||
/// Returns assigned proxy for object.
|
||||
///
|
||||
/// - parameter object: Object that can have assigned delegate proxy.
|
||||
|
@ -69,22 +69,25 @@ every view has a corresponding delegate virtual factory method.
|
||||
|
||||
In case of UITableView / UIScrollView, there is
|
||||
|
||||
extension UIScrollView {
|
||||
public func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
|
||||
return RxScrollViewDelegateProxy(parentObject: base)
|
||||
RxScrollViewDelegateProxy has factories that contains RxScrollViewDelegateProxy(parentObject: parentObject)
|
||||
....
|
||||
|
||||
|
||||
and extend it
|
||||
|
||||
RxScrollViewDelegateProxy.extend { (parentObject: UITableView) in
|
||||
RxTableViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
....
|
||||
|
||||
|
||||
and override in UITableView
|
||||
|
||||
extension UITableView {
|
||||
public override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
|
||||
....
|
||||
|
||||
|
||||
*/
|
||||
public protocol DelegateProxyType : AnyObject {
|
||||
/// DelegateProxy factory
|
||||
static var factories: [((AnyObject) -> AnyObject?)] { get set }
|
||||
|
||||
/// Extend DelegateProxy for specific subclass
|
||||
static func extend<Object: AnyObject>(with factory: @escaping ((Object) -> AnyObject))
|
||||
|
||||
/// Creates new proxy for target object.
|
||||
static func createProxyForObject(_ object: AnyObject) -> AnyObject
|
||||
|
||||
@ -210,6 +213,14 @@ extension DelegateProxyType {
|
||||
proxy.setForwardToDelegate(nil, retainDelegate: retainDelegate)
|
||||
}
|
||||
}
|
||||
|
||||
public static func extend<Object: AnyObject>(with factory: @escaping ((Object) -> AnyObject)) {
|
||||
factories.append({ ($0 as? Object).map(factory) })
|
||||
}
|
||||
|
||||
public static func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
return factories.reversed().reduce(AnyObject?.none) { $0 ?? $1(object) }!
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS) || os(tvOS)
|
||||
|
@ -12,15 +12,6 @@
|
||||
#endif
|
||||
import UIKit
|
||||
|
||||
extension NSTextStorage {
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxTextStorageDelegateProxy {
|
||||
return RxTextStorageDelegateProxy(parentObject: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension Reactive where Base: NSTextStorage {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -37,6 +37,10 @@ public class RxCollectionViewDataSourceProxy
|
||||
, UICollectionViewDataSource
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxCollectionViewDataSourceProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// Typed parent object.
|
||||
public weak private(set) var collectionView: UICollectionView?
|
||||
|
||||
@ -64,12 +68,6 @@ public class RxCollectionViewDataSourceProxy
|
||||
|
||||
// MARK: proxy
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let collectionView: UICollectionView = castOrFatalError(object)
|
||||
return collectionView.createRxDataSourceProxy()
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
|
||||
return dataSourceAssociatedTag
|
||||
|
@ -19,6 +19,10 @@
|
||||
, UINavigationControllerDelegate
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxNavigationControllerDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
|
||||
let navigationController: UINavigationController = castOrFatalError(object)
|
||||
@ -30,12 +34,6 @@
|
||||
let navigationController: UINavigationController = castOrFatalError(object)
|
||||
navigationController.delegate = castOptionalOrFatalError(delegate)
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let navigationController: UINavigationController = castOrFatalError(object)
|
||||
return navigationController.createRxDelegateProxy()
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
|
@ -18,11 +18,9 @@
|
||||
, DelegateProxyType
|
||||
, UIPickerViewDelegate {
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let pickerView: UIPickerView = castOrFatalError(object)
|
||||
return pickerView.createRxDelegateProxy()
|
||||
}
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxPickerViewDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
|
||||
|
@ -19,6 +19,13 @@ public class RxScrollViewDelegateProxy
|
||||
, UIScrollViewDelegate
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxScrollViewDelegateProxy(parentObject: $0) },
|
||||
{ ($0 as? UITableView).map { RxTableViewDelegateProxy(parentObject: $0) } },
|
||||
{ ($0 as? UICollectionView).map { RxCollectionViewDelegateProxy(parentObject: $0) } },
|
||||
{ ($0 as? UITextView).map { RxTextViewDelegateProxy(parentObject: $0) } }
|
||||
]
|
||||
|
||||
fileprivate var _contentOffsetBehaviorSubject: BehaviorSubject<CGPoint>?
|
||||
fileprivate var _contentOffsetPublishSubject: PublishSubject<()>?
|
||||
|
||||
@ -72,12 +79,6 @@ public class RxScrollViewDelegateProxy
|
||||
|
||||
// MARK: delegate proxy
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let scrollView: UIScrollView = castOrFatalError(object)
|
||||
return scrollView.createRxDelegateProxy()
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
|
||||
let scrollView: UIScrollView = castOrFatalError(object)
|
||||
|
@ -19,6 +19,12 @@ public class RxSearchBarDelegateProxy
|
||||
, UISearchBarDelegate
|
||||
, DelegateProxyType {
|
||||
|
||||
// MARK: Delegate proxy methods
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxSearchBarDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
|
||||
let searchBar: UISearchBar = castOrFatalError(object)
|
||||
@ -30,17 +36,6 @@ public class RxSearchBarDelegateProxy
|
||||
let searchBar: UISearchBar = castOrFatalError(object)
|
||||
searchBar.delegate = castOptionalOrFatalError(delegate)
|
||||
}
|
||||
|
||||
// MARK: Delegate proxy methods
|
||||
|
||||
#if os(iOS)
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let searchBar: UISearchBar = castOrFatalError(object)
|
||||
return searchBar.createRxDelegateProxy()
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -20,11 +20,9 @@ public class RxSearchControllerDelegateProxy
|
||||
, DelegateProxyType
|
||||
, UISearchControllerDelegate {
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let pickerView: UISearchController = castOrFatalError(object)
|
||||
return pickerView.createRxDelegateProxy()
|
||||
}
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxSearchControllerDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
|
||||
|
@ -19,6 +19,10 @@ public class RxTabBarControllerDelegateProxy
|
||||
, UITabBarControllerDelegate
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxTabBarControllerDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
|
||||
let tabBarController: UITabBarController = castOrFatalError(object)
|
||||
@ -30,12 +34,6 @@ public class RxTabBarControllerDelegateProxy
|
||||
let tabBarController: UITabBarController = castOrFatalError(object)
|
||||
tabBarController.delegate = castOptionalOrFatalError(delegate)
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let tabBarController: UITabBarController = castOrFatalError(object)
|
||||
return tabBarController.createRxDelegateProxy()
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -19,6 +19,10 @@ public class RxTabBarDelegateProxy
|
||||
, UITabBarDelegate
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxTabBarDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
|
||||
let tabBar: UITabBar = castOrFatalError(object)
|
||||
@ -30,13 +34,6 @@ public class RxTabBarDelegateProxy
|
||||
let tabBar: UITabBar = castOrFatalError(object)
|
||||
tabBar.delegate = castOptionalOrFatalError(delegate)
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let tabBar: UITabBar = castOrFatalError(object)
|
||||
return tabBar.createRxDelegateProxy()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -34,6 +34,10 @@ public class RxTableViewDataSourceProxy
|
||||
, UITableViewDataSource
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxTableViewDataSourceProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// Typed parent object.
|
||||
public weak fileprivate(set) var tableView: UITableView?
|
||||
|
||||
@ -61,12 +65,6 @@ public class RxTableViewDataSourceProxy
|
||||
|
||||
// MARK: proxy
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let tableView: UITableView = castOrFatalError(object)
|
||||
return tableView.createRxDataSourceProxy()
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func delegateAssociatedObjectTag() -> UnsafeRawPointer {
|
||||
return dataSourceAssociatedTag
|
||||
|
@ -18,11 +18,9 @@
|
||||
, DelegateProxyType
|
||||
, NSTextStorageDelegate {
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let pickerView: NSTextStorage = castOrFatalError(object)
|
||||
return pickerView.createRxDelegateProxy()
|
||||
}
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxTextStorageDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
|
||||
|
@ -18,11 +18,9 @@ public class RxWebViewDelegateProxy
|
||||
, DelegateProxyType
|
||||
, UIWebViewDelegate {
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let pickerView: UIWebView = castOrFatalError(object)
|
||||
return pickerView.createRxDelegateProxy()
|
||||
}
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxWebViewDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func setCurrentDelegate(_ delegate: AnyObject?, toObject object: AnyObject) {
|
||||
|
@ -160,17 +160,6 @@ extension Reactive where Base: UICollectionView {
|
||||
}
|
||||
}
|
||||
|
||||
extension UICollectionView {
|
||||
|
||||
/// Factory method that enables subclasses to implement their own `rx.dataSource`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `dataSource`.
|
||||
public func createRxDataSourceProxy() -> RxCollectionViewDataSourceProxy {
|
||||
return RxCollectionViewDataSourceProxy(parentObject: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: UICollectionView {
|
||||
|
||||
/// Reactive wrapper for `dataSource`.
|
||||
|
@ -13,15 +13,6 @@ import RxSwift
|
||||
#endif
|
||||
import UIKit
|
||||
|
||||
extension UINavigationController {
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy {
|
||||
return RxNavigationControllerDelegateProxy(parentObject: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension Reactive where Base: UINavigationController {
|
||||
public typealias ShowEvent = (viewController: UIViewController, animated: Bool)
|
||||
|
||||
|
@ -13,17 +13,6 @@
|
||||
#endif
|
||||
import UIKit
|
||||
|
||||
extension UIPickerView {
|
||||
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxPickerViewDelegateProxy {
|
||||
return RxPickerViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: UIPickerView {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -14,26 +14,6 @@
|
||||
|
||||
import UIKit
|
||||
|
||||
extension UIScrollView {
|
||||
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
|
||||
switch self {
|
||||
case self as UICollectionView:
|
||||
return RxCollectionViewDelegateProxy(parentObject: self)
|
||||
case self as UITableView:
|
||||
return RxTableViewDelegateProxy(parentObject: self)
|
||||
case self as UITextView:
|
||||
return RxTextViewDelegateProxy(parentObject: self)
|
||||
default:
|
||||
return RxScrollViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: UIScrollView {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -13,19 +13,6 @@ import RxSwift
|
||||
#endif
|
||||
import UIKit
|
||||
|
||||
|
||||
#if os(iOS)
|
||||
extension UISearchBar {
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxSearchBarDelegateProxy {
|
||||
return RxSearchBarDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
extension Reactive where Base: UISearchBar {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -13,15 +13,6 @@
|
||||
#endif
|
||||
import UIKit
|
||||
|
||||
extension UISearchController {
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxSearchControllerDelegateProxy {
|
||||
return RxSearchControllerDelegateProxy(parentObject: self)
|
||||
}
|
||||
}
|
||||
|
||||
@available(iOS 8.0, *)
|
||||
extension Reactive where Base: UISearchController {
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -70,16 +70,6 @@ extension Reactive where Base: UITabBar {
|
||||
/**
|
||||
iOS and tvOS
|
||||
*/
|
||||
extension UITabBar {
|
||||
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxTabBarDelegateProxy {
|
||||
return RxTabBarDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: UITabBar {
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -58,16 +58,6 @@ extension Reactive where Base: UITabBarController {
|
||||
/**
|
||||
iOS and tvOS
|
||||
*/
|
||||
extension UITabBarController {
|
||||
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxTabBarControllerDelegateProxy {
|
||||
return RxTabBarControllerDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: UITabBarController {
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -165,19 +165,6 @@ extension Reactive where Base: UITableView {
|
||||
|
||||
}
|
||||
|
||||
extension UITableView {
|
||||
|
||||
/**
|
||||
Factory method that enables subclasses to implement their own `rx.dataSource`.
|
||||
|
||||
- returns: Instance of delegate proxy that wraps `dataSource`.
|
||||
*/
|
||||
public func createRxDataSourceProxy() -> RxTableViewDataSourceProxy {
|
||||
return RxTableViewDataSourceProxy(parentObject: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: UITableView {
|
||||
/**
|
||||
Reactive wrapper for `dataSource`.
|
||||
|
@ -14,17 +14,6 @@ import UIKit
|
||||
import RxSwift
|
||||
#endif
|
||||
|
||||
extension UIWebView {
|
||||
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxWebViewDelegateProxy {
|
||||
return RxWebViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: UIWebView {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -21,6 +21,10 @@ public class RxTextFieldDelegateProxy
|
||||
, NSTextFieldDelegate
|
||||
, DelegateProxyType {
|
||||
|
||||
public static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxTextFieldDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
fileprivate let textSubject = PublishSubject<String?>()
|
||||
|
||||
/// Typed parent object.
|
||||
@ -45,12 +49,6 @@ public class RxTextFieldDelegateProxy
|
||||
|
||||
// MARK: Delegate proxy methods
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public override class func createProxyForObject(_ object: AnyObject) -> AnyObject {
|
||||
let control: NSTextField = castOrFatalError(object)
|
||||
return control.createRxDelegateProxy()
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
public class func currentDelegateFor(_ object: AnyObject) -> AnyObject? {
|
||||
let textField: NSTextField = castOrFatalError(object)
|
||||
@ -65,16 +63,6 @@ public class RxTextFieldDelegateProxy
|
||||
|
||||
}
|
||||
|
||||
extension NSTextField {
|
||||
|
||||
/// Factory method that enables subclasses to implement their own `delegate`.
|
||||
///
|
||||
/// - returns: Instance of delegate proxy that wraps `delegate`.
|
||||
public func createRxDelegateProxy() -> RxTextFieldDelegateProxy {
|
||||
return RxTextFieldDelegateProxy(parentObject: self)
|
||||
}
|
||||
}
|
||||
|
||||
extension Reactive where Base: NSTextField {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
|
@ -16,6 +16,10 @@ class RxCLLocationManagerDelegateProxy : DelegateProxy
|
||||
, CLLocationManagerDelegate
|
||||
, DelegateProxyType {
|
||||
|
||||
static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ RxCLLocationManagerDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
internal lazy var didUpdateLocationsSubject = PublishSubject<[CLLocation]>()
|
||||
internal lazy var didFailWithErrorSubject = PublishSubject<Error>()
|
||||
|
||||
|
@ -32,10 +32,6 @@ class ExtendNSTextFieldDelegateProxy
|
||||
final class NSTextFieldSubclass
|
||||
: NSTextField
|
||||
, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxTextFieldDelegateProxy {
|
||||
return ExtendNSTextFieldDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
|
@ -120,10 +120,6 @@ final class ExtendTableViewDelegateProxy
|
||||
final class UITableViewSubclass1
|
||||
: UITableView
|
||||
, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
|
||||
return ExtendTableViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -151,9 +147,6 @@ final class ExtendTableViewDataSourceProxy
|
||||
final class UITableViewSubclass2
|
||||
: UITableView
|
||||
, TestDelegateControl {
|
||||
override func createRxDataSourceProxy() -> RxTableViewDataSourceProxy {
|
||||
return ExtendTableViewDataSourceProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
if dataSource != nil {
|
||||
@ -184,10 +177,6 @@ final class ExtendCollectionViewDelegateProxy
|
||||
final class UICollectionViewSubclass1
|
||||
: UICollectionView
|
||||
, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
|
||||
return ExtendCollectionViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -215,9 +204,6 @@ final class ExtendCollectionViewDataSourceProxy
|
||||
final class UICollectionViewSubclass2
|
||||
: UICollectionView
|
||||
, TestDelegateControl {
|
||||
override func createRxDataSourceProxy() -> RxCollectionViewDataSourceProxy {
|
||||
return ExtendCollectionViewDataSourceProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
if dataSource != nil {
|
||||
@ -248,10 +234,6 @@ final class ExtendScrollViewDelegateProxy
|
||||
final class UIScrollViewSubclass
|
||||
: UIScrollView
|
||||
, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
|
||||
return ExtendScrollViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -280,11 +262,6 @@ final class ExtendSearchBarDelegateProxy
|
||||
final class UISearchBarSubclass
|
||||
: UISearchBar
|
||||
, TestDelegateControl {
|
||||
|
||||
override func createRxDelegateProxy() -> RxSearchBarDelegateProxy {
|
||||
return ExtendSearchBarDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -313,10 +290,6 @@ final class ExtendTextViewDelegateProxy
|
||||
final class UITextViewSubclass
|
||||
: UITextView
|
||||
, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxScrollViewDelegateProxy {
|
||||
return ExtendTextViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -341,11 +314,6 @@ final class ExtendSearchControllerDelegateProxy
|
||||
final class UISearchControllerSubclass
|
||||
: UISearchController
|
||||
, TestDelegateControl {
|
||||
|
||||
override func createRxDelegateProxy() -> RxSearchControllerDelegateProxy {
|
||||
return ExtendSearchControllerDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -371,11 +339,6 @@ final class ExtendPickerViewDelegateProxy
|
||||
final class UIPickerViewSubclass
|
||||
: UIPickerView
|
||||
, TestDelegateControl {
|
||||
|
||||
public override func createRxDelegateProxy() -> RxPickerViewDelegateProxy {
|
||||
return ExtendPickerViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -400,11 +363,6 @@ final class ExtendWebViewDelegateProxy
|
||||
}
|
||||
|
||||
final class UIWebViewSubclass: UIWebView, TestDelegateControl {
|
||||
|
||||
override func createRxDelegateProxy() -> RxWebViewDelegateProxy {
|
||||
return ExtendWebViewDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -437,11 +395,6 @@ final class ExtendTextStorageDelegateProxy
|
||||
final class NSTextStorageSubclass
|
||||
: NSTextStorage
|
||||
, TestDelegateControl {
|
||||
|
||||
override func createRxDelegateProxy() -> RxTextStorageDelegateProxy {
|
||||
return ExtendTextStorageDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -489,10 +442,6 @@ final class ExtendTabBarDelegateProxy
|
||||
}
|
||||
|
||||
final class UINavigationControllerSubclass: UINavigationController, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxNavigationControllerDelegateProxy {
|
||||
return ExtendNavigationControllerDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -511,10 +460,6 @@ final class UINavigationControllerSubclass: UINavigationController, TestDelegate
|
||||
final class UITabBarControllerSubclass
|
||||
: UITabBarController
|
||||
, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxTabBarControllerDelegateProxy {
|
||||
return ExtendTabBarControllerDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
@ -529,10 +474,6 @@ final class UITabBarControllerSubclass
|
||||
}
|
||||
|
||||
final class UITabBarSubclass: UITabBar, TestDelegateControl {
|
||||
override func createRxDelegateProxy() -> RxTabBarDelegateProxy {
|
||||
return ExtendTabBarDelegateProxy(parentObject: self)
|
||||
}
|
||||
|
||||
func doThatTest(_ value: Int) {
|
||||
(delegate as! TestDelegateProtocol).testEventHappened?(value)
|
||||
}
|
||||
|
@ -56,6 +56,62 @@ extension TestDelegateControl {
|
||||
// MARK: Tests
|
||||
|
||||
final class DelegateProxyTest : RxTest {
|
||||
override func setUp() {
|
||||
super.setUp()
|
||||
// setup extending of DelegateProxies
|
||||
#if os(iOS) || os(tvOS)
|
||||
RxScrollViewDelegateProxy.extend { (parentObject: UIScrollViewSubclass) in
|
||||
ExtendScrollViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxScrollViewDelegateProxy.extend { (parentObject: UITableViewSubclass1) in
|
||||
ExtendTableViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxTableViewDataSourceProxy.extend { (parentObject: UITableViewSubclass2) in
|
||||
ExtendTableViewDataSourceProxy(parentObject: parentObject)
|
||||
}
|
||||
RxScrollViewDelegateProxy.extend { (parentObject: UICollectionViewSubclass1) in
|
||||
ExtendCollectionViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxCollectionViewDataSourceProxy.extend { (parentObject: UICollectionViewSubclass2) in
|
||||
ExtendCollectionViewDataSourceProxy(parentObject: parentObject)
|
||||
}
|
||||
RxScrollViewDelegateProxy.extend { (parentObject: UITextViewSubclass) in
|
||||
ExtendTextViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxTextStorageDelegateProxy.extend { (parentObject: NSTextStorageSubclass) in
|
||||
ExtendTextStorageDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxNavigationControllerDelegateProxy.extend { (parentObject: UINavigationControllerSubclass) in
|
||||
ExtendNavigationControllerDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxTabBarControllerDelegateProxy.extend { (parentObject: UITabBarControllerSubclass) in
|
||||
ExtendTabBarControllerDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxTabBarDelegateProxy.extend { (parentObject: UITabBarSubclass) -> AnyObject in
|
||||
ExtendTabBarDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
#endif
|
||||
#if os(iOS)
|
||||
RxSearchBarDelegateProxy.extend { (parentObject: UISearchBarSubclass) in
|
||||
ExtendSearchBarDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxSearchControllerDelegateProxy.extend { (parentObject: UISearchControllerSubclass) in
|
||||
ExtendSearchControllerDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxPickerViewDelegateProxy.extend { (parentObject: UIPickerViewSubclass) in
|
||||
ExtendPickerViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
RxWebViewDelegateProxy.extend { (parentObject: UIWebViewSubclass) in
|
||||
ExtendWebViewDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
#endif
|
||||
#if os(macOS)
|
||||
RxTextFieldDelegateProxy.extend { (parentObject: NSTextFieldSubclass) in
|
||||
ExtendNSTextFieldDelegateProxy(parentObject: parentObject)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
func test_OnInstallDelegateIsRetained() {
|
||||
let view = ThreeDSectionedView()
|
||||
let mock = MockThreeDSectionedViewProtocol()
|
||||
@ -419,6 +475,11 @@ final class ThreeDSectionedView: NSObject {
|
||||
final class ThreeDSectionedViewDelegateProxy : DelegateProxy
|
||||
, ThreeDSectionedViewProtocol
|
||||
, DelegateProxyType {
|
||||
|
||||
static var factories: [((AnyObject) -> AnyObject?)] = [
|
||||
{ ThreeDSectionedViewDelegateProxy(parentObject: $0) }
|
||||
]
|
||||
|
||||
required init(parentObject: AnyObject) {
|
||||
super.init(parentObject: parentObject)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user