LiTranslate-iOS/LiTranslate/Application/Protocols/KeyboardReadable.swift

30 lines
810 B
Swift
Raw Normal View History

2022-09-10 19:46:05 +02:00
//
// KeyboardReadable.swift
// LiTranslate
//
// Created by George: https://stackoverflow.com/users/9607863/george
// Found on:
// https://stackoverflow.com/questions/65784294/how-to-detect-if-keyboard-is-present-in-swiftui
import Combine
import UIKit
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()
}
}