forked from shadowfacts/Tusker
30 lines
943 B
Swift
30 lines
943 B
Swift
//
|
|
// KeyboardReader.swift
|
|
// ComposeUI
|
|
//
|
|
// Created by Shadowfacts on 3/7/23.
|
|
//
|
|
|
|
import UIKit
|
|
import Combine
|
|
|
|
@available(iOS, obsoleted: 16.0)
|
|
class KeyboardReader: ObservableObject {
|
|
@Published var isVisible = false
|
|
|
|
init() {
|
|
NotificationCenter.default.addObserver(self, selector: #selector(willShow), name: UIResponder.keyboardWillShowNotification, object: nil)
|
|
NotificationCenter.default.addObserver(self, selector: #selector(willHide), name: UIResponder.keyboardWillHideNotification, object: nil)
|
|
}
|
|
|
|
@objc func willShow(_ notification: Foundation.Notification) {
|
|
// when a hardware keyboard is connected, the height is very short, so we don't consider that being "visible"
|
|
let endFrame = notification.userInfo![UIResponder.keyboardFrameEndUserInfoKey] as! CGRect
|
|
isVisible = endFrame.height > 72
|
|
}
|
|
|
|
@objc func willHide() {
|
|
isVisible = false
|
|
}
|
|
}
|