Skip to content

Commit

Permalink
Rehaul DemoApp navigation so it is possible to show reconnection bann…
Browse files Browse the repository at this point in the history
…er on any screen
  • Loading branch information
dmigach committed Apr 15, 2021
1 parent 60b3ef1 commit 123223f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
28 changes: 0 additions & 28 deletions DemoApp/ChatPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,6 @@ import StreamChat
import StreamChatUI
import UIKit

extension UIViewController {
// TODO: Where to put this???
func presentChat(userCredentials: UserCredentials) {
LogConfig.level = .error

// Create a token
let token = try! Token(rawValue: userCredentials.token)

// Create client
let config = ChatClientConfig(apiKey: .init(userCredentials.apiKey))
let client = ChatClient(config: config, tokenProvider: .static(token))

// Config
UIConfig.default.navigation.channelListRouter = DemoChatChannelListRouter.self

// Channels with the current user
let controller = client.channelListController(query: .init(filter: .containMembers(userIds: [userCredentials.id])))
let chatList = ChatChannelListVC()
chatList.controller = controller

let chatNavigationController = UINavigationController(rootViewController: chatList)

UIView.transition(with: view.window!, duration: 0.3, options: .transitionFlipFromRight, animations: {
self.view.window!.rootViewController = chatNavigationController
})
}
}

class DemoChatChannelListRouter: _ChatChannelListRouter<NoExtraData> {
override func openCreateNewChannel() {
let storyboard = UIStoryboard(name: "Main", bundle: .main)
Expand Down
4 changes: 0 additions & 4 deletions DemoApp/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
<string>Default Configuration</string>
<key>UISceneDelegateClassName</key>
<string>$(PRODUCT_MODULE_NAME).SceneDelegate</string>
<key>UISceneStoryboardFile</key>
<string>Main</string>
</dict>
</array>
</dict>
Expand All @@ -43,8 +41,6 @@
<true/>
<key>UILaunchStoryboardName</key>
<string>LaunchScreen</string>
<key>UIMainStoryboardFile</key>
<string>Main</string>
<key>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
Expand Down
3 changes: 2 additions & 1 deletion DemoApp/LoginViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class UserCredentialsCell: UITableViewCell {

class LoginViewController: UIViewController {
@IBOutlet var tableView: UITableView!
var didRequestChatPresentation: ((UserCredentials) -> Void)!

let builtInUsers = UserCredentials.builtInUsers

Expand Down Expand Up @@ -95,6 +96,6 @@ extension LoginViewController: UITableViewDelegate, UITableViewDataSource {
return
}

presentChat(userCredentials: builtInUsers[indexPath.row])
didRequestChatPresentation(builtInUsers[indexPath.row])
}
}
13 changes: 12 additions & 1 deletion DemoApp/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,21 @@ extension UIColor {
}

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private var coordinator: DemoAppCoordinator!
var window: UIWindow?

func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let scene = scene as? UIWindowScene else { return }
let window = UIWindow(windowScene: scene)

guard let navigationController = UIStoryboard(
name: "Main",
bundle: nil
).instantiateInitialViewController() as? UINavigationController else { return }
window.rootViewController = navigationController
coordinator = DemoAppCoordinator(navigationController: navigationController)
self.window = window
window.makeKeyAndVisible()
scene.windows.forEach { $0.tintColor = .streamBlue }
}

Expand Down
4 changes: 4 additions & 0 deletions StreamChat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
22FF4365256E943F00133910 /* ChatMessageComposerSuggestionsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 22FF4364256E943F00133910 /* ChatMessageComposerSuggestionsViewController.swift */; };
6428DD5526201DCC0065DA1D /* BannerShowingConnectionDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6428DD5426201DCC0065DA1D /* BannerShowingConnectionDelegate.swift */; };
647F66D5261E22C200111B19 /* BannerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647F66D4261E22C200111B19 /* BannerView.swift */; };
648EC576261EF9D400B8F05F /* DemoAppCoordinator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 648EC575261EF9D400B8F05F /* DemoAppCoordinator.swift */; };
64F70D4B26257FD400C9F979 /* Error+InternetNotAvailable_Tests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64F70D4A26257FD400C9F979 /* Error+InternetNotAvailable_Tests.swift */; };
6971257E260CA503003C7B47 /* NSManagedObjectContext+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6971256C260CA4CB003C7B47 /* NSManagedObjectContext+Extensions.swift */; };
697C6F90260CFA37000E9023 /* Deprecations.swift in Sources */ = {isa = PBXBuildFile; fileRef = 69712522260BC9B4003C7B47 /* Deprecations.swift */; };
Expand Down Expand Up @@ -1184,6 +1185,7 @@
22FF4364256E943F00133910 /* ChatMessageComposerSuggestionsViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ChatMessageComposerSuggestionsViewController.swift; sourceTree = "<group>"; };
6428DD5426201DCC0065DA1D /* BannerShowingConnectionDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerShowingConnectionDelegate.swift; sourceTree = "<group>"; };
647F66D4261E22C200111B19 /* BannerView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BannerView.swift; sourceTree = "<group>"; };
648EC575261EF9D400B8F05F /* DemoAppCoordinator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DemoAppCoordinator.swift; sourceTree = "<group>"; };
64F70D4A26257FD400C9F979 /* Error+InternetNotAvailable_Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Error+InternetNotAvailable_Tests.swift"; sourceTree = "<group>"; };
69712522260BC9B4003C7B47 /* Deprecations.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Deprecations.swift; sourceTree = "<group>"; };
6971256C260CA4CB003C7B47 /* NSManagedObjectContext+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSManagedObjectContext+Extensions.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2567,6 +2569,7 @@
792DDA5D256FB69E001DB91B /* LoginViewController.swift */,
7933064825712C8B00FBB586 /* DemoUsers.swift */,
7933060A256FF94800FBB586 /* ChatPresenter.swift */,
648EC575261EF9D400B8F05F /* DemoAppCoordinator.swift */,
6428DD5426201DCC0065DA1D /* BannerShowingConnectionDelegate.swift */,
79330603256FEBE600FBB586 /* AdvancedOptionsViewController.swift */,
792DDA5F256FB69E001DB91B /* Main.storyboard */,
Expand Down Expand Up @@ -5058,6 +5061,7 @@
files = (
6428DD5526201DCC0065DA1D /* BannerShowingConnectionDelegate.swift in Sources */,
647F66D5261E22C200111B19 /* BannerView.swift in Sources */,
648EC576261EF9D400B8F05F /* DemoAppCoordinator.swift in Sources */,
792DDA5E256FB69E001DB91B /* LoginViewController.swift in Sources */,
792DDAA825753BEA001DB91B /* CreateGroupViewController.swift in Sources */,
7933064925712C8B00FBB586 /* DemoUsers.swift in Sources */,
Expand Down

0 comments on commit 123223f

Please sign in to comment.