tvOS Fixes for UISearchBar

- `searchBarCancelButtonClicked:` is only available on iOS.
- UISearchBar instantiation is not supported on tvOS, so all subclass
  delegate methods and tests are skipped.
This commit is contained in:
Stephen H. Gerstacker 2016-03-27 21:31:53 -04:00
parent 2db92e9727
commit f58d032d34
4 changed files with 16 additions and 0 deletions

View File

@ -30,6 +30,7 @@ public class RxSearchBarDelegateProxy : DelegateProxy
// MARK: Delegate proxy methods
#if os(iOS)
/**
For more information take a look at `DelegateProxyType`.
*/
@ -38,6 +39,8 @@ public class RxSearchBarDelegateProxy : DelegateProxy
return castOrFatalError(searchBar.rx_createDelegateProxy())
}
#endif
}
#endif

View File

@ -18,6 +18,7 @@ import UIKit
extension UISearchBar {
#if os(iOS)
/**
Factory method that enables subclasses to implement their own `rx_delegate`.
@ -26,6 +27,7 @@ extension UISearchBar {
public func rx_createDelegateProxy() -> RxSearchBarDelegateProxy {
return RxSearchBarDelegateProxy(parentObject: self)
}
#endif
/**
Reactive wrapper for `delegate`.
@ -78,6 +80,7 @@ extension UISearchBar {
return ControlProperty(values: source, valueSink: bindingObserver)
}
#if os(iOS)
/**
Reactive wrapper for delegate method `searchBarCancelButtonClicked`.
*/
@ -88,6 +91,7 @@ extension UISearchBar {
}
return ControlEvent(events: source)
}
#endif
/**
Reactive wrapper for delegate method `searchBarSearchButtonClicked`.

View File

@ -44,11 +44,13 @@ import XCTest
optional func testEventHappened(value: Int)
}
#if os(iOS)
@objc protocol UISearchBarDelegateSubclass
: UISearchBarDelegate
, TestDelegateProtocol {
optional func testEventHappened(value: Int)
}
#endif
@objc protocol UITextViewDelegateSubclass
: UITextViewDelegate
@ -96,11 +98,13 @@ extension DelegateProxyTest {
// MARK: UISearchBar
#if os(iOS)
extension DelegateProxyTest {
func test_UISearchBarDelegateExtension() {
performDelegateTest(UISearchBarSubclass(frame: CGRect.zero))
}
}
#endif
// MARK: UITextView
@ -257,6 +261,7 @@ class UIScrollViewSubclass
}
}
#if os(iOS)
class ExtendSearchBarDelegateProxy
: RxSearchBarDelegateProxy
, UISearchBarDelegateSubclass {
@ -271,6 +276,7 @@ class ExtendSearchBarDelegateProxy
class UISearchBarSubclass
: UISearchBar
, TestDelegateControl {
override func rx_createDelegateProxy() -> RxSearchBarDelegateProxy {
return ExtendSearchBarDelegateProxy(parentObject: self)
}
@ -285,6 +291,7 @@ class UISearchBarSubclass
.map { a in (a[0] as! NSNumber).integerValue }
}
}
#endif
class ExtendTextViewDelegateProxy
: RxTextViewDelegateProxy

View File

@ -77,6 +77,7 @@ class UISearchBarTests : RxTest {
XCTAssertEqual(searchBar.selectedScopeButtonIndex, 1)
}
#if os(iOS)
func testCancelTap() {
let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1))
@ -95,6 +96,7 @@ class UISearchBarTests : RxTest {
let createView: () -> UISearchBar = { UISearchBar(frame: CGRectMake(0, 0, 1, 1)) }
ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx_cancelTap }
}
#endif
func testSearchTap() {
let searchBar = UISearchBar(frame: CGRectMake(0, 0, 1, 1))