diff --git a/Chatto/Source/ChatController/BaseChatViewController.swift b/Chatto/Source/ChatController/BaseChatViewController.swift index 848ae7ef5..0e0aef4bd 100644 --- a/Chatto/Source/ChatController/BaseChatViewController.swift +++ b/Chatto/Source/ChatController/BaseChatViewController.swift @@ -184,20 +184,25 @@ open class BaseChatViewController: UIViewController, UICollectionViewDataSource, } private func setupInputContainerBottomConstraint() { - // If we have been pushed on nav controller and hidesBottomBarWhenPushed = true, then ignore bottomLayoutMargin - // because it has incorrect value when we actually have a bottom bar (tabbar) - // Also if instance of BaseChatViewController is added as childViewController to another view controller, we had to check all this stuf on parent instance instead of self - let navigatedController: UIViewController - if let parent = self.parent, !(parent is UINavigationController || parent is UITabBarController) { - navigatedController = parent - } else { - navigatedController = self - } - - if navigatedController.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == navigatedController { - self.inputContainerBottomConstraint.constant = 0 - } else { + if #available(iOS 11.0, *) { self.inputContainerBottomConstraint.constant = self.bottomLayoutGuide.length + } else { + // If we have been pushed on nav controller and hidesBottomBarWhenPushed = true, then ignore bottomLayoutMargin + // because it has incorrect value when we actually have a bottom bar (tabbar) + // Also if instance of BaseChatViewController is added as childViewController to another view controller, we had to check all this stuf on parent instance instead of self + // UPD: Fixed in iOS 11.0 + let navigatedController: UIViewController + if let parent = self.parent, !(parent is UINavigationController || parent is UITabBarController) { + navigatedController = parent + } else { + navigatedController = self + } + + if navigatedController.hidesBottomBarWhenPushed && (navigationController?.viewControllers.count ?? 0) > 1 && navigationController?.viewControllers.last == navigatedController { + self.inputContainerBottomConstraint.constant = 0 + } else { + self.inputContainerBottomConstraint.constant = self.bottomLayoutGuide.length + } } } diff --git a/ChattoApp/ChattoApp.xcodeproj/project.pbxproj b/ChattoApp/ChattoApp.xcodeproj/project.pbxproj index eae3fe7af..9e3967b9f 100644 --- a/ChattoApp/ChattoApp.xcodeproj/project.pbxproj +++ b/ChattoApp/ChattoApp.xcodeproj/project.pbxproj @@ -7,11 +7,12 @@ objects = { /* Begin PBXBuildFile section */ + 0997CD2F2042E42100D7BDF9 /* CellsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0997CD2E2042E42100D7BDF9 /* CellsViewController.swift */; }; + 0997CD312042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0997CD302042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift */; }; 5587302E1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 5587302D1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift */; }; 558730341FCD8891005BC2EC /* AddRandomMessageChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 558730331FCD8891005BC2EC /* AddRandomMessageChatViewController.swift */; }; 55A77B4A1FCC5EE70040C77E /* MessagesSelectorProtocol.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A77B491FCC5EE70040C77E /* MessagesSelectorProtocol.swift */; }; 55A77B4C1FCC5FFB0040C77E /* BaseMessagesSelector.swift in Sources */ = {isa = PBXBuildFile; fileRef = 55A77B4B1FCC5FFB0040C77E /* BaseMessagesSelector.swift */; }; - C33FBFAE1BDE441C008E3545 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C33FBFAC1BDE441C008E3545 /* Main.storyboard */; }; C33FBFB01BDE441C008E3545 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = C33FBFAF1BDE441C008E3545 /* Assets.xcassets */; }; C33FBFB31BDE441C008E3545 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = C33FBFB11BDE441C008E3545 /* LaunchScreen.storyboard */; }; C341D42E1C9635DF00FD3463 /* TimeSeparatorModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = C341D42B1C9635DF00FD3463 /* TimeSeparatorModel.swift */; }; @@ -20,7 +21,7 @@ C35A6F4F1BF807EC0085CA19 /* SlidingDataSourceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = C35A6F4E1BF807EC0085CA19 /* SlidingDataSourceTests.swift */; }; C3F91DB61C75EF9E00D461D2 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA01C75EF9E00D461D2 /* AppDelegate.swift */; }; C3F91DB71C75EF9E00D461D2 /* DemoChatItemsDecorator.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA11C75EF9E00D461D2 /* DemoChatItemsDecorator.swift */; }; - C3F91DB81C75EF9E00D461D2 /* ConversationsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA21C75EF9E00D461D2 /* ConversationsViewController.swift */; }; + C3F91DB81C75EF9E00D461D2 /* ChatExamplesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA21C75EF9E00D461D2 /* ChatExamplesViewController.swift */; }; C3F91DBC1C75EF9E00D461D2 /* DemoChatViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA81C75EF9E00D461D2 /* DemoChatViewController.swift */; }; C3F91DBD1C75EF9E00D461D2 /* DemoChatDataSource.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DA91C75EF9E00D461D2 /* DemoChatDataSource.swift */; }; C3F91DBE1C75EF9E00D461D2 /* DemoChatMessageFactory.swift in Sources */ = {isa = PBXBuildFile; fileRef = C3F91DAA1C75EF9E00D461D2 /* DemoChatMessageFactory.swift */; }; @@ -64,6 +65,8 @@ /* End PBXCopyFilesBuildPhase section */ /* Begin PBXFileReference section */ + 0997CD2E2042E42100D7BDF9 /* CellsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CellsViewController.swift; sourceTree = ""; }; + 0997CD302042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatWithTabBarExamplesViewController.swift; sourceTree = ""; }; 13A796C853501DB82BA5DC27 /* Pods_ChattoApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_ChattoApp.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 2CCB5DAFC70B636492325895 /* Pods-ChattoApp.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ChattoApp.debug.xcconfig"; path = "Pods/Target Support Files/Pods-ChattoApp/Pods-ChattoApp.debug.xcconfig"; sourceTree = ""; }; 5587302D1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessagesSelectionChatViewController.swift; sourceTree = ""; }; @@ -73,7 +76,6 @@ 623390018DA74FF277EE2626 /* Pods.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 6DABD92E2BA40464C1727DA2 /* Pods-ChattoApp.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-ChattoApp.release.xcconfig"; path = "Pods/Target Support Files/Pods-ChattoApp/Pods-ChattoApp.release.xcconfig"; sourceTree = ""; }; C33FBFA51BDE441C008E3545 /* ChattoApp.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ChattoApp.app; sourceTree = BUILT_PRODUCTS_DIR; }; - C33FBFAD1BDE441C008E3545 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; C33FBFAF1BDE441C008E3545 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; C33FBFB21BDE441C008E3545 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; C33FBFB41BDE441C008E3545 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; @@ -85,7 +87,7 @@ C35A6F4E1BF807EC0085CA19 /* SlidingDataSourceTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SlidingDataSourceTests.swift; sourceTree = ""; }; C3F91DA01C75EF9E00D461D2 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; C3F91DA11C75EF9E00D461D2 /* DemoChatItemsDecorator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatItemsDecorator.swift; sourceTree = ""; }; - C3F91DA21C75EF9E00D461D2 /* ConversationsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ConversationsViewController.swift; sourceTree = ""; }; + C3F91DA21C75EF9E00D461D2 /* ChatExamplesViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ChatExamplesViewController.swift; sourceTree = ""; }; C3F91DA81C75EF9E00D461D2 /* DemoChatViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatViewController.swift; sourceTree = ""; }; C3F91DA91C75EF9E00D461D2 /* DemoChatDataSource.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatDataSource.swift; sourceTree = ""; }; C3F91DAA1C75EF9E00D461D2 /* DemoChatMessageFactory.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DemoChatMessageFactory.swift; sourceTree = ""; }; @@ -200,7 +202,6 @@ isa = PBXGroup; children = ( C3F91D9F1C75EF9E00D461D2 /* Source */, - C33FBFAC1BDE441C008E3545 /* Main.storyboard */, C33FBFAF1BDE441C008E3545 /* Assets.xcassets */, C33FBFB11BDE441C008E3545 /* LaunchScreen.storyboard */, C33FBFB41BDE441C008E3545 /* Info.plist */, @@ -234,7 +235,9 @@ 55A77B501FCC6BEA0040C77E /* Chat View Controllers */, 55A77B471FCC41CC0040C77E /* Chat Items */, C3F91DA01C75EF9E00D461D2 /* AppDelegate.swift */, - C3F91DA21C75EF9E00D461D2 /* ConversationsViewController.swift */, + 0997CD2E2042E42100D7BDF9 /* CellsViewController.swift */, + C3F91DA21C75EF9E00D461D2 /* ChatExamplesViewController.swift */, + 0997CD302042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift */, C3F91DB01C75EF9E00D461D2 /* SlidingDatasSource.swift */, 55A77B491FCC5EE70040C77E /* MessagesSelectorProtocol.swift */, 55A77B4B1FCC5FFB0040C77E /* BaseMessagesSelector.swift */, @@ -365,7 +368,6 @@ C33FBFB31BDE441C008E3545 /* LaunchScreen.storyboard in Resources */, C3F91DCD1C75EFE300D461D2 /* SendingStatusCollectionViewCell.xib in Resources */, C33FBFB01BDE441C008E3545 /* Assets.xcassets in Resources */, - C33FBFAE1BDE441C008E3545 /* Main.storyboard in Resources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -455,7 +457,7 @@ 55A77B4A1FCC5EE70040C77E /* MessagesSelectorProtocol.swift in Sources */, FE2D050B1C915ADB006F902B /* BaseMessageCollectionViewCellAvatarStyle.swift in Sources */, C3F91DBF1C75EF9E00D461D2 /* DemoChatMessageSender.swift in Sources */, - C3F91DB81C75EF9E00D461D2 /* ConversationsViewController.swift in Sources */, + C3F91DB81C75EF9E00D461D2 /* ChatExamplesViewController.swift in Sources */, C3F91DC41C75EF9E00D461D2 /* DemoTextMessageHandler.swift in Sources */, C3F91DC31C75EF9E00D461D2 /* SlidingDatasSource.swift in Sources */, C3F91DC71C75EF9E00D461D2 /* BaseMessageHandler.swift in Sources */, @@ -472,6 +474,8 @@ 5587302E1FCD7EE5005BC2EC /* MessagesSelectionChatViewController.swift in Sources */, C3F91DCC1C75EFE300D461D2 /* SendingStatusCollectionViewCell.swift in Sources */, C3F91DB71C75EF9E00D461D2 /* DemoChatItemsDecorator.swift in Sources */, + 0997CD2F2042E42100D7BDF9 /* CellsViewController.swift in Sources */, + 0997CD312042E58400D7BDF9 /* ChatWithTabBarExamplesViewController.swift in Sources */, 558730341FCD8891005BC2EC /* AddRandomMessageChatViewController.swift in Sources */, C3F91DC11C75EF9E00D461D2 /* DemoPhotoMessageModel.swift in Sources */, C3F91DC21C75EF9E00D461D2 /* DemoPhotoMessageViewModel.swift in Sources */, @@ -499,14 +503,6 @@ /* End PBXTargetDependency section */ /* Begin PBXVariantGroup section */ - C33FBFAC1BDE441C008E3545 /* Main.storyboard */ = { - isa = PBXVariantGroup; - children = ( - C33FBFAD1BDE441C008E3545 /* Base */, - ); - name = Main.storyboard; - sourceTree = ""; - }; C33FBFB11BDE441C008E3545 /* LaunchScreen.storyboard */ = { isa = PBXVariantGroup; children = ( diff --git a/ChattoApp/ChattoApp/Base.lproj/Main.storyboard b/ChattoApp/ChattoApp/Base.lproj/Main.storyboard deleted file mode 100644 index f2d4e0138..000000000 --- a/ChattoApp/ChattoApp/Base.lproj/Main.storyboard +++ /dev/null @@ -1,233 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/ChattoApp/ChattoApp/Info.plist b/ChattoApp/ChattoApp/Info.plist index 9e12b6d40..80e2d66eb 100644 --- a/ChattoApp/ChattoApp/Info.plist +++ b/ChattoApp/ChattoApp/Info.plist @@ -28,8 +28,6 @@ NSPhotoLibraryUsageDescription UILaunchStoryboardName LaunchScreen - UIMainStoryboardFile - Main UIRequiredDeviceCapabilities armv7 diff --git a/ChattoApp/ChattoApp/Source/AppDelegate.swift b/ChattoApp/ChattoApp/Source/AppDelegate.swift index 174165c3c..c50052e40 100644 --- a/ChattoApp/ChattoApp/Source/AppDelegate.swift +++ b/ChattoApp/ChattoApp/Source/AppDelegate.swift @@ -29,31 +29,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? - func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { - // Override point for customization after application launch. + func application(_ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { + let rootViewController = ChatExamplesViewController() + let window = UIWindow() + window.rootViewController = UINavigationController(rootViewController: rootViewController) + self.window = window + self.window?.makeKeyAndVisible() return true } - func applicationWillResignActive(_ application: UIApplication) { - // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. - // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. - } - - func applicationDidEnterBackground(_ application: UIApplication) { - // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. - // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. - } - - func applicationWillEnterForeground(_ application: UIApplication) { - // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. - } - - func applicationDidBecomeActive(_ application: UIApplication) { - // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. - } - - func applicationWillTerminate(_ application: UIApplication) { - // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. - } - } diff --git a/ChattoApp/ChattoApp/Source/CellsViewController.swift b/ChattoApp/ChattoApp/Source/CellsViewController.swift new file mode 100644 index 000000000..ae3314d53 --- /dev/null +++ b/ChattoApp/ChattoApp/Source/CellsViewController.swift @@ -0,0 +1,61 @@ +/* + The MIT License (MIT) + + Copyright (c) 2015-present Badoo Trading Limited. + + 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 + +class CellsViewController: UITableViewController { + + struct CellItem { + let title: String + let action: () -> Void + } + + var cellItems: [CellItem] = [] + + override func viewDidLoad() { + super.viewDidLoad() + + self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: UITableViewCell.reuseIdentifier) + } + + override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { + return self.cellItems.count + } + + override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { + let cell = tableView.dequeueReusableCell(withIdentifier: UITableViewCell.reuseIdentifier, for: indexPath) + cell.textLabel?.text = self.cellItems[indexPath.row].title + return cell + } + + override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { + self.cellItems[indexPath.row].action() + } +} + +extension UITableViewCell { + static var reuseIdentifier: String { + return String(describing: self) + } +} diff --git a/ChattoApp/ChattoApp/Source/Chat View Controllers/DemoChatViewController.swift b/ChattoApp/ChattoApp/Source/Chat View Controllers/DemoChatViewController.swift index a7f6dbcfe..ae25120a2 100644 --- a/ChattoApp/ChattoApp/Source/Chat View Controllers/DemoChatViewController.swift +++ b/ChattoApp/ChattoApp/Source/Chat View Controllers/DemoChatViewController.swift @@ -34,6 +34,7 @@ class DemoChatViewController: BaseChatViewController { var dataSource: DemoChatDataSource! { didSet { self.chatDataSource = self.dataSource + self.messageSender = self.dataSource.messageSender } } @@ -44,6 +45,7 @@ class DemoChatViewController: BaseChatViewController { override func viewDidLoad() { super.viewDidLoad() + self.title = "Chat" self.messagesSelector.delegate = self self.chatItemsDecorator = DemoChatItemsDecorator(messagesSelector: self.messagesSelector) } diff --git a/ChattoApp/ChattoApp/Source/ChatExamplesViewController.swift b/ChattoApp/ChattoApp/Source/ChatExamplesViewController.swift new file mode 100644 index 000000000..fc118097b --- /dev/null +++ b/ChattoApp/ChattoApp/Source/ChatExamplesViewController.swift @@ -0,0 +1,94 @@ +/* + The MIT License (MIT) + + Copyright (c) 2015-present Badoo Trading Limited. + + 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 + +class ChatExamplesViewController: CellsViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + self.title = "Examples" + + self.cellItems = [ + self.makeOverviewCellItem(), + self.makeChatCellItem(title: "Empty chat", messagesCount: 0), + self.makeChatCellItem(title: "Chat with 10000 messages", messagesCount: 10_000), + self.makeMessageSelectionCellItem(), + self.makeOpenWithTabBarCellItem(), + ] + } + + // MARK: - Cells + + private func makeOverviewCellItem() -> CellItem { + return CellItem(title: "Overview", action: { [weak self] in + let dataSource = DemoChatDataSource(messages: DemoChatMessageFactory.makeOverviewMessages(), pageSize: 50) + let viewController = AddRandomMessagesChatViewController() + viewController.dataSource = dataSource + self?.navigationController?.pushViewController(viewController, animated: true) + }) + } + + private func makeChatCellItem(title: String, messagesCount: Int) -> CellItem { + return CellItem(title: title, action: { [weak self] in + let dataSource = DemoChatDataSource(count: messagesCount, pageSize: 50) + let viewController = AddRandomMessagesChatViewController() + viewController.dataSource = dataSource + self?.navigationController?.pushViewController(viewController, animated: true) + }) + } + + private func makeMessageSelectionCellItem() -> CellItem { + return CellItem(title: "Chat with message selection", action: { [weak self] in + let messages = DemoChatMessageFactory.makeMessagesSelectionMessages() + let dataSource = DemoChatDataSource(messages: messages, pageSize: 50) + let viewController = MessagesSelectionChatViewController() + viewController.dataSource = dataSource + self?.navigationController?.pushViewController(viewController, animated: true) + }) + } + + private func makeOpenWithTabBarCellItem() -> CellItem { + return CellItem(title: "UITabBarController examples", action: { [weak self] in + guard let sSelf = self else { return } + let viewController = ChatWithTabBarExamplesViewController() + viewController.navigationItem.leftBarButtonItem = UIBarButtonItem( + title: "Close", + style: .done, + target: sSelf, + action: #selector(sSelf.dismissPresentedController) + ) + let navigationController = UINavigationController(rootViewController: viewController) + let tabBarViewController = UITabBarController() + tabBarViewController.setViewControllers([navigationController], animated: false) + sSelf.present(tabBarViewController, animated: true, completion: nil) + }) + } + + @objc + private func dismissPresentedController() { + self.dismiss(animated: true, completion: nil) + } +} diff --git a/ChattoApp/ChattoApp/Source/ChatWithTabBarExamplesViewController.swift b/ChattoApp/ChattoApp/Source/ChatWithTabBarExamplesViewController.swift new file mode 100644 index 000000000..81a8a18c0 --- /dev/null +++ b/ChattoApp/ChattoApp/Source/ChatWithTabBarExamplesViewController.swift @@ -0,0 +1,59 @@ +/* + The MIT License (MIT) + + Copyright (c) 2015-present Badoo Trading Limited. + + 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 + +class ChatWithTabBarExamplesViewController: CellsViewController { + + override func viewDidLoad() { + super.viewDidLoad() + + self.title = "Examples" + + self.cellItems = [ + self.makeChatWithHiddenTabBarCellItem(), + self.makeChatWithVisibleTabBarCellItem() + ] + } + + private func makeChatWithHiddenTabBarCellItem() -> CellItem { + return CellItem(title: "Chat with hidden tab bar", action: { [weak self] in + self?.pushChatViewController(hidesBottomBar: true) + }) + } + + private func makeChatWithVisibleTabBarCellItem() -> CellItem { + return CellItem(title: "Chat with visible tab bar", action: { [weak self] in + self?.pushChatViewController(hidesBottomBar: false) + }) + } + + private func pushChatViewController(hidesBottomBar: Bool) { + let dataSource = DemoChatDataSource(count: 0, pageSize: 50) + let viewController = AddRandomMessagesChatViewController() + viewController.dataSource = dataSource + viewController.hidesBottomBarWhenPushed = hidesBottomBar + self.navigationController?.pushViewController(viewController, animated: true) + } +} diff --git a/ChattoApp/ChattoApp/Source/ConversationsViewController.swift b/ChattoApp/ChattoApp/Source/ConversationsViewController.swift deleted file mode 100644 index 3efbf9fa5..000000000 --- a/ChattoApp/ChattoApp/Source/ConversationsViewController.swift +++ /dev/null @@ -1,66 +0,0 @@ -/* - The MIT License (MIT) - - Copyright (c) 2015-present Badoo Trading Limited. - - 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 - -class ConversationsViewController: UITableViewController { - - override func prepare(for segue: UIStoryboardSegue, sender: Any?) { - - var initialCount = 0 - let pageSize = 50 - - var dataSource: DemoChatDataSource! - if segue.identifier == "0 messages" { - initialCount = 0 - } else if segue.identifier == "2 messages" { - initialCount = 2 - } else if segue.identifier == "10000 messages" { - initialCount = 10000 - } else if segue.identifier == "overview" { - dataSource = DemoChatDataSource(messages: DemoChatMessageFactory.makeOverviewMessages(), pageSize: pageSize) - } else if segue.identifier == "messages_selection" { - dataSource = DemoChatDataSource(messages: DemoChatMessageFactory.makeMessagesSelectionMessages(), pageSize: pageSize) - } else { - assert(false, "segue not handled!") - } - - let chatController = { () -> DemoChatViewController? in - if let controller = segue.destination as? DemoChatViewController { - return controller - } - if let tabController = segue.destination as? UITabBarController, - let controller = tabController.viewControllers?.first as? DemoChatViewController { - return controller - } - return nil - }()! - - if dataSource == nil { - dataSource = DemoChatDataSource(count: initialCount, pageSize: pageSize) - } - chatController.dataSource = dataSource - chatController.messageSender = dataSource.messageSender - } -}