Skip to content

Commit

Permalink
- #148 Hide "No messages yet" while loading messages
Browse files Browse the repository at this point in the history
  • Loading branch information
khaliddd committed Oct 18, 2021
1 parent 4878342 commit 8a1173b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
16 changes: 1 addition & 15 deletions Snikket/chat/ChatViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,7 @@ class ChatViewController : BaseChatViewControllerWithDataSourceAndContextMenuAnd

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
let count = super.tableView(tableView, numberOfRowsInSection: section);
if count == 0 {
if self.conversationLogController!.tableView.backgroundView == nil {
let label = UILabel(frame: CGRect(x: 0, y:0, width: self.view.bounds.size.width, height: self.view.bounds.size.height));
label.text = NSLocalizedString("No messages yet. Say hi!", comment: "")
label.font = UIFont.systemFont(ofSize: UIFont.systemFontSize + 2, weight: .medium);
label.numberOfLines = 0;
label.textAlignment = .center;
label.transform = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: 0);
label.sizeToFit();
self.conversationLogController!.tableView.backgroundView = label;
}
} else {
self.conversationLogController!.tableView.backgroundView = nil;
}
return count;
return count
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
Expand Down
22 changes: 21 additions & 1 deletion Snikket/chat/ConversationLogController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,34 @@ class ConversationLogController: UIViewController, ChatViewDataSourceDelegate {
if !loaded {
loaded = true;
self.dataSource.refreshData(unread: chat.unread) { (firstUnread) in
print("got first unread at:", firstUnread as Any);
if self.tableView.numberOfRows(inSection: 0) > 0 {
self.tableView.scrollToRow(at: IndexPath(row: firstUnread ?? 0, section: 0), at: .none, animated: true);
}

if self.dataSource.count == 0 {
self.toggleNoMessagesLabel(show: true)
} else {
self.toggleNoMessagesLabel(show: false)
}
}
}
}

func toggleNoMessagesLabel(show: Bool) {
if show {
let label = UILabel(frame: CGRect(x: 0, y:0, width: self.view.bounds.size.width, height: self.view.bounds.size.height))
label.text = NSLocalizedString("No messages yet. Say hi!", comment: "")
label.font = UIFont.systemFont(ofSize: UIFont.systemFontSize + 2, weight: .medium)
label.numberOfLines = 0
label.textAlignment = .center
label.transform = CGAffineTransform(a: 1, b: 0, c: 0, d: -1, tx: 0, ty: 0)
label.sizeToFit()
self.tableView.backgroundView = label
} else {
self.tableView.backgroundView = nil
}
}

func itemAdded(at rows: IndexSet, shouldScroll: Bool) {
guard rows.count > 0 else {
return;
Expand Down

0 comments on commit 8a1173b

Please sign in to comment.