adds `UISearchBar` extensions
This commit is contained in:
parent
900035d78b
commit
483c22abd7
|
|
@ -24,6 +24,11 @@ All notable changes to this project will be documented in this file.
|
|||
* Deprecates `BinaryDisposable` in favor of `Disposables.create(_:_:)`
|
||||
* Deprecates `toObservable` in favor of `Observable.from()`.
|
||||
* Replaces old javascript automation tests with Swift UI Tests.
|
||||
* adds `UISearchBar` extensions:
|
||||
* `bookmarkButtonClicked`
|
||||
* `resultsListButtonClicked`
|
||||
* `textDidBeginEditing`
|
||||
* `textDidEndEditing`
|
||||
* ...
|
||||
|
||||
#### Anomalies
|
||||
|
|
|
|||
|
|
@ -93,8 +93,30 @@ extension Reactive where Base: UISearchBar {
|
|||
}
|
||||
return ControlEvent(events: source)
|
||||
}
|
||||
|
||||
/**
|
||||
Reactive wrapper for delegate method `searchBarBookmarkButtonClicked`.
|
||||
*/
|
||||
public var bookmarkButtonClicked: ControlEvent<Void> {
|
||||
let source: Observable<Void> = self.delegate.observe(#selector(UISearchBarDelegate.searchBarBookmarkButtonClicked(_:)))
|
||||
.map { _ in
|
||||
return ()
|
||||
}
|
||||
return ControlEvent(events: source)
|
||||
}
|
||||
|
||||
/**
|
||||
Reactive wrapper for delegate method `searchBarResultsListButtonClicked`.
|
||||
*/
|
||||
public var resultsListButtonClicked: ControlEvent<Void> {
|
||||
let source: Observable<Void> = self.delegate.observe(#selector(UISearchBarDelegate.searchBarResultsListButtonClicked(_:)))
|
||||
.map { _ in
|
||||
return ()
|
||||
}
|
||||
return ControlEvent(events: source)
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/**
|
||||
Reactive wrapper for delegate method `searchBarSearchButtonClicked`.
|
||||
*/
|
||||
|
|
@ -105,6 +127,29 @@ extension Reactive where Base: UISearchBar {
|
|||
}
|
||||
return ControlEvent(events: source)
|
||||
}
|
||||
|
||||
/**
|
||||
Reactive wrapper for delegate method `searchBarTextDidBeginEditing`.
|
||||
*/
|
||||
public var textDidBeginEditing: ControlEvent<Void> {
|
||||
let source: Observable<Void> = self.delegate.observe(#selector(UISearchBarDelegate.searchBarTextDidBeginEditing(_:)))
|
||||
.map { _ in
|
||||
return ()
|
||||
}
|
||||
return ControlEvent(events: source)
|
||||
}
|
||||
|
||||
/**
|
||||
Reactive wrapper for delegate method `searchBarTextDidEndEditing`.
|
||||
*/
|
||||
public var textDidEndEditing: ControlEvent<Void> {
|
||||
let source: Observable<Void> = self.delegate.observe(#selector(UISearchBarDelegate.searchBarTextDidEndEditing(_:)))
|
||||
.map { _ in
|
||||
return ()
|
||||
}
|
||||
return ControlEvent(events: source)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -96,8 +96,47 @@ class UISearchBarTests : RxTest {
|
|||
let createView: () -> UISearchBar = { UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) }
|
||||
ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx.cancelButtonClicked }
|
||||
}
|
||||
|
||||
func testBookmarkButtonClicked() {
|
||||
let searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
||||
|
||||
var tapped = false
|
||||
|
||||
let _ = searchBar.rx.bookmarkButtonClicked.subscribe(onNext: { _ in
|
||||
tapped = true
|
||||
})
|
||||
|
||||
XCTAssertFalse(tapped)
|
||||
searchBar.delegate!.searchBarBookmarkButtonClicked!(searchBar)
|
||||
XCTAssertTrue(tapped)
|
||||
}
|
||||
|
||||
func testBookmarkButtonClicked_DelegateEventCompletesOnDealloc() {
|
||||
let createView: () -> UISearchBar = { UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) }
|
||||
ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx.bookmarkButtonClicked }
|
||||
}
|
||||
|
||||
func testResultsListButtonClicked() {
|
||||
let searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
||||
|
||||
var tapped = false
|
||||
|
||||
let _ = searchBar.rx.resultsListButtonClicked.subscribe(onNext: { _ in
|
||||
tapped = true
|
||||
})
|
||||
|
||||
XCTAssertFalse(tapped)
|
||||
searchBar.delegate!.searchBarResultsListButtonClicked!(searchBar)
|
||||
XCTAssertTrue(tapped)
|
||||
}
|
||||
|
||||
func testResultsListButtonClicked_DelegateEventCompletesOnDealloc() {
|
||||
let createView: () -> UISearchBar = { UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) }
|
||||
ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx.resultsListButtonClicked }
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
func testSearchButtonClicked() {
|
||||
let searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
||||
|
||||
|
|
@ -116,4 +155,41 @@ class UISearchBarTests : RxTest {
|
|||
let createView: () -> UISearchBar = { UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) }
|
||||
ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx.searchButtonClicked }
|
||||
}
|
||||
|
||||
func testSearchBarTextDidBeginEditing(){
|
||||
let searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
||||
|
||||
var tapped = false
|
||||
let _ = searchBar.rx.textDidBeginEditing.subscribe(onNext: { _ in
|
||||
tapped = true
|
||||
})
|
||||
XCTAssertFalse(tapped)
|
||||
searchBar.delegate!.searchBarTextDidBeginEditing!(searchBar)
|
||||
XCTAssertTrue(tapped)
|
||||
}
|
||||
|
||||
func testSearchBarTextDidBeginEditing_DelegateEventCompletesOnDealloc() {
|
||||
let createView: () -> UISearchBar = { UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) }
|
||||
ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx.textDidBeginEditing }
|
||||
}
|
||||
|
||||
func testSearchBarTextDidEndEditing(){
|
||||
let searchBar = UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
|
||||
|
||||
var tapped = false
|
||||
let _ = searchBar.rx.textDidEndEditing.subscribe(onNext: { _ in
|
||||
tapped = true
|
||||
})
|
||||
XCTAssertFalse(tapped)
|
||||
searchBar.delegate!.searchBarTextDidBeginEditing!(searchBar)
|
||||
XCTAssertFalse(tapped)
|
||||
searchBar.delegate!.searchBarTextDidEndEditing!(searchBar)
|
||||
XCTAssertTrue(tapped)
|
||||
}
|
||||
|
||||
func testSearchBarTextDidEndEditing_DelegateEventCompletesOnDealloc() {
|
||||
let createView: () -> UISearchBar = { UISearchBar(frame: CGRect(x: 0, y: 0, width: 1, height: 1)) }
|
||||
ensureEventDeallocated(createView) { (view: UISearchBar) in view.rx.textDidEndEditing }
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue