-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChatContainer.swift
99 lines (71 loc) · 2.89 KB
/
ChatContainer.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
//
// ChatContainer.swift
// iOS Chat SDK Integration Example
//
// Created by Ilya Sokolov on 02.12.2022.
//
import UIKit
import ChatSDK
class ChatContainer: UIViewController, NChatSDKToolbar {
var chatViewController: UIViewController!
var titleView = ImageTitleView()
var avatarButton = AvatarButton()
init(with controller: UIViewController) {
super.init(nibName: nil, bundle: nil)
self.chatViewController = controller
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override open func viewDidLoad() {
super.viewDidLoad()
self.setupView()
}
fileprivate func setupView() {
navigationItem.hidesBackButton = true
view.backgroundColor = .white
addChild(chatViewController)
view.addSubview(chatViewController.view)
setupConstraints()
}
fileprivate func setupConstraints() {
chatViewController.view.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
chatViewController.view.leadingAnchor.constraint(equalTo: view.leadingAnchor),
chatViewController.view.trailingAnchor.constraint(equalTo: view.trailingAnchor),
chatViewController.view.topAnchor.constraint(equalTo: view.topAnchor),
chatViewController.view.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor),
])
}
public func setOperatorName(name: String?) {
titleView.title = name
navigationItem.titleView = titleView
}
public func setOperatorType(type: String?) {
titleView.detail = ""
navigationItem.titleView = titleView
}
public func setOperatorTypingText(_ text: String?) {
titleView.detail = text
navigationItem.titleView = titleView
}
public func hidenOperatorTypingLabel(_ value: Bool) {
titleView.operatorTypingLabel.isHidden = value
navigationItem.titleView = titleView
}
public func setOperatorTypingTheme(textColor: UIColor, font: UIFont?) {
titleView.operatorTextColor = textColor
titleView.operatorTextFont = font
navigationItem.titleView = titleView
}
public func setOperatorAvatar(avatar: UIImage?) {
let spacerItem = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
spacerItem.width = -12
let avatarItem = UIBarButtonItem(customView: avatarButton)
navigationItem.leftBarButtonItems = [spacerItem, avatarItem]
self.avatarButton.setImage(avatar, for: .normal)
}
public func showRouteToOperatorButton(with text: String) {}
public func hideRouteToOperatorButton() {}
public func routeToOperatorButton() -> UIView { return UIButton() }
}