From b8afc1c186c7769af9511e946b4cf52c542ea719 Mon Sep 17 00:00:00 2001 From: Anton Poltoratskyi Date: Wed, 8 Aug 2018 13:37:31 +0300 Subject: [PATCH 1/5] Reversed datasource --- Nynja/Modules/Message/View/MessageVC.swift | 42 ++++++++------- .../View/Views/TableView/MessageDS.swift | 52 +++++++++---------- 2 files changed, 47 insertions(+), 47 deletions(-) diff --git a/Nynja/Modules/Message/View/MessageVC.swift b/Nynja/Modules/Message/View/MessageVC.swift index ae60d8f77..0247f4f4c 100644 --- a/Nynja/Modules/Message/View/MessageVC.swift +++ b/Nynja/Modules/Message/View/MessageVC.swift @@ -103,9 +103,9 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw private(set) lazy var tableView: UITableView = { let tv = UITableView() - + tv.transform = CGAffineTransform(rotationAngle: .pi) tv.separatorStyle = .none - tv.backgroundColor = UIColor.clear + tv.backgroundColor = .clear registerCells(for: tv) @@ -114,9 +114,9 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw tv.contentInset = UIEdgeInsets( - top: Constraints.tableView.defaultVerticalInset, + top: Constraints.tableView.bottomInset, left: 0, - bottom: Constraints.tableView.bottomInset, + bottom: Constraints.tableView.defaultVerticalInset, right: 0 ) @@ -465,6 +465,10 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() + tableView.scrollIndicatorInsets = UIEdgeInsets( + top: 0, left: 0, bottom: 0, right: tableView.bounds.width - tableView.scrollIndicatorInsets.left - 8 + ) + let expandedHeight = self.tableView.bounds.height + CGFloat(FooterViewLayout.collapsedHeight) footerView?.update(constraintLayout: CollapsedView.ConstraintLayout(availableHeight: [CGFloat(FooterViewLayout.collapsedHeight), @@ -1575,21 +1579,21 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw } private func adjustTableTopInset(for bounds: CGRect, updateOffset: Bool = true) { - let minTop = Constraints.tableView.defaultVerticalInset - var topInset = max(minTop, bounds.height - tableView.contentSize.height) - let canScroll = self.canScroll(with: bounds) - - if !canScroll { - topInset -= gradientHeight - tableView.contentInset.bottom - } - - guard tableView.contentInset.top != topInset else { return } - - tableView.contentInset.top = topInset - - if updateOffset, !canScroll { - tableView.contentOffset.y = -topInset - } +// let minTop = Constraints.tableView.defaultVerticalInset +// var topInset = max(minTop, bounds.height - tableView.contentSize.height) +// let canScroll = self.canScroll(with: bounds) +// +// if !canScroll { +// topInset -= gradientHeight - tableView.contentInset.bottom +// } +// +// guard tableView.contentInset.top != topInset else { return } +// +// tableView.contentInset.top = topInset +// +// if updateOffset, !canScroll { +// tableView.contentOffset.y = -topInset +// } } //MARK: - Rejoin bar diff --git a/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift b/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift index df9e8540d..3f68a4bd7 100644 --- a/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift +++ b/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift @@ -23,7 +23,7 @@ class MessageDS: NSObject, UITableViewDataSource { // MARK: - Data - let isReversed = false + let isReversed = true var isEmpty: Bool { return cells.isEmpty @@ -38,11 +38,11 @@ class MessageDS: NSObject, UITableViewDataSource { } var bottomIndex: Int { - return cells.count - 1 + return 0 // cells.count - 1 } var bottomModel: BaseChatCellModel? { - return cells.last + return cells.first // cells.last } func update(_ cells: [BaseChatCellModel]) { @@ -50,52 +50,41 @@ class MessageDS: NSObject, UITableViewDataSource { } func unreadIndex(count: Int) -> Int { - return unreadIndices(count: count).upperBound - } - - private func unreadIndices(count: Int) -> CountableRange { - return 0.. CountableRange { - return index.. CountableRange { - return 0.. Bool) -> Int? { - return cells.index(where: predicate) + return cells.index(where: predicate).map { count - $0 - 1 } } func first(where predicate: (BaseChatCellModel) -> Bool) -> BaseChatCellModel? { - return cells.first(where: predicate) + return cells.reversed().first(where: predicate) } func filter(where predicate: (BaseChatCellModel) -> Bool) -> [BaseChatCellModel] { - return cells.filter(predicate) + return cells.reversed().filter(predicate) } func cellModel(at indexPath: IndexPath) -> BaseChatCellModel { - return cells[indexPath.row] + return cells[count - indexPath.row - 1] // cells[indexPath.row] } func cellModel(at index: Int) -> BaseChatCellModel { - return cells[index] + return cells[count - index - 1] // cells[index] } func cellModel(before index: Int, where predicate: (BaseChatCellModel) -> Bool) -> BaseChatCellModel? { - // don't reverse if table will be reversed - return cells[.. UITableViewCell { let model = cellModel(at: indexPath) + func transform(_ cell: UITableViewCell) { + cell.transform = CGAffineTransform(rotationAngle: .pi) + } + if model.unread != nil { if let cell = tableView.dequeueReusableCell(withIdentifier: "unread", for: indexPath) as? Unread { cell.setup() cell.accessibilityIdentifier = "chat_cell_unread_\(indexPath.section)" + transform(cell) return cell } } @@ -138,6 +132,7 @@ class MessageDS: NSObject, UITableViewDataSource { if let cell = tableView.dequeueReusableCell(withIdentifier: "system", for: indexPath) as? SystemCell { cell.setup(message: model.text!) cell.accessibilityIdentifier = "system_cell_unread_\(indexPath.section)" + transform(cell) return cell } } else if model.time == nil { @@ -146,6 +141,7 @@ class MessageDS: NSObject, UITableViewDataSource { if let identifier = MessageCellFactory.identifier(for: model) { cell = tableView.dequeueReusableCell(withIdentifier: identifier, for: indexPath) as? BaseChatCell cell.accessibilityIdentifier = "message_cell_\(identifier)_\(indexPath.section)" + transform(cell) } if view.messageTVDelegate != nil { @@ -157,7 +153,7 @@ class MessageDS: NSObject, UITableViewDataSource { if let cell = tableView.dequeueReusableCell(withIdentifier: "time", for: indexPath) as? TimeCell { cell.setup(date: model.time!) cell.accessibilityIdentifier = "time_cell_unread_\(indexPath.section)" - + transform(cell) return cell } } -- GitLab From 8ec6d54aed8ab47a2ec368b092ff89e69e7b71ea Mon Sep 17 00:00:00 2001 From: Anton Poltoratskyi Date: Wed, 8 Aug 2018 14:03:04 +0300 Subject: [PATCH 2/5] Handle keyboard and input bar height --- Nynja/Modules/Message/View/MessageVC.swift | 47 ++++++---------------- 1 file changed, 12 insertions(+), 35 deletions(-) diff --git a/Nynja/Modules/Message/View/MessageVC.swift b/Nynja/Modules/Message/View/MessageVC.swift index 0247f4f4c..ccb9bbd06 100644 --- a/Nynja/Modules/Message/View/MessageVC.swift +++ b/Nynja/Modules/Message/View/MessageVC.swift @@ -29,8 +29,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw var progressDictionary = [String: [(ProgressModel)->Void]]() var loadingStatus = false - var isHideKeyboard = true - var verticalOffset: CGFloat = 0.0 var messageDS: MessageDS! var messageTVDelegate: MessageTableViewDelegate! @@ -170,12 +168,7 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw inputBar.sendTypingHandler = { [weak self] status in self?.presenter.sendTyping(status) } - - inputBar.changesHeightHandler = { [weak self] diff in - guard let `self` = self else { return } - self.tableView.contentInset.top -= diff - self.tableView.contentOffset.y += diff - } + inputBar.inputTypeChangeHandler = { [weak self] inputType in self?.stickerInputState.performUpdates { state in state.inputType = inputType.toggled() @@ -465,15 +458,19 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw override func viewDidLayoutSubviews() { super.viewDidLayoutSubviews() - tableView.scrollIndicatorInsets = UIEdgeInsets( - top: 0, left: 0, bottom: 0, right: tableView.bounds.width - tableView.scrollIndicatorInsets.left - 8 - ) + let indicatorInset = tableView.bounds.width - tableView.scrollIndicatorInsets.left - 8 + tableView.scrollIndicatorInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: indicatorInset) - let expandedHeight = self.tableView.bounds.height + CGFloat(FooterViewLayout.collapsedHeight) + let expandedHeight = tableView.bounds.height + CGFloat(FooterViewLayout.collapsedHeight) - footerView?.update(constraintLayout: CollapsedView.ConstraintLayout(availableHeight: [CGFloat(FooterViewLayout.collapsedHeight), - CGFloat(FooterViewLayout.middleHeight), - expandedHeight])) + footerView?.update(constraintLayout: + CollapsedView.ConstraintLayout(availableHeight: [ + CGFloat(FooterViewLayout.collapsedHeight), + CGFloat(FooterViewLayout.middleHeight), + expandedHeight + ] + ) + ) } // MARK: - BaseVC @@ -490,28 +487,9 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw } override func keyboardNotified(endFrame: CGRect) { - let currentTableBounds = tableView.bounds - if endFrame.origin.y >= UIScreen.main.bounds.size.height { - if !isHideKeyboard { - let newTableBounds = currentTableBounds.updating(height: currentTableBounds.height + verticalOffset) - adjustTableTopInset(for: newTableBounds) - - tableView.contentOffset = CGPoint(x: 0, y: tableView.contentOffset.y - verticalOffset) - verticalOffset = 0 - } - isHideKeyboard = true updateToHide() - } else { - if isHideKeyboard { - verticalOffset = CGFloat(endFrame.height) - safeAreaBottomInset() - let newTableBounds = currentTableBounds.updating(height: currentTableBounds.height - verticalOffset) - adjustTableTopInset(for: newTableBounds) - - tableView.contentOffset = CGPoint(x: 0, y: tableView.contentOffset.y + verticalOffset) - } - isHideKeyboard = false updateToShow(endFrame: endFrame) } } @@ -521,7 +499,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw } - //MARK: - Translation private func handleUpdateForTranslation(in textView: UITextView) { let inputText = textView.text ?? "" -- GitLab From 800f56145663f1a56eb15df4330178eda61e0be4 Mon Sep 17 00:00:00 2001 From: Anton Poltoratskyi Date: Wed, 8 Aug 2018 14:07:00 +0300 Subject: [PATCH 3/5] Remove 'adjustTableTopInset' --- Nynja/Modules/Message/View/MessageVC.swift | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/Nynja/Modules/Message/View/MessageVC.swift b/Nynja/Modules/Message/View/MessageVC.swift index ccb9bbd06..0f194b90f 100644 --- a/Nynja/Modules/Message/View/MessageVC.swift +++ b/Nynja/Modules/Message/View/MessageVC.swift @@ -1552,27 +1552,9 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw // MARK: - Input View private func adjustTableTopInset(updateOffset: Bool = true) { - adjustTableTopInset(for: tableView.bounds, updateOffset: updateOffset) + // TODO: delete it } - - private func adjustTableTopInset(for bounds: CGRect, updateOffset: Bool = true) { -// let minTop = Constraints.tableView.defaultVerticalInset -// var topInset = max(minTop, bounds.height - tableView.contentSize.height) -// let canScroll = self.canScroll(with: bounds) -// -// if !canScroll { -// topInset -= gradientHeight - tableView.contentInset.bottom -// } -// -// guard tableView.contentInset.top != topInset else { return } -// -// tableView.contentInset.top = topInset -// -// if updateOffset, !canScroll { -// tableView.contentOffset.y = -topInset -// } - } - + //MARK: - Rejoin bar func rejoinRunningCall() { presenter.rejoinRunningCall() -- GitLab From 0cd7c0612da574ed32a16d19f77e2e62fa32e585 Mon Sep 17 00:00:00 2001 From: Anton Poltoratskyi Date: Wed, 8 Aug 2018 15:18:08 +0300 Subject: [PATCH 4/5] [NY-2285] Remove calls of adjustTableTopInset --- Nynja/Modules/Message/View/MessageVC.swift | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/Nynja/Modules/Message/View/MessageVC.swift b/Nynja/Modules/Message/View/MessageVC.swift index 0f194b90f..9ded93410 100644 --- a/Nynja/Modules/Message/View/MessageVC.swift +++ b/Nynja/Modules/Message/View/MessageVC.swift @@ -814,7 +814,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw func updateData(with configuration: DisplayChatConfiguration) { messageDS.update(configuration.cells) tableView.reloadData() - adjustTableTopInset() hasUnread = configuration.isUnreadShown adjustPosition(with: configuration, isLastMessageVisible: isLastMessageVisible) @@ -854,7 +853,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw let initialOffset = tableView.contentOffset tableView.reloadData() - adjustTableTopInset() if !messageDS.isReversed, messageDS.count > history.count { let indexPath = IndexPath(row: history.count, section: 0) @@ -947,7 +945,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw messageDS.addNewMessage(cell) tableView.insertRows(at: [IndexPath(row: messageDS.bottomIndex, section: 0)], with: .none) } - adjustTableTopInset() if isLastMessageVisible || cell.isOwner { dispatchAsyncMainAfter(0.01) { @@ -1120,7 +1117,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw messageDS.insert(.unreadModel(), at: index) tableView.insertRows(at: [IndexPath(row: index, section: 0)], with: .none) } - adjustTableTopInset() scrollToUnreadMessage(with: index + 1) messageDS.bottomModel.map { readMessage($0) } @@ -1226,7 +1222,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw self.messageTVDelegate.rejoinBannerDisplayed = display self.messageTVDelegate.membersCount = count self.tableView.reloadData() - adjustTableTopInset() } private func toggleReplyPreview(_ shouldShow: Bool) { @@ -1365,7 +1360,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw } tableView.reloadRows(at: indexPaths, with: .none) } - adjustTableTopInset() } private func markMesssagesAsRead(from index: Int) { @@ -1488,7 +1482,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw messageDS.remove(at: index) tableView.deleteRows(at: [IndexPath(row: index, section: 0)], with: .none) } - adjustTableTopInset() } func getNextPage() { @@ -1524,7 +1517,6 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw messageDS.remove(at: prevIndex) tableView.deleteRows(at: [IndexPath(row: prevIndex, section: 0)], with: .none) } - adjustTableTopInset() } private func goAway() { @@ -1539,6 +1531,7 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw } } + //MARK: - InputBar func updateToHide() { @@ -1549,13 +1542,9 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw updateToShow(view: inputBar, offset: -endFrame.height) } - // MARK: - Input View - - private func adjustTableTopInset(updateOffset: Bool = true) { - // TODO: delete it - } //MARK: - Rejoin bar + func rejoinRunningCall() { presenter.rejoinRunningCall() } @@ -1608,7 +1597,7 @@ extension MessageVC { } } -//MARK: - UI configuration +// MARK: - Translation UI configuration private extension MessageVC { func makeFooterView(on view: UIView, bottom: UIView) -> CollapsedView { let footerView = CollapsedView() -- GitLab From 8d972fdaa2e2c31f2a53e28e2c449f9c3f976d22 Mon Sep 17 00:00:00 2001 From: Anton Poltoratskyi Date: Wed, 8 Aug 2018 16:38:17 +0300 Subject: [PATCH 5/5] Fixed datasource --- .../Message/Protocols/MessageProtocols.swift | 3 +- Nynja/Modules/Message/View/MessageVC.swift | 29 +++++--- .../View/Views/TableView/MessageDS.swift | 4 ++ .../TableView/MessageTableViewDelegate.swift | 67 ++++++++++++------- 4 files changed, 68 insertions(+), 35 deletions(-) diff --git a/Nynja/Modules/Message/Protocols/MessageProtocols.swift b/Nynja/Modules/Message/Protocols/MessageProtocols.swift index 4ae1ebb15..4e8660a49 100644 --- a/Nynja/Modules/Message/Protocols/MessageProtocols.swift +++ b/Nynja/Modules/Message/Protocols/MessageProtocols.swift @@ -263,10 +263,9 @@ protocol MessageViewProtocol: class { func showContextMenu(fromCell cell: BaseChatCell, convertingModel: ConvertionMessageModel?, targetView: UIView?) - func scrollToBottomIfNeeded() func scrollToMessage(with localId: String?) - func scrollToUnreadMessage(with index: Int) func scrollToMessage(serverId: Int64) + func scrollToBottomIfNeeded() func scrollToBottom() func updateHeaderStatus(_ status: String) diff --git a/Nynja/Modules/Message/View/MessageVC.swift b/Nynja/Modules/Message/View/MessageVC.swift index 9ded93410..d6dbf8be3 100644 --- a/Nynja/Modules/Message/View/MessageVC.swift +++ b/Nynja/Modules/Message/View/MessageVC.swift @@ -1135,19 +1135,19 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw if canScroll { scrollToMessage(with: checkpoint.localId) if checkpoint.topOffset > 0 { - var contentOffset = tableView.contentOffset.y + CGFloat(checkpoint.topOffset) - contentOffset = min(contentOffset, tableView.contentSize.height - tableView.bounds.height) - tableView.contentOffset.y = contentOffset + (gradientHeight - tableView.contentInset.bottom) +// var contentOffset = tableView.contentOffset.y + CGFloat(checkpoint.topOffset) +// contentOffset = min(contentOffset, tableView.contentSize.height - tableView.bounds.height) +// tableView.contentOffset.y = contentOffset + (gradientHeight - tableView.contentInset.bottom) } } } - func scrollToMessage(with index: Int) { + private func scrollToMessage(with index: Int) { let indexPath = IndexPath(row: index, section: 0) scroll(to: indexPath, at: .bottom, animated: false) } - func scrollToUnreadMessage(with index: Int) { + private func scrollToUnreadMessage(with index: Int) { guard case let prevInd = index - 1, messageDS.indices.contains(prevInd) else { return } @@ -1388,15 +1388,26 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw self.scrollToBottom(animated: true) } } - + func scrollToBottom() { - scrollToBottom(animated: false) + scrollToBottom(animated: true) } func scrollToBottom(animated: Bool) { - let indexPath = IndexPath(row: messageDS.bottomIndex, section: 0) + guard case let index = messageDS.bottomIndex, messageDS.indices.contains(index) else { + return + } + let indexPath = IndexPath(row: index, section: 0) scroll(to: indexPath, at: .top, animated: animated) } + + func scrollToTop(animated: Bool) { + guard case let index = messageDS.topIndex, messageDS.indices.contains(index) else { + return + } + let indexPath = IndexPath(row: index, section: 0) + scroll(to: indexPath, at: .bottom, animated: animated) + } private func scroll(to indexPath: IndexPath, at position: UITableViewScrollPosition, animated: Bool) { guard !contextMenuPresented, canScroll else { @@ -1534,7 +1545,7 @@ final class MessageVC: BaseVC, MessageViewProtocol, ReplyPreviewDelegate, BackSw //MARK: - InputBar - func updateToHide() { + private func updateToHide() { updateToHide(view: inputBar, offset: 0) } diff --git a/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift b/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift index 3f68a4bd7..89ad63faa 100644 --- a/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift +++ b/Nynja/Modules/Message/View/Views/TableView/MessageDS.swift @@ -41,6 +41,10 @@ class MessageDS: NSObject, UITableViewDataSource { return 0 // cells.count - 1 } + var topIndex: Int { + return count - 1 // cells.count - 1 + } + var bottomModel: BaseChatCellModel? { return cells.first // cells.last } diff --git a/Nynja/Modules/Message/View/Views/TableView/MessageTableViewDelegate.swift b/Nynja/Modules/Message/View/Views/TableView/MessageTableViewDelegate.swift index d0515e6c6..5a9beb1ce 100644 --- a/Nynja/Modules/Message/View/Views/TableView/MessageTableViewDelegate.swift +++ b/Nynja/Modules/Message/View/Views/TableView/MessageTableViewDelegate.swift @@ -18,12 +18,15 @@ class MessageTableViewDelegate: NSObject, UITableViewDelegate, CallInfoViewDeleg var rejoinBannerDisplayed: Bool = false var membersCount: Int = 0 - // MARK: Init + + // MARK: - Init + init(view: MessageVC) { self.view = view } - // MARK: UITableViewDelegate + + // MARK: - UITableViewDelegate func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { var callInfoView:CallInfoView? = nil @@ -70,13 +73,32 @@ class MessageTableViewDelegate: NSObject, UITableViewDelegate, CallInfoViewDeleg func height(for model: BaseChatCellModel) -> CGFloat { return model.isOwner ? BaseChatCell.size(for: model).height : OponentChatCell.size(for: model).height } + + func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { + setupProgress(cell: cell) + setupMentions(cell: cell, indexPath: indexPath) + } + + func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { + guard let cell = cell as? BaseChatCell, let url = cell.model?.progressModel?.url.absoluteString else { + return + } + view?.progressDictionary.removeValue(forKey: url) + } - // MARK: UIScrollViewDelegate - var scrollOffset: CGFloat = 0 + + // MARK: - UIScrollViewDelegate + + private var scrollOffset: CGFloat = 0 var lastVisibleIndex: Int? func scrollViewDidScroll(_ scrollView: UIScrollView) { - let offset = scrollView.contentOffset.y + guard let view = view else { + return + } + let offset = view.messageDS.isReversed + ? scrollView.contentSize.height - scrollView.bounds.height - scrollView.contentOffset.y + : scrollView.contentOffset.y let absoluteTop: CGFloat = 0 let absoluteBottom: CGFloat = scrollView.contentSize.height - scrollView.frame.size.height @@ -85,13 +107,13 @@ class MessageTableViewDelegate: NSObject, UITableViewDelegate, CallInfoViewDeleg let isBottom = scrollOffset - offset < 0 && offset < absoluteBottom if isTop { - view?.isScrollingTo(.top) + view.isScrollingTo(.top) } else if isBottom { - view?.isScrollingTo(.bottom) + view.isScrollingTo(.bottom) } if offset >= absoluteBottom { - view?.didReachBottom() + view.didReachBottom() } let contentHeight = scrollView.contentSize.height @@ -101,20 +123,15 @@ class MessageTableViewDelegate: NSObject, UITableViewDelegate, CallInfoViewDeleg } scrollOffset = offset } - - func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) { - setupProgress(cell: cell) - setupMentions(cell: cell, indexPath: indexPath) - } - - func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) { - guard let cell = cell as? BaseChatCell, let url = cell.model?.progressModel?.url.absoluteString else { - return - } - view?.progressDictionary.removeValue(forKey: url) + + func scrollViewShouldScrollToTop(_ scrollView: UIScrollView) -> Bool { + view?.scrollToTop(animated: true) + return false } - // MARK: CallInfoVIewDelegate + + // MARK: - CallInfoVIewDelegate + func didPressButtonJoinIn(callInfoView: CallInfoView) { self.view?.rejoinRunningCall() } @@ -123,16 +140,18 @@ class MessageTableViewDelegate: NSObject, UITableViewDelegate, CallInfoViewDeleg // MARK: - Private private func setupMentions(cell: UITableViewCell, indexPath: IndexPath) { - guard let index = lastVisibleIndex ?? view?.lastVisibleCellIndex() else { + func setup() { lastVisibleIndex = indexPath.row view?.setupUnreadMentions(after: indexPath.row) + } + guard let index = lastVisibleIndex ?? view?.lastVisibleCellIndex() else { + setup() return } - guard indexPath.row > index else { + guard let datasource = view?.messageDS, datasource.isReversed ? indexPath.row < index : indexPath.row > index else { return } - lastVisibleIndex = indexPath.row - view?.setupUnreadMentions(after: indexPath.row) + setup() } private func setupProgress(cell: UITableViewCell) { -- GitLab