From 07eed9be91fb9f2aa1abd2a6bf86c7be2f9f66bd Mon Sep 17 00:00:00 2001 From: martinpucik Date: Tue, 3 May 2022 17:26:04 +0200 Subject: [PATCH] refactor: InpuBar as subview instead of accessoryView Simplify example launch VC # Conflicts: # Example/Sources/View Controllers/LaunchViewController.swift # Example/Sources/View Controllers/NavigationController.swift --- Example/ChatExample.xcodeproj/project.pbxproj | 8 +-- Example/Sources/AppDelegate.swift | 4 +- .../LaunchViewController.swift | 36 +++++------ .../NavigationController.swift | 61 ------------------- 4 files changed, 19 insertions(+), 90 deletions(-) delete mode 100644 Example/Sources/View Controllers/NavigationController.swift diff --git a/Example/ChatExample.xcodeproj/project.pbxproj b/Example/ChatExample.xcodeproj/project.pbxproj index 489bc17d..b321a3e5 100644 --- a/Example/ChatExample.xcodeproj/project.pbxproj +++ b/Example/ChatExample.xcodeproj/project.pbxproj @@ -28,7 +28,6 @@ 385C2942211FF38F0010B4BA /* AdvancedExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385C293B211FF38E0010B4BA /* AdvancedExampleViewController.swift */; }; 385C2943211FF38F0010B4BA /* SettingsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385C293C211FF38E0010B4BA /* SettingsViewController.swift */; }; 385C2944211FF38F0010B4BA /* MessageContainerController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385C293D211FF38F0010B4BA /* MessageContainerController.swift */; }; - 385C2945211FF38F0010B4BA /* NavigationController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385C293E211FF38F0010B4BA /* NavigationController.swift */; }; 385C2946211FF38F0010B4BA /* LaunchViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385C293F211FF38F0010B4BA /* LaunchViewController.swift */; }; 385C2947211FF38F0010B4BA /* BasicExampleViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385C2940211FF38F0010B4BA /* BasicExampleViewController.swift */; }; 385C2948211FF38F0010B4BA /* ChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 385C2941211FF38F0010B4BA /* ChatViewController.swift */; }; @@ -90,7 +89,6 @@ 385C293B211FF38E0010B4BA /* AdvancedExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AdvancedExampleViewController.swift; sourceTree = ""; }; 385C293C211FF38E0010B4BA /* SettingsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = ""; }; 385C293D211FF38F0010B4BA /* MessageContainerController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MessageContainerController.swift; sourceTree = ""; }; - 385C293E211FF38F0010B4BA /* NavigationController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NavigationController.swift; sourceTree = ""; }; 385C293F211FF38F0010B4BA /* LaunchViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = LaunchViewController.swift; sourceTree = ""; }; 385C2940211FF38F0010B4BA /* BasicExampleViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BasicExampleViewController.swift; sourceTree = ""; }; 385C2941211FF38F0010B4BA /* ChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatViewController.swift; sourceTree = ""; }; @@ -226,7 +224,6 @@ 385C2941211FF38F0010B4BA /* ChatViewController.swift */, 385C293F211FF38F0010B4BA /* LaunchViewController.swift */, 385C293D211FF38F0010B4BA /* MessageContainerController.swift */, - 385C293E211FF38F0010B4BA /* NavigationController.swift */, 385C293C211FF38E0010B4BA /* SettingsViewController.swift */, 63ECDABD24182A470016C349 /* MessageSubviewViewController.swift */, 63ECDAC1241889630016C349 /* MessageSubviewContainerViewController.swift */, @@ -504,7 +501,6 @@ 385C2931211FF3630010B4BA /* UIColor+Extensions.swift in Sources */, 385C2932211FF3630010B4BA /* UIViewController+Extensions.swift in Sources */, 385C292B211FF3450010B4BA /* Settings+UserDefaults.swift in Sources */, - 385C2945211FF38F0010B4BA /* NavigationController.swift in Sources */, 9B49D547263DAA29008804B5 /* CustomTextMessageContentCell.swift in Sources */, 9B49D528263C31FC008804B5 /* CustomLayoutExampleViewController.swift in Sources */, 032A15DD25965D9A00E00FE3 /* AlertService.swift in Sources */, @@ -623,7 +619,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; @@ -676,7 +672,7 @@ GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 12.0; + IPHONEOS_DEPLOYMENT_TARGET = 13.0; MTL_ENABLE_DEBUG_INFO = NO; SDKROOT = iphoneos; SWIFT_VERSION = 5.0; diff --git a/Example/Sources/AppDelegate.swift b/Example/Sources/AppDelegate.swift index 5895d4ca..8ba230d2 100644 --- a/Example/Sources/AppDelegate.swift +++ b/Example/Sources/AppDelegate.swift @@ -31,8 +31,8 @@ final internal class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { - let masterViewController = NavigationController(rootViewController: LaunchViewController()) - let detailViewController = NavigationController() + let masterViewController = UINavigationController(rootViewController: LaunchViewController()) + let detailViewController = UINavigationController() let splitViewController = UISplitViewController() splitViewController.viewControllers = [masterViewController, detailViewController] splitViewController.preferredDisplayMode = .allVisible diff --git a/Example/Sources/View Controllers/LaunchViewController.swift b/Example/Sources/View Controllers/LaunchViewController.swift index e0365f1c..433ffabe 100644 --- a/Example/Sources/View Controllers/LaunchViewController.swift +++ b/Example/Sources/View Controllers/LaunchViewController.swift @@ -28,33 +28,27 @@ import SafariServices import SwiftUI final internal class LaunchViewController: UITableViewController { - - override var preferredStatusBarStyle: UIStatusBarStyle { - return .lightContent - } - let cells = ["Basic Example", "Advanced Example", "Autocomplete Example", "Embedded Example", "Custom Layout Example", "Subview Example", "SwiftUI Example", "Settings", "Source Code", "Contributors"] + private let cells = ["Basic Example", "Advanced Example", "Autocomplete Example", "Embedded Example", "Custom Layout Example", "Subview Example", "SwiftUI Example", "Settings", "Source Code", "Contributors"] // MARK: - View Life Cycle - + + init() { + super.init(style: .insetGrouped) + } + + required init?(coder: NSCoder) { nil } + + override func viewDidLoad() { super.viewDidLoad() title = "MessageKit" navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil) + navigationController?.navigationBar.prefersLargeTitles = false tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") tableView.tableFooterView = UIView() } - override func viewWillAppear(_ animated: Bool) { - super.viewWillAppear(animated) - navigationController?.navigationBar.prefersLargeTitles = true - } - - override func viewWillDisappear(_ animated: Bool) { - super.viewWillDisappear(animated) - navigationController?.navigationBar.prefersLargeTitles = false - } - // MARK: - UITableViewDataSource override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { @@ -76,15 +70,15 @@ final internal class LaunchViewController: UITableViewController { switch cell { case "Basic Example": let viewController = BasicExampleViewController() - let detailViewController = NavigationController(rootViewController: viewController) + let detailViewController = UINavigationController(rootViewController: viewController) splitViewController?.showDetailViewController(detailViewController, sender: self) case "Advanced Example": let viewController = AdvancedExampleViewController() - let detailViewController = NavigationController(rootViewController: viewController) + let detailViewController = UINavigationController(rootViewController: viewController) splitViewController?.showDetailViewController(detailViewController, sender: self) case "Autocomplete Example": let viewController = AutocompleteExampleViewController() - let detailViewController = NavigationController(rootViewController: viewController) + let detailViewController = UINavigationController(rootViewController: viewController) splitViewController?.showDetailViewController(detailViewController, sender: self) case "Embedded Example": navigationController?.pushViewController(MessageContainerController(), animated: true) @@ -96,11 +90,11 @@ final internal class LaunchViewController: UITableViewController { } case "Settings": let viewController = SettingsViewController() - let detailViewController = NavigationController(rootViewController: viewController) + let detailViewController = UINavigationController(rootViewController: viewController) splitViewController?.showDetailViewController(detailViewController, sender: self) case "Subview Example": let viewController = MessageSubviewContainerViewController() - let detailViewController = NavigationController(rootViewController: viewController) + let detailViewController = UINavigationController(rootViewController: viewController) splitViewController?.showDetailViewController(detailViewController, sender: self) case "Source Code": guard let url = URL(string: "https://github.com/MessageKit/MessageKit") else { return } diff --git a/Example/Sources/View Controllers/NavigationController.swift b/Example/Sources/View Controllers/NavigationController.swift deleted file mode 100644 index c47cace5..00000000 --- a/Example/Sources/View Controllers/NavigationController.swift +++ /dev/null @@ -1,61 +0,0 @@ -/* - MIT License - - Copyright (c) 2017-2019 MessageKit - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. - */ - -import UIKit - -final class NavigationController: UINavigationController { - - override var preferredStatusBarStyle: UIStatusBarStyle { - return viewControllers.last?.preferredStatusBarStyle ?? .lightContent - } - - override func viewDidLoad() { - super.viewDidLoad() - navigationBar.isTranslucent = false - navigationBar.tintColor = .white - navigationBar.barTintColor = .primaryColor - navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white] - navigationBar.largeTitleTextAttributes = [.foregroundColor: UIColor.white] - navigationBar.shadowImage = UIImage() - navigationBar.setBackgroundImage(UIImage(), for: .default) - view.backgroundColor = .primaryColor - } - - func setAppearanceStyle(to style: UIStatusBarStyle) { - if style == .default { - navigationBar.shadowImage = UIImage() - navigationBar.barTintColor = .primaryColor - navigationBar.tintColor = .white - navigationBar.titleTextAttributes = [.foregroundColor: UIColor.white] - navigationBar.largeTitleTextAttributes = [.foregroundColor: UIColor.white] - } else if style == .lightContent { - navigationBar.shadowImage = nil - navigationBar.barTintColor = .white - navigationBar.tintColor = UIColor(red: 0, green: 0.5, blue: 1, alpha: 1) - navigationBar.titleTextAttributes = [.foregroundColor: UIColor.black] - navigationBar.largeTitleTextAttributes = [.foregroundColor: UIColor.black] - } - } - -}