123456789101112131415161718192021222324252627282930 |
- //
- // KeyboardReadable.swift
- // Chat
- //
- // Created by Sergey Tarasov on 25.07.2022.
- //
- import Combine
- import UIKit
- /// Publisher to read keyboard changes.
- protocol KeyboardReadable {
- var keyboardPublisher: AnyPublisher<Bool, Never> { get }
- }
- extension KeyboardReadable {
- var keyboardPublisher: AnyPublisher<Bool, Never> {
- Publishers.Merge(
- NotificationCenter.default
- .publisher(for: UIResponder.keyboardWillShowNotification)
- .map { _ in true },
- NotificationCenter.default
- .publisher(for: UIResponder.keyboardWillHideNotification)
- .map { _ in false }
- )
- .eraseToAnyPublisher()
- }
- }
|