Add dismiss on tap outside extension

This commit is contained in:
Jackson Harper
2024-03-21 10:17:50 +08:00
parent 14fc731669
commit 4184d64341
7 changed files with 35 additions and 9 deletions

View File

@ -8,13 +8,18 @@ import Views
import UIKit
@objc(ShareExtensionViewController)
final class ShareExtensionViewController: UIViewController {
final class ShareExtensionViewController: UIViewController, UIGestureRecognizerDelegate {
let labelsViewModel = LabelsViewModel()
let viewModel = ShareExtensionViewModel()
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .clear
view.backgroundColor = UIColor(white: 1.0, alpha: 0.001)
view.isUserInteractionEnabled = true
let dismissGesture = UITapGestureRecognizer(target: self, action: #selector(self.viewTapped(_:)))
dismissGesture.delegate = self
view.addGestureRecognizer(dismissGesture)
if !viewModel.services.authenticator.isLoggedIn,
!viewModel.services.dataService.appEnvironment.environmentConfigured
@ -60,6 +65,14 @@ import Views
)
}
func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldReceive touch: UITouch) -> Bool {
return touch.view == gestureRecognizer.view
}
@objc func viewTapped(_ panGesture: UIGestureRecognizer) {
viewModel.dismissExtension(extensionContext: extensionContext)
}
func openSheet(_ rootView: AnyView) {
let hostingController = UIHostingController(rootView: rootView)