Skip to content

Commit 8445cdd

Browse files
committed
Example project updated.
1 parent 0c1951e commit 8445cdd

File tree

2 files changed

+28
-44
lines changed

2 files changed

+28
-44
lines changed

Example/ChatExample/CustomChatViewController.swift

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import StreamChat
1414
class CustomChatViewController: ChatViewController {
1515

1616
@IBOutlet weak var closeBarButton: UIBarButtonItem!
17+
let membersCountButton = UIBarButtonItem(title: "🤷🏻‍♀️0", style: .plain, target: nil, action: nil)
1718

1819
required init?(coder aDecoder: NSCoder) {
1920
super.init(coder: aDecoder)
@@ -28,19 +29,38 @@ class CustomChatViewController: ChatViewController {
2829
navigationItem.rightBarButtonItems = [button]
2930
}
3031

32+
touchMembersCount()
33+
34+
if (navigationItem.rightBarButtonItems?.count ?? 0) == 1 {
35+
navigationItem.rightBarButtonItems?.append(membersCountButton)
36+
} else {
37+
navigationItem.leftBarButtonItem = membersCountButton
38+
}
39+
3140
guard let channelPresenter = channelPresenter else {
3241
return
3342
}
3443

35-
title = "\(channelPresenter.channel.name) (\(channelPresenter.channel.members.count))"
44+
title = channelPresenter.channel.name
3645

3746
channelPresenter.channelDidUpdate
3847
.drive(onNext: { [weak self] channel in
39-
self?.title = "\(channel.name) (\(channel.members.count))"
48+
self?.title = channelPresenter.channel.name
49+
self?.touchMembersCount()
4050
})
4151
.disposed(by: disposeBag)
4252
}
4353

54+
func touchMembersCount() {
55+
guard let channelPresenter = channelPresenter else {
56+
return
57+
}
58+
59+
membersCountButton.title = channelPresenter.channel.members.count > 0
60+
? "🙋🏻‍♀️\(channelPresenter.channel.members.count)"
61+
: "🤷🏻‍♀️0"
62+
}
63+
4464
@IBAction func showMenu(_ sender: Any) {
4565
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
4666

@@ -124,42 +144,4 @@ class CustomChatViewController: ChatViewController {
124144

125145
return nil
126146
}
127-
128-
// override func messageCell(at indexPath: IndexPath, message: Message, readUsers: [User]) -> UITableViewCell {
129-
// let cell = tableView.dequeueReusableCell(withIdentifier: "message")
130-
// ?? UITableViewCell(style: .value2, reuseIdentifier: "message")
131-
//
132-
// cell.textLabel?.text = message.user.name
133-
// cell.textLabel?.numberOfLines = 2
134-
// cell.textLabel?.font = .systemFont(ofSize: 12, weight: .bold)
135-
// cell.detailTextLabel?.text = message.text
136-
// cell.detailTextLabel?.numberOfLines = 0
137-
//
138-
// return cell
139-
// }
140-
//
141-
// override func loadingCell(at indexPath: IndexPath) -> UITableViewCell? {
142-
// let cell = tableView.dequeueReusableCell(withIdentifier: "loading")
143-
// ?? UITableViewCell(style: .default, reuseIdentifier: "loading")
144-
//
145-
// cell.textLabel?.textColor = .red
146-
// cell.textLabel?.text = "LOADING..."
147-
// cell.textLabel?.textAlignment = .center
148-
//
149-
// return cell
150-
// }
151-
//
152-
// override func statusCell(at indexPath: IndexPath,
153-
// title: String,
154-
// subtitle: String? = nil,
155-
// highlighted: Bool) -> UITableViewCell? {
156-
// let cell = tableView.dequeueReusableCell(withIdentifier: "status")
157-
// ?? UITableViewCell(style: .default, reuseIdentifier: "status")
158-
//
159-
// cell.textLabel?.textColor = .gray
160-
// cell.textLabel?.text = title
161-
// cell.textLabel?.textAlignment = .center
162-
//
163-
// return cell
164-
// }
165147
}

Example/ChatExample/DarkChannelsViewController.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ final class DarkChannelsViewController: ChannelsViewController {
9090
}
9191

9292
@IBAction func addChannel(_ sender: Any) {
93-
let number = Int.random(in: 100...999)
93+
let number = Int.random(in: 1000...9999)
9494
let channel = Channel(type: .messaging, id: "new_channel_\(number)", name: "Channel \(number)")
9595
channel.create().subscribe().disposed(by: disposeBag)
9696
}
@@ -99,14 +99,16 @@ final class DarkChannelsViewController: ChannelsViewController {
9999
let cell = super.channelCell(at: indexPath, channelPresenter: channelPresenter)
100100

101101
if let cell = cell as? ChannelTableViewCell {
102-
// Add a number of members.
103-
cell.nameLabel.text = "\(cell.nameLabel.text ?? "") (\(channelPresenter.channel.members.count) members)"
102+
var extraChannelName = "🙋🏻‍♀️\(channelPresenter.channel.members.count)"
104103

105104
// Add an unread count.
106105
if channelPresenter.channel.currentUnreadCount > 0 {
107-
cell.messageLabel.text = "\(cell.messageLabel.text ?? "") (\(channelPresenter.channel.currentUnreadCount) unread)"
106+
extraChannelName += " 📬\(channelPresenter.channel.currentUnreadCount)"
108107
}
109108

109+
// Add a number of members.
110+
cell.nameLabel.text = "\(cell.nameLabel.text ?? "") \(extraChannelName)"
111+
110112
cell.rx.longPressGesture().when(.began)
111113
.subscribe(onNext: { [weak self, weak channelPresenter] _ in
112114
if let self = self, let channelPresenter = channelPresenter {

0 commit comments

Comments
 (0)