forked from ReactiveX/RxSwift
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TextInput.swift
78 lines (62 loc) · 1.99 KB
/
TextInput.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
//
// TextInput.swift
// RxCocoa
//
// Created by Krunoslav Zaher on 5/12/16.
// Copyright © 2016 Krunoslav Zaher. All rights reserved.
//
import RxSwift
#if os(iOS) || os(tvOS)
import UIKit
/// Represents text input with reactive extensions.
public struct TextInput<Base: UITextInput> {
/// Base text input to extend.
public let base: Base
/// Reactive wrapper for `text` property.
public let text: ControlProperty<String?>
/// Initializes new text input.
///
/// - parameter base: Base object.
/// - parameter text: Textual control property.
public init(base: Base, text: ControlProperty<String?>) {
self.base = base
self.text = text
}
}
extension Reactive where Base: UITextField {
/// Reactive text input.
public var textInput: TextInput<Base> {
return TextInput(base: base, text: self.text)
}
}
extension Reactive where Base: UITextView {
/// Reactive text input.
public var textInput: TextInput<Base> {
return TextInput(base: base, text: self.text)
}
}
#endif
#if os(macOS)
import Cocoa
/// Represents text input with reactive extensions.
public struct TextInput<Base: NSTextInputClient> {
/// Base text input to extend.
public let base: Base
/// Reactive wrapper for `text` property.
public let text: ControlProperty<String?>
/// Initializes new text input.
///
/// - parameter base: Base object.
/// - parameter text: Textual control property.
public init(base: Base, text: ControlProperty<String?>) {
self.base = base
self.text = text
}
}
extension Reactive where Base: NSTextField, Base: NSTextInputClient {
/// Reactive text input.
public var textInput: TextInput<Base> {
return TextInput(base: self.base, text: self.text)
}
}
#endif