From 7532c89f6ff6b33f69e821c6a7a9779c790f64cc Mon Sep 17 00:00:00 2001 From: Philipp Schmid <25935690+phil1995@users.noreply.github.com> Date: Mon, 5 Dec 2022 23:58:58 +0100 Subject: [PATCH 1/2] Fix missing navigation bar items on iOS 14 as `viewDidLoad` gets not called for a UIHostingController on iOS 14. --- .../S3/S3AuthenticationViewController.swift | 15 +++++++++++++-- .../WebDAVAuthenticationViewController.swift | 17 ++++++++++++++--- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/Cryptomator/S3/S3AuthenticationViewController.swift b/Cryptomator/S3/S3AuthenticationViewController.swift index c944e0655..05fade6b6 100644 --- a/Cryptomator/S3/S3AuthenticationViewController.swift +++ b/Cryptomator/S3/S3AuthenticationViewController.swift @@ -11,14 +11,14 @@ import CryptomatorCommonCore import SwiftUI import UIKit -class S3AuthenticationViewController: UIHostingController { +class S3AuthenticationViewController: UIViewController { weak var coordinator: (Coordinator & S3Authenticating)? let viewModel: S3AuthenticationViewModel private var subscriptions = Set() init(viewModel: S3AuthenticationViewModel) { self.viewModel = viewModel - super.init(rootView: S3AuthenticationView(viewModel: viewModel)) + super.init(nibName: nil, bundle: nil) } @available(*, unavailable) @@ -28,6 +28,8 @@ class S3AuthenticationViewController: UIHostingController override func viewDidLoad() { super.viewDidLoad() + setupSwiftUIView() + let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(done)) navigationItem.rightBarButtonItem = doneButton let cancelButton = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(cancel)) @@ -64,4 +66,13 @@ class S3AuthenticationViewController: UIHostingController @objc func cancel() { coordinator?.cancel() } + + private func setupSwiftUIView() { + let child = UIHostingController(rootView: S3AuthenticationView(viewModel: viewModel)) + addChild(child) + view.addSubview(child.view) + child.didMove(toParent: self) + child.view.translatesAutoresizingMaskIntoConstraints = false + NSLayoutConstraint.activate(child.view.constraints(equalTo: view)) + } } diff --git a/Cryptomator/WebDAV/WebDAVAuthenticationViewController.swift b/Cryptomator/WebDAV/WebDAVAuthenticationViewController.swift index 93946834d..3d3ca7e75 100644 --- a/Cryptomator/WebDAV/WebDAVAuthenticationViewController.swift +++ b/Cryptomator/WebDAV/WebDAVAuthenticationViewController.swift @@ -13,15 +13,15 @@ import Promises import SwiftUI import UIKit -class WebDAVAuthenticationViewController: UIHostingController { +class WebDAVAuthenticationViewController: UIViewController { weak var coordinator: (Coordinator & WebDAVAuthenticating)? - private var viewModel: WebDAVAuthenticationViewModel + private let viewModel: WebDAVAuthenticationViewModel private var cancellables = Set() private var hud: ProgressHUD? init(viewModel: WebDAVAuthenticationViewModel) { self.viewModel = viewModel - super.init(rootView: WebDAVAuthentication(viewModel: viewModel)) + super.init(nibName: nil, bundle: nil) } @available(*, unavailable) @@ -31,6 +31,8 @@ class WebDAVAuthenticationViewController: UIHostingController Date: Mon, 5 Dec 2022 23:59:21 +0100 Subject: [PATCH 2/2] Fix WebDAVAuthentication appearance on iOS 14 --- Cryptomator/WebDAV/WebDAVAuthentication.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cryptomator/WebDAV/WebDAVAuthentication.swift b/Cryptomator/WebDAV/WebDAVAuthentication.swift index de6d56239..de649a631 100644 --- a/Cryptomator/WebDAV/WebDAVAuthentication.swift +++ b/Cryptomator/WebDAV/WebDAVAuthentication.swift @@ -20,7 +20,7 @@ struct WebDAVAuthentication: View { @FocusStateLegacy private var focusedField: Fields? = .url var body: some View { - List { + Form { TextField(LocalizedString.getValue("common.cells.url"), text: $viewModel.url) .keyboardType(.URL) .disableAutocorrection(true)