Merge pull request #660 from ReactiveX/typed-gesture-recognizer-extension
Typed gesture recognizer extension
This commit is contained in:
commit
81b9ff7322
|
|
@ -1129,6 +1129,9 @@
|
|||
D2EBEB431BB9B6DE003A27DC /* SubjectType.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093CC11B8A72BE0088E94D /* SubjectType.swift */; };
|
||||
D2EBEB441BB9B6DE003A27DC /* Variable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093CC21B8A72BE0088E94D /* Variable.swift */; };
|
||||
D2EBEB8A1BB9B9EE003A27DC /* ObservableConvertibleType+Blocking.swift in Sources */ = {isa = PBXBuildFile; fileRef = C8093F581B8A73A20088E94D /* ObservableConvertibleType+Blocking.swift */; };
|
||||
D2F461021CD7AC1F00527B4D /* Reactive.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F461001CD7ABE400527B4D /* Reactive.swift */; };
|
||||
D2F461031CD7AC2000527B4D /* Reactive.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F461001CD7ABE400527B4D /* Reactive.swift */; };
|
||||
D2F461041CD7AC2100527B4D /* Reactive.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F461001CD7ABE400527B4D /* Reactive.swift */; };
|
||||
D2FC15B31BCB95E5007361FF /* SkipWhile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22B6D251BC8504A00BCE0AB /* SkipWhile.swift */; };
|
||||
D2FC15B41BCB95E7007361FF /* SkipWhile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22B6D251BC8504A00BCE0AB /* SkipWhile.swift */; };
|
||||
D2FC15B51BCB95E8007361FF /* SkipWhile.swift in Sources */ = {isa = PBXBuildFile; fileRef = D22B6D251BC8504A00BCE0AB /* SkipWhile.swift */; };
|
||||
|
|
@ -1690,6 +1693,7 @@
|
|||
D285BAC31BC0231000B3F602 /* SkipUntil.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SkipUntil.swift; sourceTree = "<group>"; };
|
||||
D2EA280C1BB9B5A200880ED3 /* RxSwift.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxSwift.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D2EBEB811BB9B99D003A27DC /* RxBlocking.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = RxBlocking.framework; sourceTree = BUILT_PRODUCTS_DIR; };
|
||||
D2F461001CD7ABE400527B4D /* Reactive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reactive.swift; sourceTree = "<group>"; };
|
||||
F31F35AF1BB4FED800961002 /* UIStepper+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "UIStepper+Rx.swift"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
|
|
@ -2087,6 +2091,7 @@
|
|||
C8DB968C1BF7595D0084BD53 /* KVORepresentable+Swift.swift */,
|
||||
C8BCD3F31C14B6D1005F1280 /* NSLayoutConstraint+Rx.swift */,
|
||||
C8D132431C42D15E00B59FFF /* SectionedViewDataSourceType.swift */,
|
||||
D2F461001CD7ABE400527B4D /* Reactive.swift */,
|
||||
);
|
||||
path = Common;
|
||||
sourceTree = "<group>";
|
||||
|
|
@ -3294,6 +3299,7 @@
|
|||
C80D338F1B91EF9E0014629D /* Observable+Bind.swift in Sources */,
|
||||
C88254311B8A752B00B02D69 /* UISegmentedControl+Rx.swift in Sources */,
|
||||
C8093EED1B8A732E0088E94D /* KVOObservable.swift in Sources */,
|
||||
D2F461021CD7AC1F00527B4D /* Reactive.swift in Sources */,
|
||||
AAE623761C82475700FC7801 /* UIProgressView+Rx.swift in Sources */,
|
||||
C8DB968D1BF7595D0084BD53 /* KVORepresentable+Swift.swift in Sources */,
|
||||
C80DDEB11BCE8CA3006A1832 /* Driver+Operators+arity.swift in Sources */,
|
||||
|
|
@ -3360,6 +3366,7 @@
|
|||
C8DB96841BF754C80084BD53 /* NSObject+Rx+KVORepresentable.swift in Sources */,
|
||||
C8C4B4C31C17727000828BD5 /* MessageSentObserver.swift in Sources */,
|
||||
C849EF8C1C3195950048AC4A /* Variable+Driver.swift in Sources */,
|
||||
D2F461031CD7AC2000527B4D /* Reactive.swift in Sources */,
|
||||
C8093F461B8A732E0088E94D /* NSButton+Rx.swift in Sources */,
|
||||
C80DDEA01BCE69BA006A1832 /* Driver+Subscription.swift in Sources */,
|
||||
C8093ED61B8A732E0088E94D /* _RXDelegateProxy.m in Sources */,
|
||||
|
|
@ -4288,6 +4295,7 @@
|
|||
C80DDEA11BCE69BA006A1832 /* Driver+Subscription.swift in Sources */,
|
||||
D2138C891BB9BEBE00339B5C /* DelegateProxyType.swift in Sources */,
|
||||
C811C89F1C24D80100A2DDD4 /* DeallocObservable.swift in Sources */,
|
||||
D2F461041CD7AC2100527B4D /* Reactive.swift in Sources */,
|
||||
C8BCD3EF1C14B5FB005F1280 /* UIView+Rx.swift in Sources */,
|
||||
D2138C921BB9BED600339B5C /* KVOObserver.swift in Sources */,
|
||||
D2138C831BB9BEBE00339B5C /* _RXKVOObserver.m in Sources */,
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
//
|
||||
// Reactive.swift
|
||||
// Rx
|
||||
//
|
||||
// Created by Yury Korolev on 5/2/16.
|
||||
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
/**
|
||||
We can use `Reactive` protocol as customization point for constrained protocol extensions.
|
||||
|
||||
General pattern would be:
|
||||
|
||||
|
||||
// 1. Conform SomeType to Reactive protocol
|
||||
extension SomeType: Reactive {}
|
||||
|
||||
// 2. Extend Reactive protocol with constrain on Self
|
||||
// Read as: Reactive Extension where Self is a SomeType
|
||||
extension Reactive where Self: SomeType {
|
||||
// 3. Put any specific reactive extension for SomeType here
|
||||
}
|
||||
|
||||
|
||||
With this approach we can have more specialized methods and properties using
|
||||
`Self` and not just specialized on common base type.
|
||||
|
||||
See UIGestureRecognizer+Rx.swift as an example
|
||||
*/
|
||||
|
||||
public protocol Reactive {
|
||||
|
||||
}
|
||||
|
|
@ -15,15 +15,15 @@ import RxSwift
|
|||
|
||||
|
||||
// This should be only used from `MainScheduler`
|
||||
class GestureTarget: RxTarget {
|
||||
typealias Callback = (UIGestureRecognizer) -> Void
|
||||
class GestureTarget<Recognizer: UIGestureRecognizer>: RxTarget {
|
||||
typealias Callback = (Recognizer) -> Void
|
||||
|
||||
let selector = #selector(ControlTarget.eventHandler(_:))
|
||||
|
||||
weak var gestureRecognizer: UIGestureRecognizer?
|
||||
weak var gestureRecognizer: Recognizer?
|
||||
var callback: Callback?
|
||||
|
||||
init(_ gestureRecognizer: UIGestureRecognizer, callback: Callback) {
|
||||
init(_ gestureRecognizer: Recognizer, callback: Callback) {
|
||||
self.gestureRecognizer = gestureRecognizer
|
||||
self.callback = callback
|
||||
|
||||
|
|
@ -51,13 +51,15 @@ class GestureTarget: RxTarget {
|
|||
}
|
||||
}
|
||||
|
||||
extension UIGestureRecognizer {
|
||||
extension UIGestureRecognizer: Reactive { }
|
||||
|
||||
extension Reactive where Self: UIGestureRecognizer {
|
||||
|
||||
/**
|
||||
Reactive wrapper for gesture recognizer events.
|
||||
*/
|
||||
public var rx_event: ControlEvent<UIGestureRecognizer> {
|
||||
let source: Observable<UIGestureRecognizer> = Observable.create { [weak self] observer in
|
||||
public var rx_event: ControlEvent<Self> {
|
||||
let source: Observable<Self> = Observable.create { [weak self] observer in
|
||||
MainScheduler.ensureExecutingOnScheduler()
|
||||
|
||||
guard let control = self else {
|
||||
|
|
|
|||
|
|
@ -440,6 +440,7 @@
|
|||
CBEE77541BD8C7B700AD584C /* ToArray.swift in Sources */ = {isa = PBXBuildFile; fileRef = CBEE77531BD8C7B700AD584C /* ToArray.swift */; };
|
||||
D2245A191BD5654C00E7146F /* WithLatestFrom.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2245A0B1BD564A700E7146F /* WithLatestFrom.swift */; };
|
||||
D2AF91981BD3D95900A008C1 /* Using.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2AF91881BD2C51900A008C1 /* Using.swift */; };
|
||||
D2F4611B1CD7AC9000527B4D /* Reactive.swift in Sources */ = {isa = PBXBuildFile; fileRef = D2F461051CD7AC4D00527B4D /* Reactive.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
|
@ -960,6 +961,7 @@
|
|||
CBEE77531BD8C7B700AD584C /* ToArray.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ToArray.swift; sourceTree = "<group>"; };
|
||||
D2245A0B1BD564A700E7146F /* WithLatestFrom.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = WithLatestFrom.swift; sourceTree = "<group>"; };
|
||||
D2AF91881BD2C51900A008C1 /* Using.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Using.swift; sourceTree = "<group>"; };
|
||||
D2F461051CD7AC4D00527B4D /* Reactive.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Reactive.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
|
@ -1626,6 +1628,7 @@
|
|||
C8CC3E6B1C95CB5300ABA17E /* Common */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
D2F461051CD7AC4D00527B4D /* Reactive.swift */,
|
||||
C8CC3E6C1C95CB5300ABA17E /* _RX.h */,
|
||||
C8CC3E6D1C95CB5300ABA17E /* _RX.m */,
|
||||
C8CC3E6E1C95CB5300ABA17E /* _RXDelegateProxy.h */,
|
||||
|
|
@ -2416,6 +2419,7 @@
|
|||
C8CC3F0C1C95CB5300ABA17E /* UICollectionView+Rx.swift in Sources */,
|
||||
C8297E561B6CF905000589EA /* WikipediaPage.swift in Sources */,
|
||||
C8297E571B6CF905000589EA /* Randomizer.swift in Sources */,
|
||||
D2F4611B1CD7AC9000527B4D /* Reactive.swift in Sources */,
|
||||
C89464C31BC6C2B00055219D /* Concat.swift in Sources */,
|
||||
C89464F41BC6C2B00055219D /* ObservableType.swift in Sources */,
|
||||
C89464CE1BC6C2B00055219D /* Generate.swift in Sources */,
|
||||
|
|
|
|||
Loading…
Reference in New Issue