ChatApp.swift 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // ChatApp.swift
  3. // Shared
  4. //
  5. // Created by Sergey Tarasov on 24.07.2022.
  6. //
  7. import SwiftUI
  8. import XMPPFramework
  9. @main
  10. struct ChatApp: App {
  11. @UIApplicationDelegateAdaptor(AppDelegate.self) var delegate
  12. var body: some Scene {
  13. WindowGroup {
  14. ContentView()
  15. .onAppear(perform: UIApplication.shared.addTapGestureRecognizer)
  16. }
  17. }
  18. }
  19. extension UIApplication {
  20. func addTapGestureRecognizer() {
  21. let scenes = UIApplication.shared.connectedScenes
  22. let windowScene = scenes.first as? UIWindowScene
  23. guard let window = windowScene?.windows.first else { return }
  24. let tapGesture = UITapGestureRecognizer(target: window, action: #selector(UIView.endEditing))
  25. tapGesture.requiresExclusiveTouchType = false
  26. tapGesture.cancelsTouchesInView = false
  27. tapGesture.delegate = self
  28. window.addGestureRecognizer(tapGesture)
  29. }
  30. }
  31. extension UIApplication: UIGestureRecognizerDelegate {
  32. public func gestureRecognizer(
  33. _ gestureRecognizer: UIGestureRecognizer,
  34. shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer
  35. ) -> Bool {
  36. return false
  37. }
  38. }