2016-05-13 13:15:52 +03:00
|
|
|
//
|
|
|
|
// UITabBar+Rx.swift
|
2016-10-15 15:38:22 +03:00
|
|
|
// RxCocoa
|
2016-05-13 13:15:52 +03:00
|
|
|
//
|
|
|
|
// Created by Jesse Farless on 5/13/16.
|
|
|
|
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
#if os(iOS) || os(tvOS)
|
|
|
|
|
2017-11-04 20:53:02 +03:00
|
|
|
import UIKit
|
2016-05-13 13:15:52 +03:00
|
|
|
import RxSwift
|
|
|
|
|
|
|
|
/**
|
|
|
|
iOS only
|
|
|
|
*/
|
|
|
|
#if os(iOS)
|
2016-08-03 21:11:43 +03:00
|
|
|
extension Reactive where Base: UITabBar {
|
2016-05-13 13:15:52 +03:00
|
|
|
|
2017-06-14 16:57:42 +03:00
|
|
|
/// Reactive wrapper for `delegate` message `tabBar(_:willBeginCustomizing:)`.
|
2016-08-03 21:11:43 +03:00
|
|
|
public var willBeginCustomizing: ControlEvent<[UITabBarItem]> {
|
2016-06-22 17:15:37 +03:00
|
|
|
|
2016-10-03 00:12:11 +03:00
|
|
|
let source = delegate.methodInvoked(#selector(UITabBarDelegate.tabBar(_:willBeginCustomizing:)))
|
2016-05-13 13:15:52 +03:00
|
|
|
.map { a in
|
|
|
|
return try castOrThrow([UITabBarItem].self, a[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
return ControlEvent(events: source)
|
|
|
|
}
|
|
|
|
|
2017-06-14 16:57:42 +03:00
|
|
|
/// Reactive wrapper for `delegate` message `tabBar(_:didBeginCustomizing:)`.
|
2016-08-03 21:11:43 +03:00
|
|
|
public var didBeginCustomizing: ControlEvent<[UITabBarItem]> {
|
2016-10-03 00:12:11 +03:00
|
|
|
let source = delegate.methodInvoked(#selector(UITabBarDelegate.tabBar(_:didBeginCustomizing:)))
|
2016-05-13 13:15:52 +03:00
|
|
|
.map { a in
|
|
|
|
return try castOrThrow([UITabBarItem].self, a[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
return ControlEvent(events: source)
|
|
|
|
}
|
|
|
|
|
2017-06-14 16:57:42 +03:00
|
|
|
/// Reactive wrapper for `delegate` message `tabBar(_:willEndCustomizing:changed:)`.
|
2016-08-03 21:11:43 +03:00
|
|
|
public var willEndCustomizing: ControlEvent<([UITabBarItem], Bool)> {
|
2016-10-03 00:12:11 +03:00
|
|
|
let source = delegate.methodInvoked(#selector(UITabBarDelegate.tabBar(_:willEndCustomizing:changed:)))
|
2016-10-02 23:55:39 +03:00
|
|
|
.map { (a: [Any]) -> (([UITabBarItem], Bool)) in
|
2016-05-13 13:15:52 +03:00
|
|
|
let items = try castOrThrow([UITabBarItem].self, a[1])
|
|
|
|
let changed = try castOrThrow(Bool.self, a[2])
|
|
|
|
return (items, changed)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ControlEvent(events: source)
|
|
|
|
}
|
|
|
|
|
2017-06-14 16:57:42 +03:00
|
|
|
/// Reactive wrapper for `delegate` message `tabBar(_:didEndCustomizing:changed:)`.
|
2016-08-03 21:11:43 +03:00
|
|
|
public var didEndCustomizing: ControlEvent<([UITabBarItem], Bool)> {
|
2016-10-03 00:12:11 +03:00
|
|
|
let source = delegate.methodInvoked(#selector(UITabBarDelegate.tabBar(_:didEndCustomizing:changed:)))
|
2016-10-02 23:55:39 +03:00
|
|
|
.map { (a: [Any]) -> (([UITabBarItem], Bool)) in
|
2016-05-13 13:15:52 +03:00
|
|
|
let items = try castOrThrow([UITabBarItem].self, a[1])
|
|
|
|
let changed = try castOrThrow(Bool.self, a[2])
|
|
|
|
return (items, changed)
|
|
|
|
}
|
|
|
|
|
|
|
|
return ControlEvent(events: source)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
iOS and tvOS
|
|
|
|
*/
|
|
|
|
|
2016-08-15 18:46:13 +03:00
|
|
|
extension Reactive where Base: UITabBar {
|
2016-10-23 20:26:22 +03:00
|
|
|
/// Reactive wrapper for `delegate`.
|
|
|
|
///
|
|
|
|
/// For more information take a look at `DelegateProxyType` protocol documentation.
|
2017-09-13 18:12:06 +03:00
|
|
|
public var delegate: DelegateProxy<UITabBar, UITabBarDelegate> {
|
2019-12-28 22:01:28 +03:00
|
|
|
RxTabBarDelegateProxy.proxy(for: base)
|
2016-05-13 13:15:52 +03:00
|
|
|
}
|
|
|
|
|
2017-06-14 16:57:42 +03:00
|
|
|
/// Reactive wrapper for `delegate` message `tabBar(_:didSelect:)`.
|
2016-08-03 21:11:43 +03:00
|
|
|
public var didSelectItem: ControlEvent<UITabBarItem> {
|
2016-10-03 00:12:11 +03:00
|
|
|
let source = delegate.methodInvoked(#selector(UITabBarDelegate.tabBar(_:didSelect:)))
|
2016-05-13 13:15:52 +03:00
|
|
|
.map { a in
|
|
|
|
return try castOrThrow(UITabBarItem.self, a[1])
|
|
|
|
}
|
|
|
|
|
|
|
|
return ControlEvent(events: source)
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|