initial
This commit is contained in:
33
Pods/RxCocoa/RxCocoa/macOS/NSButton+Rx.swift
generated
Normal file
33
Pods/RxCocoa/RxCocoa/macOS/NSButton+Rx.swift
generated
Normal file
@@ -0,0 +1,33 @@
|
||||
//
|
||||
// NSButton+Rx.swift
|
||||
// RxCocoa
|
||||
//
|
||||
// Created by Krunoslav Zaher on 5/17/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
import RxSwift
|
||||
import Cocoa
|
||||
|
||||
extension Reactive where Base: NSButton {
|
||||
|
||||
/// Reactive wrapper for control event.
|
||||
public var tap: ControlEvent<Void> {
|
||||
self.controlEvent
|
||||
}
|
||||
|
||||
/// Reactive wrapper for `state` property`.
|
||||
public var state: ControlProperty<NSControl.StateValue> {
|
||||
return self.base.rx.controlProperty(
|
||||
getter: { control in
|
||||
return control.state
|
||||
}, setter: { (control: NSButton, state: NSControl.StateValue) in
|
||||
control.state = state
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
87
Pods/RxCocoa/RxCocoa/macOS/NSControl+Rx.swift
generated
Normal file
87
Pods/RxCocoa/RxCocoa/macOS/NSControl+Rx.swift
generated
Normal file
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// NSControl+Rx.swift
|
||||
// RxCocoa
|
||||
//
|
||||
// Created by Krunoslav Zaher on 5/31/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
import Cocoa
|
||||
import RxSwift
|
||||
|
||||
private var rx_value_key: UInt8 = 0
|
||||
private var rx_control_events_key: UInt8 = 0
|
||||
|
||||
extension Reactive where Base: NSControl {
|
||||
|
||||
/// Reactive wrapper for control event.
|
||||
public var controlEvent: ControlEvent<()> {
|
||||
MainScheduler.ensureRunningOnMainThread()
|
||||
|
||||
let source = self.lazyInstanceObservable(&rx_control_events_key) { () -> Observable<Void> in
|
||||
Observable.create { [weak control = self.base] observer in
|
||||
MainScheduler.ensureRunningOnMainThread()
|
||||
|
||||
guard let control = control else {
|
||||
observer.on(.completed)
|
||||
return Disposables.create()
|
||||
}
|
||||
|
||||
let observer = ControlTarget(control: control) { _ in
|
||||
observer.on(.next(()))
|
||||
}
|
||||
|
||||
return observer
|
||||
}
|
||||
.take(until: self.deallocated)
|
||||
.share()
|
||||
}
|
||||
|
||||
return ControlEvent(events: source)
|
||||
}
|
||||
|
||||
/// Creates a `ControlProperty` that is triggered by target/action pattern value updates.
|
||||
///
|
||||
/// - parameter getter: Property value getter.
|
||||
/// - parameter setter: Property value setter.
|
||||
public func controlProperty<T>(
|
||||
getter: @escaping (Base) -> T,
|
||||
setter: @escaping (Base, T) -> Void
|
||||
) -> ControlProperty<T> {
|
||||
MainScheduler.ensureRunningOnMainThread()
|
||||
|
||||
let source = self.base.rx.lazyInstanceObservable(&rx_value_key) { () -> Observable<()> in
|
||||
return Observable.create { [weak weakControl = self.base] (observer: AnyObserver<()>) in
|
||||
guard let control = weakControl else {
|
||||
observer.on(.completed)
|
||||
return Disposables.create()
|
||||
}
|
||||
|
||||
observer.on(.next(()))
|
||||
|
||||
let observer = ControlTarget(control: control) { _ in
|
||||
if weakControl != nil {
|
||||
observer.on(.next(()))
|
||||
}
|
||||
}
|
||||
|
||||
return observer
|
||||
}
|
||||
.take(until: self.deallocated)
|
||||
.share(replay: 1, scope: .whileConnected)
|
||||
}
|
||||
.flatMap { [weak base] _ -> Observable<T> in
|
||||
guard let control = base else { return Observable.empty() }
|
||||
return Observable.just(getter(control))
|
||||
}
|
||||
|
||||
let bindingObserver = Binder(self.base, binding: setter)
|
||||
|
||||
return ControlProperty(values: source, valueSink: bindingObserver)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
30
Pods/RxCocoa/RxCocoa/macOS/NSSlider+Rx.swift
generated
Normal file
30
Pods/RxCocoa/RxCocoa/macOS/NSSlider+Rx.swift
generated
Normal file
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// NSSlider+Rx.swift
|
||||
// RxCocoa
|
||||
//
|
||||
// Created by Junior B. on 24/05/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
import RxSwift
|
||||
import Cocoa
|
||||
|
||||
extension Reactive where Base: NSSlider {
|
||||
|
||||
/// Reactive wrapper for `value` property.
|
||||
public var value: ControlProperty<Double> {
|
||||
return self.base.rx.controlProperty(
|
||||
getter: { control -> Double in
|
||||
return control.doubleValue
|
||||
},
|
||||
setter: { control, value in
|
||||
control.doubleValue = value
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
87
Pods/RxCocoa/RxCocoa/macOS/NSTextField+Rx.swift
generated
Normal file
87
Pods/RxCocoa/RxCocoa/macOS/NSTextField+Rx.swift
generated
Normal file
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// NSTextField+Rx.swift
|
||||
// RxCocoa
|
||||
//
|
||||
// Created by Krunoslav Zaher on 5/17/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
import Cocoa
|
||||
import RxSwift
|
||||
|
||||
/// Delegate proxy for `NSTextField`.
|
||||
///
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open class RxTextFieldDelegateProxy
|
||||
: DelegateProxy<NSTextField, NSTextFieldDelegate>
|
||||
, DelegateProxyType
|
||||
, NSTextFieldDelegate {
|
||||
|
||||
/// Typed parent object.
|
||||
public weak private(set) var textField: NSTextField?
|
||||
|
||||
/// Initializes `RxTextFieldDelegateProxy`
|
||||
///
|
||||
/// - parameter textField: Parent object for delegate proxy.
|
||||
init(textField: NSTextField) {
|
||||
self.textField = textField
|
||||
super.init(parentObject: textField, delegateProxy: RxTextFieldDelegateProxy.self)
|
||||
}
|
||||
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxTextFieldDelegateProxy(textField: $0) }
|
||||
}
|
||||
|
||||
fileprivate let textSubject = PublishSubject<String?>()
|
||||
|
||||
// MARK: Delegate methods
|
||||
open func controlTextDidChange(_ notification: Notification) {
|
||||
let textField: NSTextField = castOrFatalError(notification.object)
|
||||
let nextValue = textField.stringValue
|
||||
self.textSubject.on(.next(nextValue))
|
||||
_forwardToDelegate?.controlTextDidChange?(notification)
|
||||
}
|
||||
|
||||
// MARK: Delegate proxy methods
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open class func currentDelegate(for object: ParentObject) -> NSTextFieldDelegate? {
|
||||
object.delegate
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open class func setCurrentDelegate(_ delegate: NSTextFieldDelegate?, to object: ParentObject) {
|
||||
object.delegate = delegate
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: NSTextField {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
///
|
||||
/// For more information take a look at `DelegateProxyType` protocol documentation.
|
||||
public var delegate: DelegateProxy<NSTextField, NSTextFieldDelegate> {
|
||||
RxTextFieldDelegateProxy.proxy(for: self.base)
|
||||
}
|
||||
|
||||
/// Reactive wrapper for `text` property.
|
||||
public var text: ControlProperty<String?> {
|
||||
let delegate = RxTextFieldDelegateProxy.proxy(for: self.base)
|
||||
|
||||
let source = Observable.deferred { [weak textField = self.base] in
|
||||
delegate.textSubject.startWith(textField?.stringValue)
|
||||
}.take(until: self.deallocated)
|
||||
|
||||
let observer = Binder(self.base) { (control, value: String?) in
|
||||
control.stringValue = value ?? ""
|
||||
}
|
||||
|
||||
return ControlProperty(values: source, valueSink: observer.asObserver())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
94
Pods/RxCocoa/RxCocoa/macOS/NSTextView+Rx.swift
generated
Normal file
94
Pods/RxCocoa/RxCocoa/macOS/NSTextView+Rx.swift
generated
Normal file
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// NSTextView+Rx.swift
|
||||
// RxCocoa
|
||||
//
|
||||
// Created by Cee on 8/5/18.
|
||||
// Copyright © 2018 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(macOS)
|
||||
|
||||
import Cocoa
|
||||
import RxSwift
|
||||
|
||||
/// Delegate proxy for `NSTextView`.
|
||||
///
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open class RxTextViewDelegateProxy: DelegateProxy<NSTextView, NSTextViewDelegate>, DelegateProxyType, NSTextViewDelegate {
|
||||
|
||||
#if compiler(>=5.2)
|
||||
/// Typed parent object.
|
||||
///
|
||||
/// - note: Since Swift 5.2 and Xcode 11.4, Apple have suddenly
|
||||
/// disallowed using `weak` for NSTextView. For more details
|
||||
/// see this GitHub Issue: https://git.io/JvSRn
|
||||
public private(set) var textView: NSTextView?
|
||||
#else
|
||||
/// Typed parent object.
|
||||
public weak private(set) var textView: NSTextView?
|
||||
#endif
|
||||
|
||||
/// Initializes `RxTextViewDelegateProxy`
|
||||
///
|
||||
/// - parameter textView: Parent object for delegate proxy.
|
||||
init(textView: NSTextView) {
|
||||
self.textView = textView
|
||||
super.init(parentObject: textView, delegateProxy: RxTextViewDelegateProxy.self)
|
||||
}
|
||||
|
||||
public static func registerKnownImplementations() {
|
||||
self.register { RxTextViewDelegateProxy(textView: $0) }
|
||||
}
|
||||
|
||||
fileprivate let textSubject = PublishSubject<String>()
|
||||
|
||||
// MARK: Delegate methods
|
||||
|
||||
open func textDidChange(_ notification: Notification) {
|
||||
let textView: NSTextView = castOrFatalError(notification.object)
|
||||
let nextValue = textView.string
|
||||
self.textSubject.on(.next(nextValue))
|
||||
self._forwardToDelegate?.textDidChange?(notification)
|
||||
}
|
||||
|
||||
// MARK: Delegate proxy methods
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open class func currentDelegate(for object: ParentObject) -> NSTextViewDelegate? {
|
||||
object.delegate
|
||||
}
|
||||
|
||||
/// For more information take a look at `DelegateProxyType`.
|
||||
open class func setCurrentDelegate(_ delegate: NSTextViewDelegate?, to object: ParentObject) {
|
||||
object.delegate = delegate
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension Reactive where Base: NSTextView {
|
||||
|
||||
/// Reactive wrapper for `delegate`.
|
||||
///
|
||||
/// For more information take a look at `DelegateProxyType` protocol documentation.
|
||||
public var delegate: DelegateProxy<NSTextView, NSTextViewDelegate> {
|
||||
RxTextViewDelegateProxy.proxy(for: self.base)
|
||||
}
|
||||
|
||||
/// Reactive wrapper for `string` property.
|
||||
public var string: ControlProperty<String> {
|
||||
let delegate = RxTextViewDelegateProxy.proxy(for: self.base)
|
||||
|
||||
let source = Observable.deferred { [weak textView = self.base] in
|
||||
delegate.textSubject.startWith(textView?.string ?? "")
|
||||
}.take(until: self.deallocated)
|
||||
|
||||
let observer = Binder(self.base) { control, value in
|
||||
control.string = value
|
||||
}
|
||||
|
||||
return ControlProperty(values: source, valueSink: observer.asObserver())
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
21
Pods/RxCocoa/RxCocoa/macOS/NSView+Rx.swift
generated
Normal file
21
Pods/RxCocoa/RxCocoa/macOS/NSView+Rx.swift
generated
Normal file
@@ -0,0 +1,21 @@
|
||||
//
|
||||
// NSView+Rx.swift
|
||||
// RxCocoa
|
||||
//
|
||||
// Created by Krunoslav Zaher on 12/6/15.
|
||||
// Copyright © 2015 Krunoslav Zaher. All rights reserved.
|
||||
//
|
||||
|
||||
#if os(macOS)
|
||||
import Cocoa
|
||||
import RxSwift
|
||||
|
||||
extension Reactive where Base: NSView {
|
||||
/// Bindable sink for `alphaValue` property.
|
||||
public var alpha: Binder<CGFloat> {
|
||||
return Binder(self.base) { view, value in
|
||||
view.alphaValue = value
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user