LiTranslate-iOS/LiTranslate/Application/Protocols/KeyboardReadable.swift
Viktor Kalyniuk 823b3abe77 release v1.0
2022-09-10 20:46:05 +03:00

29 lines
810 B
Swift

//
// 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()
}
}