mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
101 lines
2.8 KiB
Swift
101 lines
2.8 KiB
Swift
import UIKit
|
|
import SwiftUI
|
|
import AsyncDisplayKit
|
|
import Display
|
|
|
|
public func isKeyboardWindow(window: NSObject) -> Bool {
|
|
let typeName = NSStringFromClass(type(of: window))
|
|
if #available(iOS 9.0, *) {
|
|
if typeName.hasPrefix("UI") && typeName.hasSuffix("RemoteKeyboardWindow") {
|
|
return true
|
|
}
|
|
} else {
|
|
if typeName.hasPrefix("UI") && typeName.hasSuffix("TextEffectsWindow") {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
public func isKeyboardView(view: NSObject) -> Bool {
|
|
let typeName = NSStringFromClass(type(of: view))
|
|
if typeName.hasPrefix("UI") && typeName.hasSuffix("InputSetHostView") {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
public func isKeyboardViewContainer(view: NSObject) -> Bool {
|
|
let typeName = NSStringFromClass(type(of: view))
|
|
if typeName.hasPrefix("UI") && typeName.hasSuffix("InputSetContainerView") {
|
|
return true
|
|
}
|
|
return false
|
|
}
|
|
|
|
public class ApplicationStatusBarHost: StatusBarHost {
|
|
private let application = UIApplication.shared
|
|
|
|
public var isApplicationInForeground: Bool {
|
|
switch self.application.applicationState {
|
|
case .background:
|
|
return false
|
|
default:
|
|
return true
|
|
}
|
|
}
|
|
|
|
public var statusBarFrame: CGRect {
|
|
return self.application.statusBarFrame
|
|
}
|
|
public var statusBarStyle: UIStatusBarStyle {
|
|
get {
|
|
return self.application.statusBarStyle
|
|
} set(value) {
|
|
self.setStatusBarStyle(value, animated: false)
|
|
}
|
|
}
|
|
|
|
public func setStatusBarStyle(_ style: UIStatusBarStyle, animated: Bool) {
|
|
if self.shouldChangeStatusBarStyle?(style) ?? true {
|
|
self.application.internalSetStatusBarStyle(style, animated: animated)
|
|
}
|
|
}
|
|
|
|
public var shouldChangeStatusBarStyle: ((UIStatusBarStyle) -> Bool)?
|
|
|
|
public func setStatusBarHidden(_ value: Bool, animated: Bool) {
|
|
self.application.internalSetStatusBarHidden(value, animation: animated ? .fade : .none)
|
|
}
|
|
|
|
public var keyboardWindow: UIWindow? {
|
|
if #available(iOS 16.0, *) {
|
|
return UIApplication.shared.internalGetKeyboard()
|
|
}
|
|
|
|
for window in UIApplication.shared.windows {
|
|
if isKeyboardWindow(window: window) {
|
|
return window
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
public var keyboardView: UIView? {
|
|
guard let keyboardWindow = self.keyboardWindow else {
|
|
return nil
|
|
}
|
|
|
|
for view in keyboardWindow.subviews {
|
|
if isKeyboardViewContainer(view: view) {
|
|
for subview in view.subviews {
|
|
if isKeyboardView(view: subview) {
|
|
return subview
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
}
|